diff options
Diffstat (limited to 'sway/input/keyboard.c')
-rw-r--r-- | sway/input/keyboard.c | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index 25def7ac..68a95bac 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c | |||
@@ -1,8 +1,52 @@ | |||
1 | #include <wlr/backend/multi.h> | ||
2 | #include <wlr/backend/session.h> | ||
1 | #include "sway/input/seat.h" | 3 | #include "sway/input/seat.h" |
2 | #include "sway/input/keyboard.h" | 4 | #include "sway/input/keyboard.h" |
3 | #include "sway/input/input-manager.h" | 5 | #include "sway/input/input-manager.h" |
4 | #include "log.h" | 6 | #include "log.h" |
5 | 7 | ||
8 | /** | ||
9 | * Execute a built-in, hardcoded compositor binding. These are triggered from a | ||
10 | * single keysym. | ||
11 | * | ||
12 | * Returns true if the keysym was handled by a binding and false if the event | ||
13 | * should be propagated to clients. | ||
14 | */ | ||
15 | static bool keyboard_execute_compositor_binding(xkb_keysym_t keysym) { | ||
16 | if (keysym >= XKB_KEY_XF86Switch_VT_1 && | ||
17 | keysym <= XKB_KEY_XF86Switch_VT_12) { | ||
18 | if (wlr_backend_is_multi(server.backend)) { | ||
19 | struct wlr_session *session = | ||
20 | wlr_multi_get_session(server.backend); | ||
21 | if (session) { | ||
22 | unsigned vt = keysym - XKB_KEY_XF86Switch_VT_1 + 1; | ||
23 | wlr_session_change_vt(session, vt); | ||
24 | } | ||
25 | } | ||
26 | return true; | ||
27 | } | ||
28 | |||
29 | return false; | ||
30 | } | ||
31 | |||
32 | /** | ||
33 | * Execute keyboard bindings. These include compositor bindings and user-defined | ||
34 | * bindings. | ||
35 | * | ||
36 | * Returns true if the keysym was handled by a binding and false if the event | ||
37 | * should be propagated to clients. | ||
38 | */ | ||
39 | static bool keyboard_execute_binding(struct sway_keyboard *keyboard, | ||
40 | xkb_keysym_t *pressed_keysyms, uint32_t modifiers, | ||
41 | const xkb_keysym_t *keysyms, size_t keysyms_len) { | ||
42 | for (size_t i = 0; i < keysyms_len; ++i) { | ||
43 | if (keyboard_execute_compositor_binding(keysyms[i])) { | ||
44 | return true; | ||
45 | } | ||
46 | } | ||
47 | return false; | ||
48 | } | ||
49 | |||
6 | /* | 50 | /* |
7 | * Get keysyms and modifiers from the keyboard as xkb sees them. | 51 | * Get keysyms and modifiers from the keyboard as xkb sees them. |
8 | * | 52 | * |
@@ -138,7 +182,9 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) { | |||
138 | pressed_keysyms_update(keyboard->pressed_keysyms_translated, keysyms, | 182 | pressed_keysyms_update(keyboard->pressed_keysyms_translated, keysyms, |
139 | keysyms_len, event->state); | 183 | keysyms_len, event->state); |
140 | if (event->state == WLR_KEY_PRESSED) { | 184 | if (event->state == WLR_KEY_PRESSED) { |
141 | // TODO execute binding | 185 | handled = keyboard_execute_binding(keyboard, |
186 | keyboard->pressed_keysyms_translated, modifiers, keysyms, | ||
187 | keysyms_len); | ||
142 | } | 188 | } |
143 | 189 | ||
144 | // Handle raw keysyms | 190 | // Handle raw keysyms |
@@ -146,7 +192,8 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) { | |||
146 | pressed_keysyms_update(keyboard->pressed_keysyms_raw, keysyms, keysyms_len, | 192 | pressed_keysyms_update(keyboard->pressed_keysyms_raw, keysyms, keysyms_len, |
147 | event->state); | 193 | event->state); |
148 | if (event->state == WLR_KEY_PRESSED && !handled) { | 194 | if (event->state == WLR_KEY_PRESSED && !handled) { |
149 | // TODO execute binding | 195 | handled = keyboard_execute_binding(keyboard, |
196 | keyboard->pressed_keysyms_raw, modifiers, keysyms, keysyms_len); | ||
150 | } | 197 | } |
151 | 198 | ||
152 | if (!handled) { | 199 | if (!handled) { |