~sircmpwn/wio

`Esc` stops current action / event v1 PROPOSED

Leon Plickat
Leon Plickat: 1
 `Esc` stops current action / event

 1 files changed, 20 insertions(+), 0 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/wio/patches/6188/mbox | git am -3
Learn more about email & git

[PATCH] `Esc` stops current action / event Export this patch

Leon Plickat
---
 input.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/input.c b/input.c
index ab26804..b4cee19 100644
--- a/input.c
+++ b/input.c
@@ -23,6 +23,7 @@ static void keyboard_handle_modifiers(
 		&keyboard->device->keyboard->modifiers);
 }
 
+static void view_end_interactive(struct wio_server *server);
 static void keyboard_handle_key(
 		struct wl_listener *listener, void *data) {
 	struct wio_keyboard *keyboard =
@@ -30,6 +31,25 @@ static void keyboard_handle_key(
 	struct wio_server *server = keyboard->server;
 	struct wlr_event_keyboard_key *event = data;
 	struct wlr_seat *seat = server->seat;
+	xkb_keycode_t keycode = event->keycode + 8;
+	const xkb_keysym_t *syms;
+	int nsyms = xkb_state_key_get_syms(
+		keyboard->device->keyboard->xkb_state,
+		keycode, &syms);
+
+	for (int i = 0; i < nsyms; i++) {
+		if (syms[i] == XKB_KEY_Escape) {
+			switch (server->input_state) {
+			case INPUT_STATE_NONE:
+			case INPUT_STATE_MENU:
+				break;
+			default:
+				view_end_interactive(server);
+				return;
+			}
+		}
+	}
+
 	wlr_seat_set_keyboard(seat, keyboard->device);
 	wlr_seat_keyboard_notify_key(seat, event->time_msec,
 		event->keycode, event->state);
-- 
2.22.0
View this thread in the archives