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/keyboard.c | |
parent | swaybar: fix setting floating watcher slots (diff) | |
download | sway-d7ff776552bef524e905d85c2a5e7651c8408658.tar.gz sway-d7ff776552bef524e905d85c2a5e7651c8408658.tar.zst sway-d7ff776552bef524e905d85c2a5e7651c8408658.zip |
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/keyboard.c')
-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 @@ | |||
1 | #include <assert.h> | 1 | #include <assert.h> |
2 | #include <limits.h> | 2 | #include <limits.h> |
3 | #include <strings.h> | ||
3 | #include <wlr/backend/multi.h> | 4 | #include <wlr/backend/multi.h> |
4 | #include <wlr/backend/session.h> | 5 | #include <wlr/backend/session.h> |
5 | #include <wlr/types/wlr_idle.h> | 6 | #include <wlr/types/wlr_idle.h> |
6 | #include <wlr/interfaces/wlr_keyboard.h> | 7 | #include <wlr/interfaces/wlr_keyboard.h> |
8 | #include <xkbcommon/xkbcommon-names.h> | ||
7 | #include "sway/commands.h" | 9 | #include "sway/commands.h" |
8 | #include "sway/desktop/transaction.h" | 10 | #include "sway/desktop/transaction.h" |
9 | #include "sway/input/input-manager.h" | 11 | #include "sway/input/input-manager.h" |
@@ -12,6 +14,58 @@ | |||
12 | #include "sway/ipc-server.h" | 14 | #include "sway/ipc-server.h" |
13 | #include "log.h" | 15 | #include "log.h" |
14 | 16 | ||
17 | static struct modifier_key { | ||
18 | char *name; | ||
19 | uint32_t mod; | ||
20 | } modifiers[] = { | ||
21 | { XKB_MOD_NAME_SHIFT, WLR_MODIFIER_SHIFT }, | ||
22 | { XKB_MOD_NAME_CAPS, WLR_MODIFIER_CAPS }, | ||
23 | { XKB_MOD_NAME_CTRL, WLR_MODIFIER_CTRL }, | ||
24 | { "Ctrl", WLR_MODIFIER_CTRL }, | ||
25 | { XKB_MOD_NAME_ALT, WLR_MODIFIER_ALT }, | ||
26 | { "Alt", WLR_MODIFIER_ALT }, | ||
27 | { XKB_MOD_NAME_NUM, WLR_MODIFIER_MOD2 }, | ||
28 | { "Mod3", WLR_MODIFIER_MOD3 }, | ||
29 | { XKB_MOD_NAME_LOGO, WLR_MODIFIER_LOGO }, | ||
30 | { "Mod5", WLR_MODIFIER_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 | } | ||
54 | |||
55 | int get_modifier_names(const char **names, uint32_t modifier_masks) { | ||
56 | int length = 0; | ||
57 | int i; | ||
58 | for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { | ||
59 | if ((modifier_masks & modifiers[i].mod) != 0) { | ||
60 | names[length] = modifiers[i].name; | ||
61 | ++length; | ||
62 | modifier_masks ^= modifiers[i].mod; | ||
63 | } | ||
64 | } | ||
65 | |||
66 | return length; | ||
67 | } | ||
68 | |||
15 | /** | 69 | /** |
16 | * Remove all key ids associated to a keycode from the list of pressed keys | 70 | * Remove all key ids associated to a keycode from the list of pressed keys |
17 | */ | 71 | */ |