diff options
author | M Stoeckl <code@mstoeckl.com> | 2019-01-21 12:39:16 -0500 |
---|---|---|
committer | M Stoeckl <code@mstoeckl.com> | 2019-01-21 12:39:16 -0500 |
commit | d7ff776552bef524e905d85c2a5e7651c8408658 (patch) | |
tree | ae20feac64f93f776e9c9e136c62459705e97987 /sway/input | |
parent | 410c961388bbfecb5f1b63e4a1977a78709a6e57 (diff) |
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 .
Diffstat (limited to 'sway/input')
-rw-r--r-- | sway/input/keyboard.c | 54 |
1 files changed, 54 insertions, 0 deletions
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 <assert.h> #include <limits.h> +#include <strings.h> #include <wlr/backend/multi.h> #include <wlr/backend/session.h> #include <wlr/types/wlr_idle.h> #include <wlr/interfaces/wlr_keyboard.h> +#include <xkbcommon/xkbcommon-names.h> #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 */ |