Tag clients more intelligently (FS#700)
[awesome.git] / common / xcursor.c
blobd122d3dbf3987242daced4204d3378ded6354a60
1 /*
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.
22 /* CURSORFONT */
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",
31 [XC_arrow] = "arrow",
32 [XC_based_arrow_down] = "based_arrow_down",
33 [XC_based_arrow_up] = "based_arrow_up",
34 [XC_boat] = "boat",
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",
43 [XC_clock] = "clock",
44 [XC_coffee_mug] = "coffee_mug",
45 [XC_cross] = "cross",
46 [XC_cross_reverse] = "cross_reverse",
47 [XC_crosshair] = "crosshair",
48 [XC_diamond_cross] = "diamond_cross",
49 [XC_dot] = "dot",
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",
56 [XC_fleur] = "fleur",
57 [XC_gobbler] = "gobbler",
58 [XC_gumby] = "gumby",
59 [XC_hand1] = "hand1",
60 [XC_hand2] = "hand2",
61 [XC_heart] = "heart",
62 [XC_icon] = "icon",
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",
70 [XC_man] = "man",
71 [XC_middlebutton] = "middlebutton",
72 [XC_mouse] = "mouse",
73 [XC_pencil] = "pencil",
74 [XC_pirate] = "pirate",
75 [XC_plus] = "plus",
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",
93 [XC_star] = "star",
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",
101 [XC_trek] = "trek",
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.
112 uint16_t
113 xcursor_font_fromstr(const char *s)
115 if(s)
116 for(int i = 0; i < countof(xcursor_font); i++)
117 if(xcursor_font[i] && !a_strcmp(s, xcursor_font[i]))
118 return i;
119 return 0;
122 /** Get a cursor name.
123 * \param c The cursor.
125 const char *
126 xcursor_font_tostr(uint16_t c)
128 if(c < countof(xcursor_font))
129 return xcursor_font[c];
130 return NULL;
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.
139 xcb_cursor_t
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 */
146 if(!font)
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,
157 0, 0, 0,
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