From 8271cca44fe785e54fa6db9a7f4c29942d143fa3 Mon Sep 17 00:00:00 2001 From: Yorick van Pelt Date: Tue, 12 Feb 2019 21:38:28 +0100 Subject: [PATCH] Abort on escape (closes #17) --- main.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/main.c b/main.c index 2c8ccc1..704fa03 100644 --- a/main.c +++ b/main.c @@ -131,6 +131,24 @@ void pointer_get_box(struct slurp_pointer *pointer, int *x, int *y, *height = abs(pointer->y - pointer->pressed_y); } +static void keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard, + uint32_t serial, uint32_t time, uint32_t key, uint32_t key_state) { + struct slurp_state *state = data; + if (key_state == WL_KEYBOARD_KEY_STATE_PRESSED) { + if (key == KEY_ESC) { + state->running = false; + } + } +} + +static const struct wl_keyboard_listener keyboard_listener = { + .keymap = noop, + .enter = noop, + .leave = noop, + .key = keyboard_handle_key, + .modifiers = noop, +}; + static void seat_handle_capabilities(void *data, struct wl_seat *seat, uint32_t capabilities) { @@ -140,6 +158,10 @@ static void seat_handle_capabilities(void *data, struct wl_seat *seat, struct wl_pointer *wl_pointer = wl_seat_get_pointer(seat); create_pointer(state, wl_pointer); } + if (capabilities & WL_SEAT_CAPABILITY_KEYBOARD) { + struct wl_keyboard *wl_keyboard = wl_seat_get_keyboard(seat); + wl_keyboard_add_listener(wl_keyboard, &keyboard_listener, state); + } } static const struct wl_seat_listener seat_listener = { @@ -463,6 +485,7 @@ int main(int argc, char *argv[]) { ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM); + zwlr_layer_surface_v1_set_keyboard_interactivity(output->layer_surface, true); zwlr_layer_surface_v1_set_exclusive_zone(output->layer_surface, -1); wl_surface_commit(output->surface);