2 * xcursor.c - X cursors management
4 * Copyright © 2008 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <X11/Xlibint.h>
25 #include "common/xcursor.h"
26 #include "common/util.h"
28 static char const * const xcursor_font
[] =
30 [XC_X_cursor
] = "X_cursor",
32 [XC_based_arrow_down
] = "based_arrow_down",
33 [XC_based_arrow_up
] = "based_arrow_up",
35 [XC_bogosity
] = "bogosity",
36 [XC_bottom_left_corner
] = "bottom_left_corner",
37 [XC_bottom_right_corner
] = "bottom_right_corner",
38 [XC_bottom_side
] = "bottom_side",
39 [XC_bottom_tee
] = "bottom_tee",
40 [XC_box_spiral
] = "box_spiral",
41 [XC_center_ptr
] = "center_ptr",
42 [XC_circle
] = "circle",
44 [XC_coffee_mug
] = "coffee_mug",
46 [XC_cross_reverse
] = "cross_reverse",
47 [XC_crosshair
] = "crosshair",
48 [XC_diamond_cross
] = "diamond_cross",
50 [XC_dotbox
] = "dotbox",
51 [XC_double_arrow
] = "double_arrow",
52 [XC_draft_large
] = "draft_large",
53 [XC_draft_small
] = "draft_small",
54 [XC_draped_box
] = "draped_box",
55 [XC_exchange
] = "exchange",
57 [XC_gobbler
] = "gobbler",
63 [XC_iron_cross
] = "iron_cross",
64 [XC_left_ptr
] = "left_ptr",
65 [XC_left_side
] = "left_side",
66 [XC_left_tee
] = "left_tee",
67 [XC_leftbutton
] = "leftbutton",
68 [XC_ll_angle
] = "ll_angle",
69 [XC_lr_angle
] = "lr_angle",
71 [XC_middlebutton
] = "middlebutton",
73 [XC_pencil
] = "pencil",
74 [XC_pirate
] = "pirate",
76 [XC_question_arrow
] = "question_arrow",
77 [XC_right_ptr
] = "right_ptr",
78 [XC_right_side
] = "right_side",
79 [XC_right_tee
] = "right_tee",
80 [XC_rightbutton
] = "rightbutton",
81 [XC_rtl_logo
] = "rtl_logo",
82 [XC_sailboat
] = "sailboat",
83 [XC_sb_down_arrow
] = "sb_down_arrow",
84 [XC_sb_h_double_arrow
] = "sb_h_double_arrow",
85 [XC_sb_left_arrow
] = "sb_left_arrow",
86 [XC_sb_right_arrow
] = "sb_right_arrow",
87 [XC_sb_up_arrow
] = "sb_up_arrow",
88 [XC_sb_v_double_arrow
] = "sb_v_double_arrow",
89 [XC_shuttle
] = "shuttle",
90 [XC_sizing
] = "sizing",
91 [XC_spider
] = "spider",
92 [XC_spraycan
] = "spraycan",
94 [XC_target
] = "target",
95 [XC_tcross
] = "tcross",
96 [XC_top_left_arrow
] = "top_left_arrow",
97 [XC_top_left_corner
] = "top_left_corner",
98 [XC_top_right_corner
] = "top_right_corner",
99 [XC_top_side
] = "top_side",
100 [XC_top_tee
] = "top_tee",
102 [XC_ul_angle
] = "ul_angle",
103 [XC_umbrella
] = "umbrella",
104 [XC_ur_angle
] = "ur_angle",
105 [XC_watch
] = "watch",
106 [XC_xterm
] = "xterm",
109 /** Get a cursor from a string.
110 * \param s The string.
113 xcursor_font_fromstr(const char *s
)
116 for(int i
= 0; i
< countof(xcursor_font
); i
++)
117 if(xcursor_font
[i
] && !a_strcmp(s
, xcursor_font
[i
]))
122 /** Get a cursor name.
123 * \param c The cursor.
126 xcursor_font_tostr(uint16_t c
)
128 if(c
< countof(xcursor_font
))
129 return xcursor_font
[c
];
133 /** Equivalent to 'XCreateFontCursor()', error are handled by the
134 * default current error handler.
135 * \param conn The connection to the X server.
136 * \param cursor_font Type of cursor to use.
137 * \return Allocated cursor font.
140 xcursor_new(xcb_connection_t
*conn
, uint16_t cursor_font
)
142 static xcb_font_t font
= XCB_NONE
;
143 static xcb_cursor_t xcursor
[countof(xcursor_font
)];
145 /* Get the font for the cursor */
148 font
= xcb_generate_id(conn
);
149 xcb_open_font(conn
, font
, sizeof(CURSORFONT
) - 1, CURSORFONT
);
152 if(!xcursor
[cursor_font
])
154 xcursor
[cursor_font
] = xcb_generate_id(conn
);
155 xcb_create_glyph_cursor(conn
, xcursor
[cursor_font
], font
, font
,
156 cursor_font
, cursor_font
+ 1,
158 65535, 65535, 65535);
161 return xcursor
[cursor_font
];
165 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80