Added initial support for Xlib cursor themes
[awesome.git] / common / xcursor.c
blob1e6e24e1cdeaad8142ef8cdd0299feafb98cbdb1
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 #include "common/xcursor.h"
23 #include "common/util.h"
25 static char const * const xcursor_font[] =
27 [XC_X_cursor] = "X_cursor",
28 [XC_arrow] = "arrow",
29 [XC_based_arrow_down] = "based_arrow_down",
30 [XC_based_arrow_up] = "based_arrow_up",
31 [XC_boat] = "boat",
32 [XC_bogosity] = "bogosity",
33 [XC_bottom_left_corner] = "bottom_left_corner",
34 [XC_bottom_right_corner] = "bottom_right_corner",
35 [XC_bottom_side] = "bottom_side",
36 [XC_bottom_tee] = "bottom_tee",
37 [XC_box_spiral] = "box_spiral",
38 [XC_center_ptr] = "center_ptr",
39 [XC_circle] = "circle",
40 [XC_clock] = "clock",
41 [XC_coffee_mug] = "coffee_mug",
42 [XC_cross] = "cross",
43 [XC_cross_reverse] = "cross_reverse",
44 [XC_crosshair] = "crosshair",
45 [XC_diamond_cross] = "diamond_cross",
46 [XC_dot] = "dot",
47 [XC_dotbox] = "dotbox",
48 [XC_double_arrow] = "double_arrow",
49 [XC_draft_large] = "draft_large",
50 [XC_draft_small] = "draft_small",
51 [XC_draped_box] = "draped_box",
52 [XC_exchange] = "exchange",
53 [XC_fleur] = "fleur",
54 [XC_gobbler] = "gobbler",
55 [XC_gumby] = "gumby",
56 [XC_hand1] = "hand1",
57 [XC_hand2] = "hand2",
58 [XC_heart] = "heart",
59 [XC_icon] = "icon",
60 [XC_iron_cross] = "iron_cross",
61 [XC_left_ptr] = "left_ptr",
62 [XC_left_side] = "left_side",
63 [XC_left_tee] = "left_tee",
64 [XC_leftbutton] = "leftbutton",
65 [XC_ll_angle] = "ll_angle",
66 [XC_lr_angle] = "lr_angle",
67 [XC_man] = "man",
68 [XC_middlebutton] = "middlebutton",
69 [XC_mouse] = "mouse",
70 [XC_pencil] = "pencil",
71 [XC_pirate] = "pirate",
72 [XC_plus] = "plus",
73 [XC_question_arrow] = "question_arrow",
74 [XC_right_ptr] = "right_ptr",
75 [XC_right_side] = "right_side",
76 [XC_right_tee] = "right_tee",
77 [XC_rightbutton] = "rightbutton",
78 [XC_rtl_logo] = "rtl_logo",
79 [XC_sailboat] = "sailboat",
80 [XC_sb_down_arrow] = "sb_down_arrow",
81 [XC_sb_h_double_arrow] = "sb_h_double_arrow",
82 [XC_sb_left_arrow] = "sb_left_arrow",
83 [XC_sb_right_arrow] = "sb_right_arrow",
84 [XC_sb_up_arrow] = "sb_up_arrow",
85 [XC_sb_v_double_arrow] = "sb_v_double_arrow",
86 [XC_shuttle] = "shuttle",
87 [XC_sizing] = "sizing",
88 [XC_spider] = "spider",
89 [XC_spraycan] = "spraycan",
90 [XC_star] = "star",
91 [XC_target] = "target",
92 [XC_tcross] = "tcross",
93 [XC_top_left_arrow] = "top_left_arrow",
94 [XC_top_left_corner] = "top_left_corner",
95 [XC_top_right_corner] = "top_right_corner",
96 [XC_top_side] = "top_side",
97 [XC_top_tee] = "top_tee",
98 [XC_trek] = "trek",
99 [XC_ul_angle] = "ul_angle",
100 [XC_umbrella] = "umbrella",
101 [XC_ur_angle] = "ur_angle",
102 [XC_watch] = "watch",
103 [XC_xterm] = "xterm",
106 /** Get a cursor from a string.
107 * \param s The string.
109 uint16_t
110 xcursor_font_fromstr(const char *s)
112 if(s)
113 for(int i = 0; i < countof(xcursor_font); i++)
114 if(xcursor_font[i] && A_STREQ(s, xcursor_font[i]))
115 return i;
116 return 0;
119 /** Get a cursor name.
120 * \param c The cursor.
122 const char *
123 xcursor_font_tostr(uint16_t c)
125 if(c < countof(xcursor_font))
126 return xcursor_font[c];
127 return NULL;
130 /** Equivalent to 'XCreateFontCursor()', error are handled by the
131 * default current error handler.
132 * \param conn The connection to the X server.
133 * \param cursor_font Type of cursor to use.
134 * \return Allocated cursor font.
136 xcb_cursor_t
137 xcursor_new(Display *conn, uint16_t cursor_font)
139 static xcb_cursor_t xcursor[countof(xcursor_font)];
141 if (!xcursor[cursor_font]) {
142 xcursor[cursor_font] = XcursorLibraryLoadCursor(conn, xcursor_font_tostr(cursor_font));
145 return xcursor[cursor_font];
149 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80