]>
Dogcows Code - chaz/openbox/blob - keyboard/translate.c
1 #include "../../kernel/openbox.h"
5 static guint
translate_modifier(char *str
)
7 if (!g_ascii_strcasecmp("Mod1", str
) ||
8 !g_ascii_strcasecmp("A", str
)) return Mod1Mask
;
9 else if (!g_ascii_strcasecmp("Mod2", str
)) return Mod2Mask
;
10 else if (!g_ascii_strcasecmp("Mod3", str
)) return Mod3Mask
;
11 else if (!g_ascii_strcasecmp("Mod4", str
) ||
12 !g_ascii_strcasecmp("W", str
)) return Mod4Mask
;
13 else if (!g_ascii_strcasecmp("Mod5", str
)) return Mod5Mask
;
14 else if (!g_ascii_strcasecmp("Control", str
) ||
15 !g_ascii_strcasecmp("C", str
)) return ControlMask
;
16 else if (!g_ascii_strcasecmp("Shift", str
) ||
17 !g_ascii_strcasecmp("S", str
)) return ShiftMask
;
18 g_message("Invalid modifier '%s' in binding.", str
);
22 gboolean
translate_key(char *str
, guint
*state
, guint
*keycode
)
30 parsed
= g_strsplit(str
, "-", -1);
32 /* first, find the key (last token) */
34 for (i
= 0; parsed
[i
] != NULL
; ++i
)
37 goto translation_fail
;
39 /* figure out the mod mask */
41 for (i
= 0; parsed
[i
] != l
; ++i
) {
42 guint m
= translate_modifier(parsed
[i
]);
43 if (!m
) goto translation_fail
;
47 /* figure out the keycode */
48 sym
= XStringToKeysym(l
);
49 if (sym
== NoSymbol
) {
50 g_message("Invalid key name '%s' in key binding.", l
);
51 goto translation_fail
;
53 *keycode
= XKeysymToKeycode(ob_display
, sym
);
55 g_message("Key '%s' does not exist on the display.", l
);
56 goto translation_fail
;
This page took 0.037946 seconds and 4 git commands to generate.