File: xcursor.c

package info (click to toggle)
awesome 4.3-8.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,468 kB
  • sloc: ansic: 14,508; sh: 526; makefile: 46
file content (151 lines) | stat: -rw-r--r-- 4,620 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
 * xcursor.c - X cursors management
 *
 * Copyright © 2008 Julien Danjou <julien@danjou.info>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

#include "common/xcursor.h"
#include "common/util.h"

#include <X11/cursorfont.h>

static char const * const xcursor_font[] =
{
    [XC_X_cursor] = "X_cursor",
    [XC_arrow] = "arrow",
    [XC_based_arrow_down] = "based_arrow_down",
    [XC_based_arrow_up] = "based_arrow_up",
    [XC_boat] = "boat",
    [XC_bogosity] = "bogosity",
    [XC_bottom_left_corner] = "bottom_left_corner",
    [XC_bottom_right_corner] = "bottom_right_corner",
    [XC_bottom_side] = "bottom_side",
    [XC_bottom_tee] = "bottom_tee",
    [XC_box_spiral] = "box_spiral",
    [XC_center_ptr] = "center_ptr",
    [XC_circle] = "circle",
    [XC_clock] = "clock",
    [XC_coffee_mug] = "coffee_mug",
    [XC_cross] = "cross",
    [XC_cross_reverse] = "cross_reverse",
    [XC_crosshair] = "crosshair",
    [XC_diamond_cross] = "diamond_cross",
    [XC_dot] = "dot",
    [XC_dotbox] = "dotbox",
    [XC_double_arrow] = "double_arrow",
    [XC_draft_large] = "draft_large",
    [XC_draft_small] = "draft_small",
    [XC_draped_box] = "draped_box",
    [XC_exchange] = "exchange",
    [XC_fleur] = "fleur",
    [XC_gobbler] = "gobbler",
    [XC_gumby] = "gumby",
    [XC_hand1] = "hand1",
    [XC_hand2] = "hand2",
    [XC_heart] = "heart",
    [XC_icon] = "icon",
    [XC_iron_cross] = "iron_cross",
    [XC_left_ptr] = "left_ptr",
    [XC_left_side] = "left_side",
    [XC_left_tee] = "left_tee",
    [XC_leftbutton] = "leftbutton",
    [XC_ll_angle] = "ll_angle",
    [XC_lr_angle] = "lr_angle",
    [XC_man] = "man",
    [XC_middlebutton] = "middlebutton",
    [XC_mouse] = "mouse",
    [XC_pencil] = "pencil",
    [XC_pirate] = "pirate",
    [XC_plus] = "plus",
    [XC_question_arrow] = "question_arrow",
    [XC_right_ptr] = "right_ptr",
    [XC_right_side] = "right_side",
    [XC_right_tee] = "right_tee",
    [XC_rightbutton] = "rightbutton",
    [XC_rtl_logo] = "rtl_logo",
    [XC_sailboat] = "sailboat",
    [XC_sb_down_arrow] = "sb_down_arrow",
    [XC_sb_h_double_arrow] = "sb_h_double_arrow",
    [XC_sb_left_arrow] = "sb_left_arrow",
    [XC_sb_right_arrow] = "sb_right_arrow",
    [XC_sb_up_arrow] = "sb_up_arrow",
    [XC_sb_v_double_arrow] = "sb_v_double_arrow",
    [XC_shuttle] = "shuttle",
    [XC_sizing] = "sizing",
    [XC_spider] = "spider",
    [XC_spraycan] = "spraycan",
    [XC_star] = "star",
    [XC_target] = "target",
    [XC_tcross] = "tcross",
    [XC_top_left_arrow] = "top_left_arrow",
    [XC_top_left_corner] = "top_left_corner",
    [XC_top_right_corner] = "top_right_corner",
    [XC_top_side] = "top_side",
    [XC_top_tee] = "top_tee",
    [XC_trek] = "trek",
    [XC_ul_angle] = "ul_angle",
    [XC_umbrella] = "umbrella",
    [XC_ur_angle] = "ur_angle",
    [XC_watch] = "watch",
    [XC_xterm] = "xterm",
};

/** Get a cursor from a string.
 * \param s The string.
 */
uint16_t
xcursor_font_fromstr(const char *s)
{
    if(s)
        for(int i = 0; i < countof(xcursor_font); i++)
            if(xcursor_font[i] && A_STREQ(s, xcursor_font[i]))
                return i;
    return 0;
}

/** Get a cursor name.
 * \param c The cursor.
 */
const char *
xcursor_font_tostr(uint16_t c)
{
    if(c < countof(xcursor_font))
        return xcursor_font[c];
    return NULL;
}

/** Equivalent to 'XCreateFontCursor()', error are handled by the
 * default current error handler.
 * \param ctx The xcb-cursor context.
 * \param cursor_font Type of cursor to use.
 * \return Allocated cursor font.
 */
xcb_cursor_t
xcursor_new(xcb_cursor_context_t *ctx, uint16_t cursor_font)
{
    static xcb_cursor_t xcursor[countof(xcursor_font)];

    if (!xcursor[cursor_font]) {
        xcursor[cursor_font] = xcb_cursor_load_cursor(ctx, xcursor_font_tostr(cursor_font));
    }

    return xcursor[cursor_font];
}


// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80