diff options
-rw-r--r-- | include/client/registry.h | 2 | ||||
-rw-r--r-- | swaylock/main.c | 6 | ||||
-rw-r--r-- | 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 { | |||
51 | uint32_t last_code; | 51 | uint32_t last_code; |
52 | uint32_t modifiers; | 52 | uint32_t modifiers; |
53 | 53 | ||
54 | void (*notify)(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t code); | 54 | void (*notify)(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t code, uint32_t codepoint); |
55 | }; | 55 | }; |
56 | 56 | ||
57 | struct registry { | 57 | 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) { | |||
29 | exit(EXIT_FAILURE); | 29 | exit(EXIT_FAILURE); |
30 | } | 30 | } |
31 | 31 | ||
32 | void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t code, uint32_t codepoint) { | ||
33 | sway_log(L_INFO, "notified of key %c", (char)codepoint); | ||
34 | } | ||
35 | |||
32 | int main(int argc, char **argv) { | 36 | int main(int argc, char **argv) { |
33 | init_log(L_INFO); | 37 | init_log(L_INFO); |
34 | surfaces = create_list(); | 38 | surfaces = create_list(); |
@@ -49,6 +53,8 @@ int main(int argc, char **argv) { | |||
49 | list_add(surfaces, window); | 53 | list_add(surfaces, window); |
50 | } | 54 | } |
51 | 55 | ||
56 | registry->input->notify = notify_key; | ||
57 | |||
52 | GError *err = NULL; | 58 | GError *err = NULL; |
53 | GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(argv[1], &err); // TODO: Parse i3lock arguments | 59 | GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(argv[1], &err); // TODO: Parse i3lock arguments |
54 | if (!pixbuf) { | 60 | 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, | |||
133 | xkb_keysym_t sym = xkb_state_key_get_one_sym(registry->input->xkb.state, key + 8); | 133 | xkb_keysym_t sym = xkb_state_key_get_one_sym(registry->input->xkb.state, key + 8); |
134 | registry->input->sym = (state == WL_KEYBOARD_KEY_STATE_PRESSED ? sym : XKB_KEY_NoSymbol); | 134 | registry->input->sym = (state == WL_KEYBOARD_KEY_STATE_PRESSED ? sym : XKB_KEY_NoSymbol); |
135 | registry->input->code = (state == WL_KEYBOARD_KEY_STATE_PRESSED ? key + 8 : 0); | 135 | registry->input->code = (state == WL_KEYBOARD_KEY_STATE_PRESSED ? key + 8 : 0); |
136 | uint32_t codepoint = xkb_state_key_get_utf32(registry->input->xkb.state, registry->input->code); | ||
136 | if (registry->input->notify) { | 137 | if (registry->input->notify) { |
137 | registry->input->notify(state, sym, key); | 138 | registry->input->notify(state, sym, key, codepoint); |
138 | } | 139 | } |
139 | } | 140 | } |
140 | 141 | ||
141 | static void keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard, | 142 | static void keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard, |
142 | uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, | 143 | uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, |
143 | uint32_t mods_locked, uint32_t group) { | 144 | uint32_t mods_locked, uint32_t group) { |
145 | struct registry *registry = data; | ||
146 | |||
147 | if (!registry->input->xkb.keymap) { | ||
148 | return; | ||
149 | } | ||
150 | |||
151 | xkb_state_update_mask(registry->input->xkb.state, mods_depressed, mods_latched, mods_locked, 0, 0, group); | ||
152 | xkb_mod_mask_t mask = xkb_state_serialize_mods(registry->input->xkb.state, | ||
153 | XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED); | ||
154 | |||
155 | registry->input->modifiers = 0; | ||
156 | for (uint32_t i = 0; i < MASK_LAST; ++i) { | ||
157 | if (mask & registry->input->xkb.masks[i]) { | ||
158 | registry->input->modifiers |= XKB_MODS[i]; | ||
159 | } | ||
160 | } | ||
144 | } | 161 | } |
145 | 162 | ||
146 | static void keyboard_handle_repeat_info(void *data, struct wl_keyboard *keyboard, | 163 | static void keyboard_handle_repeat_info(void *data, struct wl_keyboard *keyboard, |
147 | int32_t rate, int32_t delay) { | 164 | int32_t rate, int32_t delay) { |
165 | // this space intentionally left blank | ||
148 | } | 166 | } |
149 | 167 | ||
150 | static const struct wl_keyboard_listener keyboard_listener = { | 168 | static const struct wl_keyboard_listener keyboard_listener = { |