aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/input-manager.c
diff options
context:
space:
mode:
authorLibravatar Michael Weiser <michael.weiser@gmx.de>2020-02-15 20:55:33 +0100
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2020-03-11 23:51:37 -0400
commiteeac0aa170d4ee19111df072ea361b56c802cf34 (patch)
tree58327ead389b1c396117e55af9f766e8c38e0995 /sway/input/input-manager.c
parentconfig: Fix typo in reload bindsym flag bitmask (diff)
downloadsway-eeac0aa170d4ee19111df072ea361b56c802cf34.tar.gz
sway-eeac0aa170d4ee19111df072ea361b56c802cf34.tar.zst
sway-eeac0aa170d4ee19111df072ea361b56c802cf34.zip
input: Add support for keyboard shortcuts inhibit
Adding support for the keyboard shortcuts inhibit protocol allows remote desktop and virtualisation software to receive all keyboard input in order to pass it through to their clients so users can fully interact the their remote/virtual session. The software usually provides its own key combination to release its "grab" to all keyboard input. The inhibitor can be deactivated by the user by removing focus from the surface using another input device such as the pointer. Use support for the procotol in wlroots to add support to sway. Extend the input manager with handlers for inhibitor creation and destruction and appropriate bookkeeping. Attach the inhibitors to the seats they apply to to avoid having to search the list of all currently existing inhibitors on every keystroke and passing the inhibitor manager around. Add a helper function to retrieve the inhibitor applying to the currently focused surface of a seat, if one exists. Extend bindsym with a flag for bindings that should be processed even if an inhibitor is active. Conversely this disables all normal shortcuts if an inhibitor is found for the currently focused surface in keyboard::handle_key_event() since they don't have that flag set. Use above helper function to determine if an inhibitor exists for the surface that would eventually receive input. Signed-off-by: Michael Weiser <michael.weiser@gmx.de>
Diffstat (limited to 'sway/input/input-manager.c')
-rw-r--r--sway/input/input-manager.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c
index 4cc07fe6..af0f5afa 100644
--- a/sway/input/input-manager.c
+++ b/sway/input/input-manager.c
@@ -296,6 +296,46 @@ static void handle_inhibit_deactivate(struct wl_listener *listener, void *data)
296 } 296 }
297} 297}
298 298
299static void handle_keyboard_shortcuts_inhibitor_destroy(
300 struct wl_listener *listener, void *data) {
301 struct sway_keyboard_shortcuts_inhibitor *sway_inhibitor =
302 wl_container_of(listener, sway_inhibitor, destroy);
303
304 sway_log(SWAY_DEBUG, "Removing keyboard shortcuts inhibitor");
305
306 // sway_seat::keyboard_shortcuts_inhibitors
307 wl_list_remove(&sway_inhibitor->link);
308 wl_list_remove(&sway_inhibitor->destroy.link);
309 free(sway_inhibitor);
310}
311
312static void handle_keyboard_shortcuts_inhibit_new_inhibitor(
313 struct wl_listener *listener, void *data) {
314 struct sway_input_manager *input_manager =
315 wl_container_of(listener, input_manager,
316 keyboard_shortcuts_inhibit_new_inhibitor);
317 struct wlr_keyboard_shortcuts_inhibitor_v1 *inhibitor = data;
318
319 sway_log(SWAY_DEBUG, "Adding keyboard shortcuts inhibitor");
320
321 struct sway_keyboard_shortcuts_inhibitor *sway_inhibitor =
322 calloc(1, sizeof(struct sway_keyboard_shortcuts_inhibitor));
323 if (!sway_assert(sway_inhibitor, "could not allocate keyboard "
324 "shortcuts inhibitor")) {
325 return;
326 }
327 sway_inhibitor->inhibitor = inhibitor;
328
329 sway_inhibitor->destroy.notify = handle_keyboard_shortcuts_inhibitor_destroy;
330 wl_signal_add(&inhibitor->events.destroy, &sway_inhibitor->destroy);
331
332 // attach inhibitor to the seat it applies to
333 struct sway_seat *seat = inhibitor->seat->data;
334 wl_list_insert(&seat->keyboard_shortcuts_inhibitors, &sway_inhibitor->link);
335
336 wlr_keyboard_shortcuts_inhibitor_v1_activate(inhibitor);
337}
338
299void handle_virtual_keyboard(struct wl_listener *listener, void *data) { 339void handle_virtual_keyboard(struct wl_listener *listener, void *data) {
300 struct sway_input_manager *input_manager = 340 struct sway_input_manager *input_manager =
301 wl_container_of(listener, input_manager, virtual_keyboard_new); 341 wl_container_of(listener, input_manager, virtual_keyboard_new);
@@ -397,6 +437,13 @@ struct sway_input_manager *input_manager_create(struct sway_server *server) {
397 wl_signal_add(&input->inhibit->events.deactivate, 437 wl_signal_add(&input->inhibit->events.deactivate,
398 &input->inhibit_deactivate); 438 &input->inhibit_deactivate);
399 439
440 input->keyboard_shortcuts_inhibit =
441 wlr_keyboard_shortcuts_inhibit_v1_create(server->wl_display);
442 input->keyboard_shortcuts_inhibit_new_inhibitor.notify =
443 handle_keyboard_shortcuts_inhibit_new_inhibitor;
444 wl_signal_add(&input->keyboard_shortcuts_inhibit->events.new_inhibitor,
445 &input->keyboard_shortcuts_inhibit_new_inhibitor);
446
400 return input; 447 return input;
401} 448}
402 449