diff options
author | marius vlad <marius.vlad@collabora.com> | 2023-04-03 17:34:27 +0300 |
---|---|---|
committer | Marius Vlad <marius.vlad@collabora.com> | 2023-04-12 14:40:38 +0300 |
commit | 1446d9cb3c21bbc1731fbf9e0fa270f2e986b8e1 (patch) | |
tree | ffb8872f36abdd26e7901c73e04e3fa9da6dcbe6 /clients | |
parent | 2e0b67e5be9b34282a94dc74ef4051c781ea83f4 (diff) | |
download | weston-1446d9cb3c21bbc1731fbf9e0fa270f2e986b8e1.tar.gz |
client-shm: Add basic keyboard support
And use it to exit with using the KEY_ESC, similar to simple-egl.
This was ripped from simple-egl ad litteram.
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Diffstat (limited to 'clients')
-rw-r--r-- | clients/simple-shm.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/clients/simple-shm.c b/clients/simple-shm.c index 8df96f62..6bcb45ad 100644 --- a/clients/simple-shm.c +++ b/clients/simple-shm.c @@ -35,6 +35,8 @@ #include <signal.h> #include <errno.h> +#include <linux/input.h> + #include <wayland-client.h> #include "shared/os-compatibility.h" #include <libweston/zalloc.h> @@ -49,6 +51,8 @@ struct display { struct wl_compositor *compositor; struct xdg_wm_base *wm_base; struct zwp_fullscreen_shell_v1 *fshell; + struct wl_seat *seat; + struct wl_keyboard *keyboard; struct wl_shm *shm; bool has_xrgb; }; @@ -192,6 +196,71 @@ create_shm_buffer(struct window *window, struct buffer *buffer, uint32_t format) } static void +keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard, + uint32_t format, int fd, uint32_t size) +{ + /* Just so we don’t leak the keymap fd */ + close(fd); +} + +static void +keyboard_handle_enter(void *data, struct wl_keyboard *keyboard, + uint32_t serial, struct wl_surface *surface, + struct wl_array *keys) +{ +} + +static void +keyboard_handle_leave(void *data, struct wl_keyboard *keyboard, + uint32_t serial, struct wl_surface *surface) +{ +} + +static void +keyboard_handle_key(void *data, struct wl_keyboard *keyboard, + uint32_t serial, uint32_t time, uint32_t key, + uint32_t state) +{ + if (key == KEY_ESC && state) + running = 0; +} + +static void +keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard, + uint32_t serial, uint32_t mods_depressed, + uint32_t mods_latched, uint32_t mods_locked, + uint32_t group) +{ +} + +static const struct wl_keyboard_listener keyboard_listener = { + keyboard_handle_keymap, + keyboard_handle_enter, + keyboard_handle_leave, + keyboard_handle_key, + keyboard_handle_modifiers, +}; + +static void +seat_handle_capabilities(void *data, struct wl_seat *seat, + enum wl_seat_capability caps) +{ + struct display *d = data; + + if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !d->keyboard) { + d->keyboard = wl_seat_get_keyboard(seat); + wl_keyboard_add_listener(d->keyboard, &keyboard_listener, d); + } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && d->keyboard) { + wl_keyboard_destroy(d->keyboard); + d->keyboard = NULL; + } +} + +static const struct wl_seat_listener seat_listener = { + seat_handle_capabilities, +}; + +static void handle_xdg_surface_configure(void *data, struct xdg_surface *surface, uint32_t serial) { @@ -487,6 +556,10 @@ registry_handle_global(void *data, struct wl_registry *registry, d->wm_base = wl_registry_bind(registry, id, &xdg_wm_base_interface, 1); xdg_wm_base_add_listener(d->wm_base, &xdg_wm_base_listener, d); + } else if (strcmp(interface, "wl_seat") == 0) { + d->seat = wl_registry_bind(registry, id, + &wl_seat_interface, 1); + wl_seat_add_listener(d->seat, &seat_listener, d); } else if (strcmp(interface, "zwp_fullscreen_shell_v1") == 0) { d->fshell = wl_registry_bind(registry, id, &zwp_fullscreen_shell_v1_interface, 1); |