From 34277207fd63b57ec8170f011a4115ef11c8ab0d Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 12 Dec 2015 15:19:23 -0500 Subject: [PATCH] Pass keys along from wayland backend to clients --- include/client/registry.h | 2 +- swaylock/main.c | 6 ++++++ wayland/registry.c | 20 +++++++++++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/include/client/registry.h b/include/client/registry.h index 253fcab8..9ac10c27 100644 --- a/include/client/registry.h +++ b/include/client/registry.h @@ -51,7 +51,7 @@ struct input { uint32_t last_code; uint32_t modifiers; - void (*notify)(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t code); + void (*notify)(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t code, uint32_t codepoint); }; struct registry { diff --git a/swaylock/main.c b/swaylock/main.c index c3743965..95921d53 100644 --- a/swaylock/main.c +++ b/swaylock/main.c @@ -29,6 +29,10 @@ void sway_terminate(void) { exit(EXIT_FAILURE); } +void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t code, uint32_t codepoint) { + sway_log(L_INFO, "notified of key %c", (char)codepoint); +} + int main(int argc, char **argv) { init_log(L_INFO); surfaces = create_list(); @@ -49,6 +53,8 @@ int main(int argc, char **argv) { list_add(surfaces, window); } + registry->input->notify = notify_key; + GError *err = NULL; GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(argv[1], &err); // TODO: Parse i3lock arguments if (!pixbuf) { diff --git a/wayland/registry.c b/wayland/registry.c index 6c290185..89756292 100644 --- a/wayland/registry.c +++ b/wayland/registry.c @@ -133,18 +133,36 @@ static void keyboard_handle_key(void *data, struct wl_keyboard *keyboard, xkb_keysym_t sym = xkb_state_key_get_one_sym(registry->input->xkb.state, key + 8); registry->input->sym = (state == WL_KEYBOARD_KEY_STATE_PRESSED ? sym : XKB_KEY_NoSymbol); registry->input->code = (state == WL_KEYBOARD_KEY_STATE_PRESSED ? key + 8 : 0); + uint32_t codepoint = xkb_state_key_get_utf32(registry->input->xkb.state, registry->input->code); if (registry->input->notify) { - registry->input->notify(state, sym, key); + registry->input->notify(state, sym, key, codepoint); } } 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) { + struct registry *registry = data; + + if (!registry->input->xkb.keymap) { + return; + } + + xkb_state_update_mask(registry->input->xkb.state, mods_depressed, mods_latched, mods_locked, 0, 0, group); + xkb_mod_mask_t mask = xkb_state_serialize_mods(registry->input->xkb.state, + XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED); + + registry->input->modifiers = 0; + for (uint32_t i = 0; i < MASK_LAST; ++i) { + if (mask & registry->input->xkb.masks[i]) { + registry->input->modifiers |= XKB_MODS[i]; + } + } } static void keyboard_handle_repeat_info(void *data, struct wl_keyboard *keyboard, int32_t rate, int32_t delay) { + // this space intentionally left blank } static const struct wl_keyboard_listener keyboard_listener = {