* Fixed StickyAcrossPages style in the FvwmPager.
[fvwm.git] / libs / Cursor.c
blob299a5d298f4660b31fbfe571369415d9cbdb0469
1 /* -*-c-*- */
2 /* This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 /* Modification History */
19 /* Created on 10/05/01 by Dan Espen (dane):
20 Extracted from fvwm/cursor.c.
21 Contains common routine to verify and convert a cursor name
22 into a cursor number from X11/cursorfont.h.
23 Used by fvwm CursorStyle command and FvwmForm.
25 #include "config.h"
26 #include <stdio.h>
27 #include "fvwmlib.h"
28 #include <X11/cursorfont.h>
29 #include "Cursor.h"
32 * fvwmCursorNameToIndex: return the number of a X11 cursor from its
33 * name, if not found return -1.
35 int fvwmCursorNameToIndex (char *cursor_name)
37 static const struct CursorNameIndex {
38 const char *name;
39 unsigned int number;
40 } cursor_table[] = {
41 {"arrow", XC_arrow},
42 {"based_arrow_down", XC_based_arrow_down},
43 {"based_arrow_up", XC_based_arrow_up},
44 {"boat", XC_boat},
45 {"bogosity", XC_bogosity},
46 {"bottom_left_corner", XC_bottom_left_corner},
47 {"bottom_right_corner", XC_bottom_right_corner},
48 {"bottom_side", XC_bottom_side},
49 {"bottom_tee", XC_bottom_tee},
50 {"box_spiral", XC_box_spiral},
51 {"center_ptr", XC_center_ptr},
52 {"circle", XC_circle},
53 {"clock", XC_clock},
54 {"coffee_mug", XC_coffee_mug},
55 {"cross", XC_cross},
56 {"cross_reverse", XC_cross_reverse},
57 {"crosshair", XC_crosshair},
58 {"diamond_cross", XC_diamond_cross},
59 {"dot", XC_dot},
60 {"dotbox", XC_dotbox},
61 {"double_arrow", XC_double_arrow},
62 {"draft_large", XC_draft_large},
63 {"draft_small", XC_draft_small},
64 {"draped_box", XC_draped_box},
65 {"exchange", XC_exchange},
66 {"fleur", XC_fleur},
67 {"gobbler", XC_gobbler},
68 {"gumby", XC_gumby},
69 {"hand1", XC_hand1},
70 {"hand2", XC_hand2},
71 {"heart", XC_heart},
72 {"icon", XC_icon},
73 {"iron_cross", XC_iron_cross},
74 {"left_ptr", XC_left_ptr},
75 {"left_side", XC_left_side},
76 {"left_tee", XC_left_tee},
77 {"leftbutton", XC_leftbutton},
78 {"ll_angle", XC_ll_angle},
79 {"lr_angle", XC_lr_angle},
80 {"man", XC_man},
81 {"middlebutton", XC_middlebutton},
82 {"mouse", XC_mouse},
83 {"pencil", XC_pencil},
84 {"pirate", XC_pirate},
85 {"plus", XC_plus},
86 {"question_arrow", XC_question_arrow},
87 {"right_ptr", XC_right_ptr},
88 {"right_side", XC_right_side},
89 {"right_tee", XC_right_tee},
90 {"rightbutton", XC_rightbutton},
91 {"rtl_logo", XC_rtl_logo},
92 {"sailboat", XC_sailboat},
93 {"sb_down_arrow", XC_sb_down_arrow},
94 {"sb_h_double_arrow", XC_sb_h_double_arrow},
95 {"sb_left_arrow", XC_sb_left_arrow},
96 {"sb_right_arrow", XC_sb_right_arrow},
97 {"sb_up_arrow", XC_sb_up_arrow},
98 {"sb_v_double_arrow", XC_sb_v_double_arrow},
99 {"sizing", XC_sizing},
100 {"spider", XC_spider},
101 {"spraycan", XC_spraycan},
102 {"star", XC_star},
103 {"target", XC_target},
104 {"tcross", XC_tcross},
105 {"top_left_arrow", XC_top_left_arrow},
106 {"top_left_corner", XC_top_left_corner},
107 {"top_right_corner", XC_top_right_corner},
108 {"top_side", XC_top_side},
109 {"top_tee", XC_top_tee},
110 {"trek", XC_trek},
111 {"ul_angle", XC_ul_angle},
112 {"umbrella", XC_umbrella},
113 {"ur_angle", XC_ur_angle},
114 {"watch", XC_watch},
115 {"x_cursor", XC_X_cursor},
116 {"xterm", XC_xterm},
119 int cond;
120 int down = 0;
121 int up = (sizeof cursor_table / sizeof cursor_table[0]) - 1;
122 int middle;
123 char temp[20];
124 char *s;
126 if (!cursor_name || cursor_name[0] == 0 ||
127 strlen(cursor_name) >= sizeof temp)
128 return -1;
129 strcpy(temp, cursor_name);
131 for (s = temp; *s != 0; s++)
132 if (isupper(*s))
133 *s = tolower(*s);
135 while (down <= up)
137 middle= (down + up) / 2;
138 if ((cond = strcmp(temp, cursor_table[middle].name)) < 0)
139 up = middle - 1;
140 else if (cond > 0)
141 down = middle + 1;
142 else
143 return cursor_table[middle].number;
145 return -1;