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