mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-02 03:45:58 +01:00
Add modifiers support in wayland backend, parse modifiers in rootston config
This commit is contained in:
parent
3a8fdebaaa
commit
d3d9aca40c
6 changed files with 57 additions and 13 deletions
|
@ -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,
|
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 serial, uint32_t mods_depressed, uint32_t mods_latched,
|
||||||
uint32_t mods_locked, uint32_t group) {
|
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,
|
static void keyboard_handle_repeat_info(void *data, struct wl_keyboard *wl_keyboard,
|
||||||
|
|
|
@ -19,6 +19,7 @@ struct device_config {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct binding_config {
|
struct binding_config {
|
||||||
|
uint32_t modifiers;
|
||||||
xkb_keysym_t *keysyms;
|
xkb_keysym_t *keysyms;
|
||||||
size_t keysyms_len;
|
size_t keysyms_len;
|
||||||
char *command;
|
char *command;
|
||||||
|
|
|
@ -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_destroy(struct wlr_keyboard *keyboard);
|
||||||
void wlr_keyboard_update_state(struct wlr_keyboard *keyboard,
|
void wlr_keyboard_update_state(struct wlr_keyboard *keyboard,
|
||||||
struct wlr_event_keyboard_key *event);
|
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
|
#endif
|
||||||
|
|
|
@ -177,28 +177,49 @@ static int config_ini_handler(void *user, const char *section, const char *name,
|
||||||
|
|
||||||
bc->command = strdup(value);
|
bc->command = strdup(value);
|
||||||
|
|
||||||
bc->keysyms_len = 1;
|
size_t keysyms_len = 1;
|
||||||
char *symnames = strdup(name);
|
char *symnames = strdup(name);
|
||||||
for (char *c = symnames; *c != '\0'; c++) {
|
for (char *c = symnames; *c != '\0'; c++) {
|
||||||
if (*c == '+') {
|
if (*c == '+') {
|
||||||
*c = '\0';
|
*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;
|
char *symname = symnames;
|
||||||
for (size_t i = 0; i < bc->keysyms_len; i++) {
|
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_t sym = xkb_keysym_from_name(symname,
|
||||||
XKB_KEYSYM_NO_FLAGS);
|
XKB_KEYSYM_NO_FLAGS);
|
||||||
if (sym == XKB_KEY_NoSymbol) {
|
if (sym == XKB_KEY_NoSymbol) {
|
||||||
wlr_log(L_ERROR, "got unknown key binding symbol: %s", symname);
|
wlr_log(L_ERROR, "got unknown key binding symbol: %s",
|
||||||
|
symname);
|
||||||
wl_list_remove(&bc->link);
|
wl_list_remove(&bc->link);
|
||||||
free(bc->keysyms);
|
free(bc->keysyms);
|
||||||
free(bc);
|
free(bc);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
bc->keysyms[i] = sym;
|
bc->keysyms[bc->keysyms_len] = sym;
|
||||||
|
bc->keysyms_len++;
|
||||||
|
}
|
||||||
symname += strlen(symname) + 1;
|
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));
|
struct binding_config *bc = calloc(1, sizeof(struct binding_config));
|
||||||
wl_list_insert(&config->bindings, &bc->link);
|
wl_list_insert(&config->bindings, &bc->link);
|
||||||
bc->command = strdup("exit");
|
bc->command = strdup("exit");
|
||||||
|
bc->modifiers = WLR_MODIFIER_LOGO;
|
||||||
bc->keysyms_len = 2;
|
bc->keysyms_len = 2;
|
||||||
bc->keysyms = calloc(1, bc->keysyms_len * sizeof(xkb_keysym_t));
|
bc->keysyms = calloc(1, bc->keysyms_len * sizeof(xkb_keysym_t));
|
||||||
bc->keysyms[0] = XKB_KEY_Meta_L;
|
bc->keysyms[0] = XKB_KEY_Meta_L;
|
||||||
|
|
|
@ -61,9 +61,14 @@ static void keyboard_keysym_press(struct roots_keyboard *keyboard,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t modifiers = wlr_keyboard_get_modifiers(keyboard->device->keyboard);
|
||||||
struct wl_list *bindings = &keyboard->input->server->config->bindings;
|
struct wl_list *bindings = &keyboard->input->server->config->bindings;
|
||||||
struct binding_config *bc;
|
struct binding_config *bc;
|
||||||
wl_list_for_each(bc, bindings, link) {
|
wl_list_for_each(bc, bindings, link) {
|
||||||
|
if (modifiers ^ bc->modifiers) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
for (size_t i = 0; i < bc->keysyms_len; i++) {
|
for (size_t i = 0; i < bc->keysyms_len; i++) {
|
||||||
ssize_t j = keyboard_pressed_keysym_index(keyboard, bc->keysyms[i]);
|
ssize_t j = keyboard_pressed_keysym_index(keyboard, bc->keysyms[i]);
|
||||||
|
|
|
@ -30,6 +30,15 @@ void wlr_keyboard_update_state(struct wlr_keyboard *keyboard,
|
||||||
wl_signal_emit(&keyboard->events.key, event);
|
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,
|
void wlr_keyboard_init(struct wlr_keyboard *kb,
|
||||||
struct wlr_keyboard_impl *impl) {
|
struct wlr_keyboard_impl *impl) {
|
||||||
kb->impl = impl;
|
kb->impl = impl;
|
||||||
|
|
Loading…
Reference in a new issue