]> Dogcows Code - chaz/openbox/blob - plugins/mouse/translate.c
translate "Control" and "Shift" for modifiers too
[chaz/openbox] / plugins / mouse / translate.c
1 #include "../../kernel/openbox.h"
2 #include <glib.h>
3 #include <string.h>
4 #include <stdlib.h>
5
6 static guint translate_modifier(char *str)
7 {
8 if (!strcmp("Mod1", str) || !strcmp("A", str)) return Mod1Mask;
9 else if (!strcmp("Mod2", str)) return Mod2Mask;
10 else if (!strcmp("Mod3", str)) return Mod3Mask;
11 else if (!strcmp("Mod4", str) || !strcmp("W", str)) return Mod4Mask;
12 else if (!strcmp("Mod5", str)) return Mod5Mask;
13 else if (!strcmp("Control", str) || !strcmp("C", str)) return ControlMask;
14 else if (!strcmp("Shift", str) || !strcmp("S", str)) return ShiftMask;
15 g_warning("Invalid modifier '%s' in binding.", str);
16 return 0;
17 }
18
19 gboolean translate_button(char *str, guint *state, guint *button)
20 {
21 char **parsed;
22 char *l;
23 int i;
24 gboolean ret = FALSE;
25
26 parsed = g_strsplit(str, "-", -1);
27
28 /* first, find the button (last token) */
29 l = NULL;
30 for (i = 0; parsed[i] != NULL; ++i)
31 l = parsed[i];
32 if (l == NULL)
33 goto translation_fail;
34
35 /* figure out the mod mask */
36 *state = 0;
37 for (i = 0; parsed[i] != l; ++i) {
38 guint m = translate_modifier(parsed[i]);
39 if (!m) goto translation_fail;
40 *state |= m;
41 }
42
43 /* figure out the button */
44 *button = atoi(l);
45 if (!*button) {
46 g_warning("Invalid button '%s' in pointer binding.", l);
47 goto translation_fail;
48 }
49
50 ret = TRUE;
51
52 translation_fail:
53 g_strfreev(parsed);
54 return ret;
55 }
This page took 0.037933 seconds and 5 git commands to generate.