From d7ff776552bef524e905d85c2a5e7651c8408658 Mon Sep 17 00:00:00 2001 From: M Stoeckl Date: Mon, 21 Jan 2019 12:39:16 -0500 Subject: Move sway-specific functions in common/util.c into sway/ Modifier handling functions were moved into sway/input/keyboard.c; opposite_direction for enum wlr_direction into sway/tree/output.c; and get_parent_pid into sway/tree/root.c . --- sway/input/keyboard.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'sway/input/keyboard.c') diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index c1fc60f7..12c57366 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c @@ -1,9 +1,11 @@ #include #include +#include #include #include #include #include +#include #include "sway/commands.h" #include "sway/desktop/transaction.h" #include "sway/input/input-manager.h" @@ -12,6 +14,58 @@ #include "sway/ipc-server.h" #include "log.h" +static struct modifier_key { + char *name; + uint32_t mod; +} modifiers[] = { + { XKB_MOD_NAME_SHIFT, WLR_MODIFIER_SHIFT }, + { XKB_MOD_NAME_CAPS, WLR_MODIFIER_CAPS }, + { XKB_MOD_NAME_CTRL, WLR_MODIFIER_CTRL }, + { "Ctrl", WLR_MODIFIER_CTRL }, + { XKB_MOD_NAME_ALT, WLR_MODIFIER_ALT }, + { "Alt", WLR_MODIFIER_ALT }, + { XKB_MOD_NAME_NUM, WLR_MODIFIER_MOD2 }, + { "Mod3", WLR_MODIFIER_MOD3 }, + { XKB_MOD_NAME_LOGO, WLR_MODIFIER_LOGO }, + { "Mod5", WLR_MODIFIER_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; +} + +int get_modifier_names(const char **names, uint32_t modifier_masks) { + int length = 0; + int i; + for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { + if ((modifier_masks & modifiers[i].mod) != 0) { + names[length] = modifiers[i].name; + ++length; + modifier_masks ^= modifiers[i].mod; + } + } + + return length; +} + /** * Remove all key ids associated to a keycode from the list of pressed keys */ -- cgit v1.2.3