mirror of
https://github.com/swaywm/sway.git
synced 2024-11-29 03:11:27 +00:00
Pass keys along from wayland backend to clients
This commit is contained in:
parent
af80b12add
commit
34277207fd
|
@ -51,7 +51,7 @@ struct input {
|
||||||
uint32_t last_code;
|
uint32_t last_code;
|
||||||
uint32_t modifiers;
|
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 {
|
struct registry {
|
||||||
|
|
|
@ -29,6 +29,10 @@ void sway_terminate(void) {
|
||||||
exit(EXIT_FAILURE);
|
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) {
|
int main(int argc, char **argv) {
|
||||||
init_log(L_INFO);
|
init_log(L_INFO);
|
||||||
surfaces = create_list();
|
surfaces = create_list();
|
||||||
|
@ -49,6 +53,8 @@ int main(int argc, char **argv) {
|
||||||
list_add(surfaces, window);
|
list_add(surfaces, window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registry->input->notify = notify_key;
|
||||||
|
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(argv[1], &err); // TODO: Parse i3lock arguments
|
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(argv[1], &err); // TODO: Parse i3lock arguments
|
||||||
if (!pixbuf) {
|
if (!pixbuf) {
|
||||||
|
|
|
@ -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);
|
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->sym = (state == WL_KEYBOARD_KEY_STATE_PRESSED ? sym : XKB_KEY_NoSymbol);
|
||||||
registry->input->code = (state == WL_KEYBOARD_KEY_STATE_PRESSED ? key + 8 : 0);
|
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) {
|
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,
|
static void keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,
|
||||||
uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched,
|
uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched,
|
||||||
uint32_t mods_locked, uint32_t group) {
|
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,
|
static void keyboard_handle_repeat_info(void *data, struct wl_keyboard *keyboard,
|
||||||
int32_t rate, int32_t delay) {
|
int32_t rate, int32_t delay) {
|
||||||
|
// this space intentionally left blank
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct wl_keyboard_listener keyboard_listener = {
|
static const struct wl_keyboard_listener keyboard_listener = {
|
||||||
|
|
Loading…
Reference in a new issue