diff options
author | frsfnrrg <frsfnrrg@users.noreply.github.com> | 2018-07-23 21:38:29 -0400 |
---|---|---|
committer | frsfnrrg <frsfnrrg@users.noreply.github.com> | 2018-07-23 21:38:29 -0400 |
commit | 94dd8823a0081f7983dce368d5d093d1d3eeaefe (patch) | |
tree | f2147f1ef4871edb4d989d26cd9b1104797d27bc /sway/input/keyboard.c | |
parent | Parse mouse binding options (diff) | |
download | sway-94dd8823a0081f7983dce368d5d093d1d3eeaefe.tar.gz sway-94dd8823a0081f7983dce368d5d093d1d3eeaefe.tar.zst sway-94dd8823a0081f7983dce368d5d093d1d3eeaefe.zip |
Invoke mouse bindings
The mouse binding logic is inspired/copied from the
keyboard binding logic; we store a sorted list of the
currently pressed buttons, and trigger a binding when
the currently pressed (or just recently pressed, in
the case of a release binding) buttons, as well as
modifiers/container region, match those of a given
binding.
As the code to execute a binding is not very keyboard
specific, keyboard_execute_command is renamed to
seat_execute_command and moved to where the other
binding handling functions are. The call to
transaction_commit_dirty has been lifted out.
Diffstat (limited to 'sway/input/keyboard.c')
-rw-r--r-- | sway/input/keyboard.c | 40 |
1 files changed, 13 insertions, 27 deletions
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index e6c5c335..49241db8 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c | |||
@@ -3,11 +3,11 @@ | |||
3 | #include <wlr/backend/multi.h> | 3 | #include <wlr/backend/multi.h> |
4 | #include <wlr/backend/session.h> | 4 | #include <wlr/backend/session.h> |
5 | #include <wlr/types/wlr_idle.h> | 5 | #include <wlr/types/wlr_idle.h> |
6 | #include "sway/commands.h" | ||
6 | #include "sway/desktop/transaction.h" | 7 | #include "sway/desktop/transaction.h" |
7 | #include "sway/input/seat.h" | ||
8 | #include "sway/input/keyboard.h" | ||
9 | #include "sway/input/input-manager.h" | 8 | #include "sway/input/input-manager.h" |
10 | #include "sway/commands.h" | 9 | #include "sway/input/keyboard.h" |
10 | #include "sway/input/seat.h" | ||
11 | #include "log.h" | 11 | #include "log.h" |
12 | 12 | ||
13 | /** | 13 | /** |
@@ -88,8 +88,8 @@ static void get_active_binding(const struct sway_shortcut_state *state, | |||
88 | uint32_t modifiers, bool release, bool locked) { | 88 | uint32_t modifiers, bool release, bool locked) { |
89 | for (int i = 0; i < bindings->length; ++i) { | 89 | for (int i = 0; i < bindings->length; ++i) { |
90 | struct sway_binding *binding = bindings->items[i]; | 90 | struct sway_binding *binding = bindings->items[i]; |
91 | bool binding_locked = binding->flags | BINDING_LOCKED; | 91 | bool binding_locked = binding->flags & BINDING_LOCKED; |
92 | bool binding_release = binding->flags | BINDING_RELEASE; | 92 | bool binding_release = binding->flags & BINDING_RELEASE; |
93 | 93 | ||
94 | if (modifiers ^ binding->modifiers || | 94 | if (modifiers ^ binding->modifiers || |
95 | state->npressed != (size_t)binding->keys->length || | 95 | state->npressed != (size_t)binding->keys->length || |
@@ -121,23 +121,6 @@ static void get_active_binding(const struct sway_shortcut_state *state, | |||
121 | } | 121 | } |
122 | 122 | ||
123 | /** | 123 | /** |
124 | * Execute the command associated to a binding | ||
125 | */ | ||
126 | static void keyboard_execute_command(struct sway_keyboard *keyboard, | ||
127 | struct sway_binding *binding) { | ||
128 | wlr_log(WLR_DEBUG, "running command for binding: %s", | ||
129 | binding->command); | ||
130 | config->handler_context.seat = keyboard->seat_device->sway_seat; | ||
131 | struct cmd_results *results = execute_command(binding->command, NULL); | ||
132 | transaction_commit_dirty(); | ||
133 | if (results->status != CMD_SUCCESS) { | ||
134 | wlr_log(WLR_DEBUG, "could not run command for binding: %s (%s)", | ||
135 | binding->command, results->error); | ||
136 | } | ||
137 | free_cmd_results(results); | ||
138 | } | ||
139 | |||
140 | /** | ||
141 | * Execute a built-in, hardcoded compositor binding. These are triggered from a | 124 | * Execute a built-in, hardcoded compositor binding. These are triggered from a |
142 | * single keysym. | 125 | * single keysym. |
143 | * | 126 | * |
@@ -213,12 +196,13 @@ static size_t keyboard_keysyms_raw(struct sway_keyboard *keyboard, | |||
213 | static void handle_keyboard_key(struct wl_listener *listener, void *data) { | 196 | static void handle_keyboard_key(struct wl_listener *listener, void *data) { |
214 | struct sway_keyboard *keyboard = | 197 | struct sway_keyboard *keyboard = |
215 | wl_container_of(listener, keyboard, keyboard_key); | 198 | wl_container_of(listener, keyboard, keyboard_key); |
216 | struct wlr_seat *wlr_seat = keyboard->seat_device->sway_seat->wlr_seat; | 199 | struct sway_seat* seat = keyboard->seat_device->sway_seat; |
200 | struct wlr_seat *wlr_seat = seat->wlr_seat; | ||
217 | struct wlr_input_device *wlr_device = | 201 | struct wlr_input_device *wlr_device = |
218 | keyboard->seat_device->input_device->wlr_device; | 202 | keyboard->seat_device->input_device->wlr_device; |
219 | wlr_idle_notify_activity(keyboard->seat_device->sway_seat->input->server->idle, wlr_seat); | 203 | wlr_idle_notify_activity(seat->input->server->idle, wlr_seat); |
220 | struct wlr_event_keyboard_key *event = data; | 204 | struct wlr_event_keyboard_key *event = data; |
221 | bool input_inhibited = keyboard->seat_device->sway_seat->exclusive_client != NULL; | 205 | bool input_inhibited = seat->exclusive_client != NULL; |
222 | 206 | ||
223 | // Identify new keycode, raw keysym(s), and translated keysym(s) | 207 | // Identify new keycode, raw keysym(s), and translated keysym(s) |
224 | xkb_keycode_t keycode = event->keycode + 8; | 208 | xkb_keycode_t keycode = event->keycode + 8; |
@@ -268,7 +252,7 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) { | |||
268 | // Execute stored release binding once no longer active | 252 | // Execute stored release binding once no longer active |
269 | if (keyboard->held_binding && binding_released != keyboard->held_binding && | 253 | if (keyboard->held_binding && binding_released != keyboard->held_binding && |
270 | event->state == WLR_KEY_RELEASED) { | 254 | event->state == WLR_KEY_RELEASED) { |
271 | keyboard_execute_command(keyboard, keyboard->held_binding); | 255 | seat_execute_command(seat, keyboard->held_binding); |
272 | handled = true; | 256 | handled = true; |
273 | } | 257 | } |
274 | if (binding_released != keyboard->held_binding) { | 258 | if (binding_released != keyboard->held_binding) { |
@@ -292,7 +276,7 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) { | |||
292 | raw_modifiers, false, input_inhibited); | 276 | raw_modifiers, false, input_inhibited); |
293 | 277 | ||
294 | if (binding_pressed) { | 278 | if (binding_pressed) { |
295 | keyboard_execute_command(keyboard, binding_pressed); | 279 | seat_execute_command(seat, binding_pressed); |
296 | handled = true; | 280 | handled = true; |
297 | } | 281 | } |
298 | } | 282 | } |
@@ -314,6 +298,8 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) { | |||
314 | wlr_seat_keyboard_notify_key(wlr_seat, event->time_msec, | 298 | wlr_seat_keyboard_notify_key(wlr_seat, event->time_msec, |
315 | event->keycode, event->state); | 299 | event->keycode, event->state); |
316 | } | 300 | } |
301 | |||
302 | transaction_commit_dirty(); | ||
317 | } | 303 | } |
318 | 304 | ||
319 | static void handle_keyboard_modifiers(struct wl_listener *listener, | 305 | static void handle_keyboard_modifiers(struct wl_listener *listener, |