diff options
author | Mikkel Oscar Lyderik <mikkeloscar@gmail.com> | 2016-01-05 18:07:43 +0100 |
---|---|---|
committer | Mikkel Oscar Lyderik <mikkeloscar@gmail.com> | 2016-01-05 18:36:24 +0100 |
commit | 95e0f44c73f2783541b180c9bd555f6b8abb7c0f (patch) | |
tree | f9f48b2376434e631fee5638b0dfe7c4ffa9eb83 /common | |
parent | c20c63b677c03b17441f0d135b5325e23d65f38d (diff) | |
download | sway-95e0f44c73f2783541b180c9bd555f6b8abb7c0f.tar.xz |
Move modifier name table to common/util.c
Lookup of modifier names is required in several places, thus it makes
sense to move it to a general place.
Diffstat (limited to 'common')
-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) { if (n >= 10) return 2; return 1; } + +static struct modifier_key { + char *name; + uint32_t mod; +} modifiers[] = { + { XKB_MOD_NAME_SHIFT, WLC_BIT_MOD_SHIFT }, + { XKB_MOD_NAME_CAPS, WLC_BIT_MOD_CAPS }, + { XKB_MOD_NAME_CTRL, WLC_BIT_MOD_CTRL }, + { "Ctrl", WLC_BIT_MOD_CTRL }, + { XKB_MOD_NAME_ALT, WLC_BIT_MOD_ALT }, + { "Alt", WLC_BIT_MOD_ALT }, + { XKB_MOD_NAME_NUM, WLC_BIT_MOD_MOD2 }, + { "Mod3", WLC_BIT_MOD_MOD3 }, + { XKB_MOD_NAME_LOGO, WLC_BIT_MOD_LOGO }, + { "Mod5", WLC_BIT_MOD_MOD5 }, +}; + +uint32_t get_modifier_mask_by_name(const char *name) { + int i; + for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { + if (strcasecmp(modifiers[i].name, name) == 0) { + return modifiers[i].mod; + } + } + + return 0; +} + +const char *get_modifier_name_by_mask(uint32_t modifier) { + int i; + for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { + if (modifiers[i].mod == modifier) { + return modifiers[i].name; + } + } + + return NULL; +} |