aboutsummaryrefslogtreecommitdiff
path: root/sway/input/input-manager.c
diff options
context:
space:
mode:
authorMichael Weiser <michael.weiser@gmx.de>2020-02-15 20:55:33 +0100
committerBrian Ashworth <bosrsf04@gmail.com>2020-03-11 23:51:37 -0400
commiteeac0aa170d4ee19111df072ea361b56c802cf34 (patch)
tree58327ead389b1c396117e55af9f766e8c38e0995 /sway/input/input-manager.c
parentef9c597fcb1b48482d2fd16f16316af286640616 (diff)
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)
}
}
+static void handle_keyboard_shortcuts_inhibitor_destroy(
+ struct wl_listener *listener, void *data) {
+ struct sway_keyboard_shortcuts_inhibitor *sway_inhibitor =
+ wl_container_of(listener, sway_inhibitor, destroy);
+
+ sway_log(SWAY_DEBUG, "Removing keyboard shortcuts inhibitor");
+
+ // sway_seat::keyboard_shortcuts_inhibitors
+ wl_list_remove(&sway_inhibitor->link);
+ wl_list_remove(&sway_inhibitor->destroy.link);
+ free(sway_inhibitor);
+}
+
+static void handle_keyboard_shortcuts_inhibit_new_inhibitor(
+ struct wl_listener *listener, void *data) {
+ struct sway_input_manager *input_manager =
+ wl_container_of(listener, input_manager,
+ keyboard_shortcuts_inhibit_new_inhibitor);
+ struct wlr_keyboard_shortcuts_inhibitor_v1 *inhibitor = data;
+
+ sway_log(SWAY_DEBUG, "Adding keyboard shortcuts inhibitor");
+
+ struct sway_keyboard_shortcuts_inhibitor *sway_inhibitor =
+ calloc(1, sizeof(struct sway_keyboard_shortcuts_inhibitor));
+ if (!sway_assert(sway_inhibitor, "could not allocate keyboard "
+ "shortcuts inhibitor")) {
+ return;
+ }
+ sway_inhibitor->inhibitor = inhibitor;
+
+ sway_inhibitor->destroy.notify = handle_keyboard_shortcuts_inhibitor_destroy;
+ wl_signal_add(&inhibitor->events.destroy, &sway_inhibitor->destroy);
+
+ // attach inhibitor to the seat it applies to
+ struct sway_seat *seat = inhibitor->seat->data;
+ wl_list_insert(&seat->keyboard_shortcuts_inhibitors, &sway_inhibitor->link);
+
+ wlr_keyboard_shortcuts_inhibitor_v1_activate(inhibitor);
+}
+
void handle_virtual_keyboard(struct wl_listener *listener, void *data) {
struct sway_input_manager *input_manager =
wl_container_of(listener, input_manager, virtual_keyboard_new);
@@ -397,6 +437,13 @@ struct sway_input_manager *input_manager_create(struct sway_server *server) {
wl_signal_add(&input->inhibit->events.deactivate,
&input->inhibit_deactivate);
+ input->keyboard_shortcuts_inhibit =
+ wlr_keyboard_shortcuts_inhibit_v1_create(server->wl_display);
+ input->keyboard_shortcuts_inhibit_new_inhibitor.notify =
+ handle_keyboard_shortcuts_inhibit_new_inhibitor;
+ wl_signal_add(&input->keyboard_shortcuts_inhibit->events.new_inhibitor,
+ &input->keyboard_shortcuts_inhibit_new_inhibitor);
+
return input;
}