diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2018-10-18 13:13:40 -0400 |
---|---|---|
committer | Brian Ashworth <bosrsf04@gmail.com> | 2018-10-18 13:42:01 -0400 |
commit | 2e637b7368de565a85f77fbd03408f33b763dd7b (patch) | |
tree | 00f3a082111e02dc2d7e7e54af60db4e58ebfc26 /sway/input/keyboard.c | |
parent | Merge pull request #2874 from ianyfan/swaybar (diff) | |
download | sway-2e637b7368de565a85f77fbd03408f33b763dd7b.tar.gz sway-2e637b7368de565a85f77fbd03408f33b763dd7b.tar.zst sway-2e637b7368de565a85f77fbd03408f33b763dd7b.zip |
cmd_bind{sym,code}: Implement per-device bindings
bindsym --input-device=<identifier> ...
bindcode --input-device=<identifier> ...
Diffstat (limited to 'sway/input/keyboard.c')
-rw-r--r-- | sway/input/keyboard.c | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index 2c8b41cd..4427dabe 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c | |||
@@ -87,7 +87,7 @@ static void update_shortcut_state(struct sway_shortcut_state *state, | |||
87 | */ | 87 | */ |
88 | static void get_active_binding(const struct sway_shortcut_state *state, | 88 | static void get_active_binding(const struct sway_shortcut_state *state, |
89 | list_t *bindings, struct sway_binding **current_binding, | 89 | list_t *bindings, struct sway_binding **current_binding, |
90 | uint32_t modifiers, bool release, bool locked) { | 90 | uint32_t modifiers, bool release, bool locked, const char *input) { |
91 | for (int i = 0; i < bindings->length; ++i) { | 91 | for (int i = 0; i < bindings->length; ++i) { |
92 | struct sway_binding *binding = bindings->items[i]; | 92 | struct sway_binding *binding = bindings->items[i]; |
93 | bool binding_locked = binding->flags & BINDING_LOCKED; | 93 | bool binding_locked = binding->flags & BINDING_LOCKED; |
@@ -96,7 +96,9 @@ static void get_active_binding(const struct sway_shortcut_state *state, | |||
96 | if (modifiers ^ binding->modifiers || | 96 | if (modifiers ^ binding->modifiers || |
97 | state->npressed != (size_t)binding->keys->length || | 97 | state->npressed != (size_t)binding->keys->length || |
98 | release != binding_release || | 98 | release != binding_release || |
99 | locked > binding_locked) { | 99 | locked > binding_locked || |
100 | (strcmp(binding->input, input) != 0 && | ||
101 | strcmp(binding->input, "*") != 0)) { | ||
100 | continue; | 102 | continue; |
101 | } | 103 | } |
102 | 104 | ||
@@ -112,13 +114,19 @@ static void get_active_binding(const struct sway_shortcut_state *state, | |||
112 | continue; | 114 | continue; |
113 | } | 115 | } |
114 | 116 | ||
115 | if (*current_binding && *current_binding != binding) { | 117 | if (*current_binding && *current_binding != binding && |
118 | strcmp((*current_binding)->input, binding->input) == 0) { | ||
116 | wlr_log(WLR_DEBUG, "encountered duplicate bindings %d and %d", | 119 | wlr_log(WLR_DEBUG, "encountered duplicate bindings %d and %d", |
117 | (*current_binding)->order, binding->order); | 120 | (*current_binding)->order, binding->order); |
118 | } else { | 121 | } else if (!*current_binding || |
122 | strcmp((*current_binding)->input, "*") == 0) { | ||
119 | *current_binding = binding; | 123 | *current_binding = binding; |
124 | |||
125 | if (strcmp((*current_binding)->input, input) == 0) { | ||
126 | // If a binding is found for the exact input, quit searching | ||
127 | return; | ||
128 | } | ||
120 | } | 129 | } |
121 | return; | ||
122 | } | 130 | } |
123 | } | 131 | } |
124 | 132 | ||
@@ -202,6 +210,7 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) { | |||
202 | struct wlr_seat *wlr_seat = seat->wlr_seat; | 210 | struct wlr_seat *wlr_seat = seat->wlr_seat; |
203 | struct wlr_input_device *wlr_device = | 211 | struct wlr_input_device *wlr_device = |
204 | keyboard->seat_device->input_device->wlr_device; | 212 | keyboard->seat_device->input_device->wlr_device; |
213 | char *device_identifier = input_device_get_identifier(wlr_device); | ||
205 | wlr_idle_notify_activity(seat->input->server->idle, wlr_seat); | 214 | wlr_idle_notify_activity(seat->input->server->idle, wlr_seat); |
206 | struct wlr_event_keyboard_key *event = data; | 215 | struct wlr_event_keyboard_key *event = data; |
207 | bool input_inhibited = seat->exclusive_client != NULL; | 216 | bool input_inhibited = seat->exclusive_client != NULL; |
@@ -242,13 +251,13 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) { | |||
242 | struct sway_binding *binding_released = NULL; | 251 | struct sway_binding *binding_released = NULL; |
243 | get_active_binding(&keyboard->state_keycodes, | 252 | get_active_binding(&keyboard->state_keycodes, |
244 | config->current_mode->keycode_bindings, &binding_released, | 253 | config->current_mode->keycode_bindings, &binding_released, |
245 | code_modifiers, true, input_inhibited); | 254 | code_modifiers, true, input_inhibited, device_identifier); |
246 | get_active_binding(&keyboard->state_keysyms_translated, | 255 | get_active_binding(&keyboard->state_keysyms_translated, |
247 | config->current_mode->keysym_bindings, &binding_released, | 256 | config->current_mode->keysym_bindings, &binding_released, |
248 | translated_modifiers, true, input_inhibited); | 257 | translated_modifiers, true, input_inhibited, device_identifier); |
249 | get_active_binding(&keyboard->state_keysyms_raw, | 258 | get_active_binding(&keyboard->state_keysyms_raw, |
250 | config->current_mode->keysym_bindings, &binding_released, | 259 | config->current_mode->keysym_bindings, &binding_released, |
251 | raw_modifiers, true, input_inhibited); | 260 | raw_modifiers, true, input_inhibited, device_identifier); |
252 | 261 | ||
253 | // Execute stored release binding once no longer active | 262 | // Execute stored release binding once no longer active |
254 | if (keyboard->held_binding && binding_released != keyboard->held_binding && | 263 | if (keyboard->held_binding && binding_released != keyboard->held_binding && |
@@ -268,13 +277,14 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) { | |||
268 | if (event->state == WLR_KEY_PRESSED) { | 277 | if (event->state == WLR_KEY_PRESSED) { |
269 | get_active_binding(&keyboard->state_keycodes, | 278 | get_active_binding(&keyboard->state_keycodes, |
270 | config->current_mode->keycode_bindings, &binding, | 279 | config->current_mode->keycode_bindings, &binding, |
271 | code_modifiers, false, input_inhibited); | 280 | code_modifiers, false, input_inhibited, device_identifier); |
272 | get_active_binding(&keyboard->state_keysyms_translated, | 281 | get_active_binding(&keyboard->state_keysyms_translated, |
273 | config->current_mode->keysym_bindings, &binding, | 282 | config->current_mode->keysym_bindings, &binding, |
274 | translated_modifiers, false, input_inhibited); | 283 | translated_modifiers, false, input_inhibited, |
284 | device_identifier); | ||
275 | get_active_binding(&keyboard->state_keysyms_raw, | 285 | get_active_binding(&keyboard->state_keysyms_raw, |
276 | config->current_mode->keysym_bindings, &binding, | 286 | config->current_mode->keysym_bindings, &binding, |
277 | raw_modifiers, false, input_inhibited); | 287 | raw_modifiers, false, input_inhibited, device_identifier); |
278 | 288 | ||
279 | if (binding) { | 289 | if (binding) { |
280 | seat_execute_command(seat, binding); | 290 | seat_execute_command(seat, binding); |
@@ -315,6 +325,8 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) { | |||
315 | } | 325 | } |
316 | 326 | ||
317 | transaction_commit_dirty(); | 327 | transaction_commit_dirty(); |
328 | |||
329 | free(device_identifier); | ||
318 | } | 330 | } |
319 | 331 | ||
320 | static int handle_keyboard_repeat(void *data) { | 332 | static int handle_keyboard_repeat(void *data) { |