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",
29 [XC_based_arrow_down
] = "based_arrow_down",
30 [XC_based_arrow_up
] = "based_arrow_up",
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",
41 [XC_coffee_mug
] = "coffee_mug",
43 [XC_cross_reverse
] = "cross_reverse",
44 [XC_crosshair
] = "crosshair",
45 [XC_diamond_cross
] = "diamond_cross",
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",
54 [XC_gobbler
] = "gobbler",
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",
68 [XC_middlebutton
] = "middlebutton",
70 [XC_pencil
] = "pencil",
71 [XC_pirate
] = "pirate",
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",
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",
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.
110 xcursor_font_fromstr(const char *s
)
113 for(int i
= 0; i
< countof(xcursor_font
); i
++)
114 if(xcursor_font
[i
] && A_STREQ(s
, xcursor_font
[i
]))
119 /** Get a cursor name.
120 * \param c The cursor.
123 xcursor_font_tostr(uint16_t c
)
125 if(c
< countof(xcursor_font
))
126 return xcursor_font
[c
];
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.
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