diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index ba3feb8d..44ce6028 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -155,7 +155,11 @@ static void keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard, static void keyboard_handle_modifiers(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group) { + struct wlr_input_device *dev = data; + assert(dev && dev->keyboard); + wlr_keyboard_update_modifiers(dev->keyboard, mods_depressed, mods_latched, + mods_locked, group); } static void keyboard_handle_repeat_info(void *data, struct wl_keyboard *wl_keyboard, diff --git a/include/rootston/config.h b/include/rootston/config.h index ef101f2d..ece11829 100644 --- a/include/rootston/config.h +++ b/include/rootston/config.h @@ -19,6 +19,7 @@ struct device_config { }; struct binding_config { + uint32_t modifiers; xkb_keysym_t *keysyms; size_t keysyms_len; char *command; diff --git a/include/wlr/interfaces/wlr_keyboard.h b/include/wlr/interfaces/wlr_keyboard.h index 78c1f753..9755267a 100644 --- a/include/wlr/interfaces/wlr_keyboard.h +++ b/include/wlr/interfaces/wlr_keyboard.h @@ -13,5 +13,8 @@ void wlr_keyboard_init(struct wlr_keyboard *keyboard, struct wlr_keyboard_impl * void wlr_keyboard_destroy(struct wlr_keyboard *keyboard); void wlr_keyboard_update_state(struct wlr_keyboard *keyboard, struct wlr_event_keyboard_key *event); +void wlr_keyboard_update_modifiers(struct wlr_keyboard *keyboard, + uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, + uint32_t group); #endif diff --git a/rootston/config.c b/rootston/config.c index a80a8304..3a21aff3 100644 --- a/rootston/config.c +++ b/rootston/config.c @@ -177,28 +177,49 @@ static int config_ini_handler(void *user, const char *section, const char *name, bc->command = strdup(value); - bc->keysyms_len = 1; + size_t keysyms_len = 1; char *symnames = strdup(name); for (char *c = symnames; *c != '\0'; c++) { if (*c == '+') { *c = '\0'; - bc->keysyms_len++; + keysyms_len++; } } - bc->keysyms = calloc(1, bc->keysyms_len * sizeof(xkb_keysym_t)); + // TODO: bc->keysyms is larger than needed + bc->keysyms = calloc(1, keysyms_len * sizeof(xkb_keysym_t)); char *symname = symnames; - for (size_t i = 0; i < bc->keysyms_len; i++) { - xkb_keysym_t sym = xkb_keysym_from_name(symname, - XKB_KEYSYM_NO_FLAGS); - if (sym == XKB_KEY_NoSymbol) { - wlr_log(L_ERROR, "got unknown key binding symbol: %s", symname); - wl_list_remove(&bc->link); - free(bc->keysyms); - free(bc); - break; + for (size_t i = 0; i < keysyms_len; i++) { + if (strcmp(symname, "Shift") == 0) { + bc->modifiers |= WLR_MODIFIER_SHIFT; + } else if (strcmp(symname, "Caps") == 0) { + bc->modifiers |= WLR_MODIFIER_CAPS; + } else if (strcmp(symname, "Ctrl") == 0) { + bc->modifiers |= WLR_MODIFIER_CTRL; + } else if (strcmp(symname, "Alt") == 0) { + bc->modifiers |= WLR_MODIFIER_ALT; + } else if (strcmp(symname, "Mod2") == 0) { + bc->modifiers |= WLR_MODIFIER_MOD2; + } else if (strcmp(symname, "Mod3") == 0) { + bc->modifiers |= WLR_MODIFIER_MOD3; + } else if (strcmp(symname, "Logo") == 0) { + bc->modifiers |= WLR_MODIFIER_LOGO; + } else if (strcmp(symname, "Mod5") == 0) { + bc->modifiers |= WLR_MODIFIER_MOD5; + } else { + xkb_keysym_t sym = xkb_keysym_from_name(symname, + XKB_KEYSYM_NO_FLAGS); + if (sym == XKB_KEY_NoSymbol) { + wlr_log(L_ERROR, "got unknown key binding symbol: %s", + symname); + wl_list_remove(&bc->link); + free(bc->keysyms); + free(bc); + break; + } + bc->keysyms[bc->keysyms_len] = sym; + bc->keysyms_len++; } - bc->keysyms[i] = sym; symname += strlen(symname) + 1; } @@ -249,6 +270,7 @@ struct roots_config *parse_args(int argc, char *argv[]) { struct binding_config *bc = calloc(1, sizeof(struct binding_config)); wl_list_insert(&config->bindings, &bc->link); bc->command = strdup("exit"); + bc->modifiers = WLR_MODIFIER_LOGO; bc->keysyms_len = 2; bc->keysyms = calloc(1, bc->keysyms_len * sizeof(xkb_keysym_t)); bc->keysyms[0] = XKB_KEY_Meta_L; diff --git a/rootston/keyboard.c b/rootston/keyboard.c index 5ac6e59b..6f6fa0e8 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -61,9 +61,14 @@ static void keyboard_keysym_press(struct roots_keyboard *keyboard, return; } + uint32_t modifiers = wlr_keyboard_get_modifiers(keyboard->device->keyboard); struct wl_list *bindings = &keyboard->input->server->config->bindings; struct binding_config *bc; wl_list_for_each(bc, bindings, link) { + if (modifiers ^ bc->modifiers) { + continue; + } + bool ok = true; for (size_t i = 0; i < bc->keysyms_len; i++) { ssize_t j = keyboard_pressed_keysym_index(keyboard, bc->keysyms[i]); diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index 4d7f215c..9c111af4 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -30,6 +30,15 @@ void wlr_keyboard_update_state(struct wlr_keyboard *keyboard, wl_signal_emit(&keyboard->events.key, event); } +void wlr_keyboard_update_modifiers(struct wlr_keyboard *keyboard, + uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, + uint32_t group) { + keyboard->modifiers.depressed = mods_depressed; + keyboard->modifiers.latched = mods_latched; + keyboard->modifiers.locked = mods_locked; + keyboard->modifiers.group = group; +} + void wlr_keyboard_init(struct wlr_keyboard *kb, struct wlr_keyboard_impl *impl) { kb->impl = impl;