diff options
Diffstat (limited to 'rootston')
-rw-r--r-- | rootston/desktop.c | 10 | ||||
-rw-r--r-- | rootston/keyboard.c | 73 |
2 files changed, 72 insertions, 11 deletions
diff --git a/rootston/desktop.c b/rootston/desktop.c index e752e639..c5242599 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -128,6 +128,16 @@ void view_setup(struct roots_view *view) { void view_teardown(struct roots_view *view) { // TODO replace me with a signal + /* + struct wlr_list *views = view->desktop->views; + if (views->length < 2 || views->items[views->length-1] != view) { + return; + } + + struct roots_view *prev_view = views->items[views->length-2]; + struct roots_input *input = prev_view->desktop->server->input; + set_view_focus(input, prev_view->desktop, prev_view); + */ } struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly, diff --git a/rootston/keyboard.c b/rootston/keyboard.c index a770f00f..9692ea7d 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -123,17 +123,58 @@ static void keyboard_keysym_release(struct roots_keyboard *keyboard, keyboard->pressed_keysyms[i] = XKB_KEY_NoSymbol; } } - -void roots_keyboard_handle_key(struct roots_keyboard *keyboard, - struct wlr_event_keyboard_key *event) { - uint32_t keycode = event->keycode + 8; +/* + * Process keypresses from the keyboard as xkb sees them. + * + * This uses the xkb keysyms translation based on pressed modifiers and clears + * the consumed modifiers from the list of modifiers passed to keybind + * detection. + * + * (On US layout) this will trigger: [Alt]+[at] + */ +static bool keyboard_keysyms_xkb(struct roots_keyboard *keyboard, + uint32_t keycode, enum wlr_key_state state) { + uint32_t modifiers = wlr_keyboard_get_modifiers(keyboard->device->keyboard); const xkb_keysym_t *syms; int syms_len = xkb_state_key_get_syms(keyboard->device->keyboard->xkb_state, keycode, &syms); + uint32_t consumed = xkb_state_key_get_consumed_mods2( + keyboard->device->keyboard->xkb_state, keycode, XKB_CONSUMED_MODE_XKB); + + modifiers = modifiers & ~consumed; bool handled = false; for (int i = 0; i < syms_len; i++) { - if (event->state == WLR_KEY_PRESSED) { + if (state) { + bool keysym_handled = + keyboard_keysym_press(keyboard, syms[i]); + handled = handled || keysym_handled; + } else { // WLR_KEY_RELEASED + keyboard_keysym_release(keyboard, syms[i]); + } + } + + return handled; +} +/* + * Process keypresses from the keyboard as if modifiers didn't change keysyms. + * + * This avoids the xkb keysym translation based on modifiers considered pressed + * in the state and uses the list of modifiers saved on the rootston side. + * + * This will trigger the keybind: [Alt]+[Shift]+2 + */ +static bool keyboard_keysyms_simple(struct roots_keyboard *keyboard, + uint32_t keycode, enum wlr_key_state state) { + const xkb_keysym_t *syms; + xkb_layout_index_t layout_index = xkb_state_key_get_layout( + keyboard->device->keyboard->xkb_state, keycode); + int syms_len = xkb_keymap_key_get_syms_by_level( + keyboard->device->keyboard->keymap, keycode, layout_index, 0, &syms); + + bool handled = false; + for (int i = 0; i < syms_len; i++) { + if (state) { bool keysym_handled = keyboard_keysym_press(keyboard, syms[i]); handled = handled || keysym_handled; } else { // WLR_KEY_RELEASED @@ -141,6 +182,21 @@ void roots_keyboard_handle_key(struct roots_keyboard *keyboard, } } + return handled; +} + +void roots_keyboard_handle_key(struct roots_keyboard *keyboard, + struct wlr_event_keyboard_key *event) { + uint32_t keycode = event->keycode + 8; + + bool handled = keyboard_keysyms_xkb(keyboard, keycode, event->state); + + if (!handled) { + bool key_handled = keyboard_keysyms_simple(keyboard, keycode, + event->state); + handled = handled || key_handled; + } + if (!handled) { wlr_seat_set_keyboard(keyboard->seat->seat, keyboard->device); wlr_seat_keyboard_notify_key(keyboard->seat->seat, event->time_msec, @@ -151,13 +207,8 @@ void roots_keyboard_handle_key(struct roots_keyboard *keyboard, void roots_keyboard_handle_modifiers(struct roots_keyboard *r_keyboard, struct wlr_event_keyboard_modifiers *event) { struct wlr_seat *seat = r_keyboard->seat->seat; - struct wlr_keyboard *keyboard = r_keyboard->device->keyboard; wlr_seat_set_keyboard(seat, r_keyboard->device); - wlr_seat_keyboard_notify_modifiers(seat, - keyboard->modifiers.depressed, - keyboard->modifiers.latched, - keyboard->modifiers.locked, - keyboard->modifiers.group); + wlr_seat_keyboard_notify_modifiers(seat); } static void keyboard_config_merge(struct keyboard_config *config, |