]>
Dogcows Code - chaz/openbox/blob - openbox/translate.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 translate.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003 Ben Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
26 static guint
translate_modifier(gchar
*str
)
28 if (!g_ascii_strcasecmp("Mod1", str
) ||
29 !g_ascii_strcasecmp("A", str
)) return Mod1Mask
;
30 else if (!g_ascii_strcasecmp("Mod2", str
)) return Mod2Mask
;
31 else if (!g_ascii_strcasecmp("Mod3", str
) ||
32 !g_ascii_strcasecmp("M", str
)) return Mod3Mask
;
33 else if (!g_ascii_strcasecmp("Mod4", str
) ||
34 !g_ascii_strcasecmp("W", str
)) return Mod4Mask
;
35 else if (!g_ascii_strcasecmp("Mod5", str
)) return Mod5Mask
;
36 else if (!g_ascii_strcasecmp("Control", str
) ||
37 !g_ascii_strcasecmp("C", str
)) return ControlMask
;
38 else if (!g_ascii_strcasecmp("Shift", str
) ||
39 !g_ascii_strcasecmp("S", str
)) return ShiftMask
;
40 g_warning("Invalid modifier '%s' in binding.", str
);
44 gboolean
translate_button(const gchar
*str
, guint
*state
, guint
*button
)
51 parsed
= g_strsplit(str
, "-", -1);
53 /* first, find the button (last token) */
55 for (i
= 0; parsed
[i
] != NULL
; ++i
)
58 goto translation_fail
;
60 /* figure out the mod mask */
62 for (i
= 0; parsed
[i
] != l
; ++i
) {
63 guint m
= translate_modifier(parsed
[i
]);
64 if (!m
) goto translation_fail
;
68 /* figure out the button */
69 if (!g_ascii_strcasecmp("Left", l
)) *button
= 1;
70 else if (!g_ascii_strcasecmp("Middle", l
)) *button
= 2;
71 else if (!g_ascii_strcasecmp("Right", l
)) *button
= 3;
72 else if (!g_ascii_strcasecmp("Up", l
)) *button
= 4;
73 else if (!g_ascii_strcasecmp("Down", l
)) *button
= 5;
74 else if (!g_ascii_strncasecmp("Button", l
, 6)) *button
= atoi(l
+6);
76 g_warning("Invalid button '%s' in pointer binding.", l
);
77 goto translation_fail
;
87 gboolean
translate_key(const gchar
*str
, guint
*state
, guint
*keycode
)
95 parsed
= g_strsplit(str
, "-", -1);
97 /* first, find the key (last token) */
99 for (i
= 0; parsed
[i
] != NULL
; ++i
)
102 goto translation_fail
;
104 /* figure out the mod mask */
106 for (i
= 0; parsed
[i
] != l
; ++i
) {
107 guint m
= translate_modifier(parsed
[i
]);
108 if (!m
) goto translation_fail
;
112 if (!g_ascii_strncasecmp("0x", l
, 2)) {
115 /* take it directly */
116 *keycode
= strtol(l
, &end
, 16);
117 if (*l
== '\0' || *end
!= '\0') {
118 g_warning("Invalid key code '%s' in key binding.", l
);
119 goto translation_fail
;
122 /* figure out the keycode */
123 sym
= XStringToKeysym(l
);
124 if (sym
== NoSymbol
) {
125 g_warning("Invalid key name '%s' in key binding.", l
);
126 goto translation_fail
;
128 *keycode
= XKeysymToKeycode(ob_display
, sym
);
131 g_warning("Key '%s' does not exist on the display.", l
);
132 goto translation_fail
;
This page took 0.040875 seconds and 4 git commands to generate.