aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/keyboard.c
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-27 15:17:01 -0500
committerLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-27 15:17:01 -0500
commitd941246d58b55b56179cfe159bec5b4bfb201d2e (patch)
tree8c6f787a1aa5d505a361f81aebb3e60c66b3ef8a /sway/input/keyboard.c
parentcompositor bindings (diff)
downloadsway-d941246d58b55b56179cfe159bec5b4bfb201d2e.tar.gz
sway-d941246d58b55b56179cfe159bec5b4bfb201d2e.tar.zst
sway-d941246d58b55b56179cfe159bec5b4bfb201d2e.zip
match user bindsym
Diffstat (limited to 'sway/input/keyboard.c')
-rw-r--r--sway/input/keyboard.c69
1 files changed, 49 insertions, 20 deletions
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c
index 68a95bac..326ee584 100644
--- a/sway/input/keyboard.c
+++ b/sway/input/keyboard.c
@@ -5,6 +5,27 @@
5#include "sway/input/input-manager.h" 5#include "sway/input/input-manager.h"
6#include "log.h" 6#include "log.h"
7 7
8static size_t pressed_keysyms_length(xkb_keysym_t *pressed_keysyms) {
9 size_t n = 0;
10 for (size_t i = 0; i < SWAY_KEYBOARD_PRESSED_KEYSYMS_CAP; ++i) {
11 if (pressed_keysyms[i] != XKB_KEY_NoSymbol) {
12 ++n;
13 }
14 }
15 return n;
16}
17
18static ssize_t pressed_keysyms_index(xkb_keysym_t *pressed_keysyms,
19 xkb_keysym_t keysym) {
20 for (size_t i = 0; i < SWAY_KEYBOARD_PRESSED_KEYSYMS_CAP; ++i) {
21 if (pressed_keysyms[i] == keysym) {
22 return i;
23 }
24 }
25 return -1;
26}
27
28
8/** 29/**
9 * Execute a built-in, hardcoded compositor binding. These are triggered from a 30 * Execute a built-in, hardcoded compositor binding. These are triggered from a
10 * single keysym. 31 * single keysym.
@@ -39,11 +60,39 @@ static bool keyboard_execute_compositor_binding(xkb_keysym_t keysym) {
39static bool keyboard_execute_binding(struct sway_keyboard *keyboard, 60static bool keyboard_execute_binding(struct sway_keyboard *keyboard,
40 xkb_keysym_t *pressed_keysyms, uint32_t modifiers, 61 xkb_keysym_t *pressed_keysyms, uint32_t modifiers,
41 const xkb_keysym_t *keysyms, size_t keysyms_len) { 62 const xkb_keysym_t *keysyms, size_t keysyms_len) {
63 // compositor bindings
42 for (size_t i = 0; i < keysyms_len; ++i) { 64 for (size_t i = 0; i < keysyms_len; ++i) {
43 if (keyboard_execute_compositor_binding(keysyms[i])) { 65 if (keyboard_execute_compositor_binding(keysyms[i])) {
44 return true; 66 return true;
45 } 67 }
46 } 68 }
69
70 // configured bindings
71 int n = pressed_keysyms_length(pressed_keysyms);
72 list_t *keysym_bindings = config->current_mode->keysym_bindings;
73 for (int i = 0; i < keysym_bindings->length; ++i) {
74 struct sway_binding *binding = keysym_bindings->items[i];
75 if (modifiers ^ binding->modifiers || n != binding->keys->length) {
76 continue;
77 }
78
79 bool match = true;
80 for (int j = 0; j < binding->keys->length; ++j) {
81 match =
82 pressed_keysyms_index(pressed_keysyms,
83 *(int*)binding->keys->items[j]) < 0;
84
85 if (!match) {
86 break;
87 }
88 }
89
90 if (match) {
91 sway_log(L_DEBUG, "TODO: executing binding command: %s", binding->command);
92 return true;
93 }
94 }
95
47 return false; 96 return false;
48} 97}
49 98
@@ -92,26 +141,6 @@ static size_t keyboard_keysyms_raw(struct sway_keyboard *keyboard,
92 keycode, layout_index, 0, keysyms); 141 keycode, layout_index, 0, keysyms);
93} 142}
94 143
95static ssize_t pressed_keysyms_index(xkb_keysym_t *pressed_keysyms,
96 xkb_keysym_t keysym) {
97 for (size_t i = 0; i < SWAY_KEYBOARD_PRESSED_KEYSYMS_CAP; ++i) {
98 if (pressed_keysyms[i] == keysym) {
99 return i;
100 }
101 }
102 return -1;
103}
104
105static size_t pressed_keysyms_length(xkb_keysym_t *pressed_keysyms) {
106 size_t n = 0;
107 for (size_t i = 0; i < SWAY_KEYBOARD_PRESSED_KEYSYMS_CAP; ++i) {
108 if (pressed_keysyms[i] != XKB_KEY_NoSymbol) {
109 ++n;
110 }
111 }
112 return n;
113}
114
115static void pressed_keysyms_add(xkb_keysym_t *pressed_keysyms, 144static void pressed_keysyms_add(xkb_keysym_t *pressed_keysyms,
116 xkb_keysym_t keysym) { 145 xkb_keysym_t keysym) {
117 ssize_t i = pressed_keysyms_index(pressed_keysyms, keysym); 146 ssize_t i = pressed_keysyms_index(pressed_keysyms, keysym);