aboutsummaryrefslogtreecommitdiff
path: root/tinywl
diff options
context:
space:
mode:
authorSimon Zeni <simon@bl4ckb0ne.ca>2022-03-07 11:01:49 -0500
committerKirill Primak <vyivel@eclair.cafe>2022-03-07 16:37:41 +0000
commit9d8dc026e50e9497b9268be40b5a7d2766cffe72 (patch)
treea9dc6d14f45dc9715dcbfbe2825fbd6d62d71abe /tinywl
parent10cbb9fbe141ee8f5c766783bde645ae19998d22 (diff)
tinywl: destroy keyboard on wlr_input_device event
Diffstat (limited to 'tinywl')
-rw-r--r--tinywl/tinywl.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/tinywl/tinywl.c b/tinywl/tinywl.c
index a4fcc262..2abcfb11 100644
--- a/tinywl/tinywl.c
+++ b/tinywl/tinywl.c
@@ -95,6 +95,7 @@ struct tinywl_keyboard {
struct wl_listener modifiers;
struct wl_listener key;
+ struct wl_listener destroy;
};
static void focus_view(struct tinywl_view *view, struct wlr_surface *surface) {
@@ -216,6 +217,20 @@ static void keyboard_handle_key(
}
}
+static void keyboard_handle_destroy(struct wl_listener *listener, void *data) {
+ /* This event is raised by the keyboard base wlr_input_device to signal
+ * the destruction of the wlr_keyboard. It will no longer receive events
+ * and should be destroyed.
+ */
+ struct tinywl_keyboard *keyboard =
+ wl_container_of(listener, keyboard, destroy);
+ wl_list_remove(&keyboard->modifiers.link);
+ wl_list_remove(&keyboard->key.link);
+ wl_list_remove(&keyboard->destroy.link);
+ wl_list_remove(&keyboard->link);
+ free(keyboard);
+}
+
static void server_new_keyboard(struct tinywl_server *server,
struct wlr_input_device *device) {
struct tinywl_keyboard *keyboard =
@@ -239,6 +254,8 @@ static void server_new_keyboard(struct tinywl_server *server,
wl_signal_add(&device->keyboard->events.modifiers, &keyboard->modifiers);
keyboard->key.notify = keyboard_handle_key;
wl_signal_add(&device->keyboard->events.key, &keyboard->key);
+ keyboard->destroy.notify = keyboard_handle_destroy;
+ wl_signal_add(&device->events.destroy, &keyboard->destroy);
wlr_seat_set_keyboard(server->seat, device);