1 #include "kernel/openbox.h"
7 static guint translate_modifier(char *str)
9 if (!g_ascii_strcasecmp("Mod1", str) ||
10 !g_ascii_strcasecmp("A", str)) return Mod1Mask;
11 else if (!g_ascii_strcasecmp("Mod2", str)) return Mod2Mask;
12 else if (!g_ascii_strcasecmp("Mod3", str)) return Mod3Mask;
13 else if (!g_ascii_strcasecmp("Mod4", str) ||
14 !g_ascii_strcasecmp("W", str)) return Mod4Mask;
15 else if (!g_ascii_strcasecmp("Mod5", str)) return Mod5Mask;
16 else if (!g_ascii_strcasecmp("Control", str) ||
17 !g_ascii_strcasecmp("C", str)) return ControlMask;
18 else if (!g_ascii_strcasecmp("Shift", str) ||
19 !g_ascii_strcasecmp("S", str)) return ShiftMask;
20 g_warning("Invalid modifier '%s' in binding.", str);
24 gboolean translate_button(char *str, guint *state, guint *button)
31 parsed = g_strsplit(str, "-", -1);
33 /* first, find the button (last token) */
35 for (i = 0; parsed[i] != NULL; ++i)
38 goto translation_fail;
40 /* figure out the mod mask */
42 for (i = 0; parsed[i] != l; ++i) {
43 guint m = translate_modifier(parsed[i]);
44 if (!m) goto translation_fail;
48 /* figure out the button */
49 if (!g_ascii_strcasecmp("Left", l)) *button = 1;
50 else if (!g_ascii_strcasecmp("Middle", l)) *button = 2;
51 else if (!g_ascii_strcasecmp("Right", l)) *button = 3;
52 else if (!g_ascii_strcasecmp("Up", l)) *button = 4;
53 else if (!g_ascii_strcasecmp("Down", l)) *button = 5;
54 else if (!g_ascii_strncasecmp("Button", l, 6)) *button = atoi(l+6);
56 g_warning("Invalid button '%s' in pointer binding.", l);
57 goto translation_fail;
67 gboolean translate_key(char *str, guint *state, guint *keycode)
75 parsed = g_strsplit(str, "-", -1);
77 /* first, find the key (last token) */
79 for (i = 0; parsed[i] != NULL; ++i)
82 goto translation_fail;
84 /* figure out the mod mask */
86 for (i = 0; parsed[i] != l; ++i) {
87 guint m = translate_modifier(parsed[i]);
88 if (!m) goto translation_fail;
92 /* figure out the keycode */
93 sym = XStringToKeysym(l);
94 if (sym == NoSymbol) {
95 g_warning("Invalid key name '%s' in key binding.", l);
96 goto translation_fail;
98 *keycode = XKeysymToKeycode(ob_display, sym);
100 g_warning("Key '%s' does not exist on the display.", l);
101 goto translation_fail;