diff options
Diffstat (limited to 'common/util.c')
-rw-r--r-- | common/util.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/common/util.c b/common/util.c index ed6d033f..b5037d35 100644 --- a/common/util.c +++ b/common/util.c | |||
@@ -13,3 +13,41 @@ int numlen(int n) { | |||
13 | if (n >= 10) return 2; | 13 | if (n >= 10) return 2; |
14 | return 1; | 14 | return 1; |
15 | } | 15 | } |
16 | |||
17 | static struct modifier_key { | ||
18 | char *name; | ||
19 | uint32_t mod; | ||
20 | } modifiers[] = { | ||
21 | { XKB_MOD_NAME_SHIFT, WLC_BIT_MOD_SHIFT }, | ||
22 | { XKB_MOD_NAME_CAPS, WLC_BIT_MOD_CAPS }, | ||
23 | { XKB_MOD_NAME_CTRL, WLC_BIT_MOD_CTRL }, | ||
24 | { "Ctrl", WLC_BIT_MOD_CTRL }, | ||
25 | { XKB_MOD_NAME_ALT, WLC_BIT_MOD_ALT }, | ||
26 | { "Alt", WLC_BIT_MOD_ALT }, | ||
27 | { XKB_MOD_NAME_NUM, WLC_BIT_MOD_MOD2 }, | ||
28 | { "Mod3", WLC_BIT_MOD_MOD3 }, | ||
29 | { XKB_MOD_NAME_LOGO, WLC_BIT_MOD_LOGO }, | ||
30 | { "Mod5", WLC_BIT_MOD_MOD5 }, | ||
31 | }; | ||
32 | |||
33 | uint32_t get_modifier_mask_by_name(const char *name) { | ||
34 | int i; | ||
35 | for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { | ||
36 | if (strcasecmp(modifiers[i].name, name) == 0) { | ||
37 | return modifiers[i].mod; | ||
38 | } | ||
39 | } | ||
40 | |||
41 | return 0; | ||
42 | } | ||
43 | |||
44 | const char *get_modifier_name_by_mask(uint32_t modifier) { | ||
45 | int i; | ||
46 | for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { | ||
47 | if (modifiers[i].mod == modifier) { | ||
48 | return modifiers[i].name; | ||
49 | } | ||
50 | } | ||
51 | |||
52 | return NULL; | ||
53 | } | ||