2021-09-24 21:45:48 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2022-11-02 16:37:24 -04:00
|
|
|
#include <assert.h>
|
2021-07-01 17:53:47 +01:00
|
|
|
#include <wlr/backend/multi.h>
|
|
|
|
|
#include <wlr/backend/session.h>
|
2022-01-05 21:27:47 +00:00
|
|
|
#include "action.h"
|
2023-07-08 18:27:40 +02:00
|
|
|
#include "idle.h"
|
2021-12-21 22:25:59 +00:00
|
|
|
#include "key-state.h"
|
2020-09-28 20:41:41 +01:00
|
|
|
#include "labwc.h"
|
2023-08-30 11:20:46 +02:00
|
|
|
#include "menu/menu.h"
|
2022-07-06 07:19:28 +02:00
|
|
|
#include "regions.h"
|
2023-02-05 19:29:24 +00:00
|
|
|
#include "view.h"
|
2022-06-15 02:02:50 +02:00
|
|
|
#include "workspaces.h"
|
2020-05-29 21:44:50 +01:00
|
|
|
|
2022-08-30 15:47:00 +01:00
|
|
|
static bool should_cancel_cycling_on_next_key_release;
|
|
|
|
|
|
2021-07-01 17:53:47 +01:00
|
|
|
static void
|
|
|
|
|
change_vt(struct server *server, unsigned int vt)
|
|
|
|
|
{
|
|
|
|
|
if (!wlr_backend_is_multi(server->backend)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
struct wlr_session *session = wlr_backend_get_session(server->backend);
|
|
|
|
|
if (session) {
|
|
|
|
|
wlr_session_change_vt(session, vt);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 01:19:31 +02:00
|
|
|
bool
|
|
|
|
|
keyboard_any_modifiers_pressed(struct wlr_keyboard *keyboard)
|
2021-08-28 18:42:18 +01:00
|
|
|
{
|
2021-10-15 20:52:36 +01:00
|
|
|
xkb_mod_index_t i;
|
2021-08-28 19:05:19 +01:00
|
|
|
for (i = 0; i < xkb_keymap_num_mods(keyboard->keymap); i++) {
|
2023-01-31 11:43:45 +01:00
|
|
|
if (xkb_state_mod_index_is_active(keyboard->xkb_state,
|
|
|
|
|
i, XKB_STATE_MODS_DEPRESSED)) {
|
2021-08-28 18:42:18 +01:00
|
|
|
return true;
|
2021-08-28 19:05:19 +01:00
|
|
|
}
|
2021-08-28 18:42:18 +01:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-30 15:47:00 +01:00
|
|
|
static void
|
|
|
|
|
end_cycling(struct server *server)
|
|
|
|
|
{
|
2023-04-01 14:06:52 -04:00
|
|
|
if (server->osd_state.cycle_view) {
|
2023-09-27 18:37:28 -04:00
|
|
|
desktop_focus_view(server->osd_state.cycle_view,
|
|
|
|
|
/*raise*/ true);
|
2023-04-01 14:06:52 -04:00
|
|
|
}
|
2022-08-30 15:47:00 +01:00
|
|
|
|
|
|
|
|
/* osd_finish() additionally resets cycle_view to NULL */
|
|
|
|
|
osd_finish(server);
|
|
|
|
|
should_cancel_cycling_on_next_key_release = false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-26 07:17:19 +01:00
|
|
|
void
|
2020-10-02 21:19:56 +01:00
|
|
|
keyboard_modifiers_notify(struct wl_listener *listener, void *data)
|
2020-05-29 21:44:50 +01:00
|
|
|
{
|
2022-09-26 07:17:19 +01:00
|
|
|
struct keyboard *keyboard = wl_container_of(listener, keyboard, modifier);
|
|
|
|
|
struct seat *seat = keyboard->base.seat;
|
2021-08-28 18:42:18 +01:00
|
|
|
struct server *server = seat->server;
|
2022-09-26 07:17:19 +01:00
|
|
|
struct wlr_keyboard *wlr_keyboard = keyboard->wlr_keyboard;
|
2021-08-28 18:42:18 +01:00
|
|
|
|
2023-03-07 17:51:28 +01:00
|
|
|
if (server->input_mode == LAB_INPUT_STATE_MOVE) {
|
|
|
|
|
/* Any change to the modifier state re-enable region snap */
|
|
|
|
|
seat->region_prevent_snap = false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 07:19:28 +02:00
|
|
|
if (server->osd_state.cycle_view || server->grabbed_view
|
|
|
|
|
|| seat->workspace_osd_shown_by_modifier) {
|
2023-03-07 17:58:15 +01:00
|
|
|
if (!keyboard_any_modifiers_pressed(wlr_keyboard)) {
|
2022-04-26 22:06:22 +02:00
|
|
|
if (server->osd_state.cycle_view) {
|
2022-08-30 15:47:00 +01:00
|
|
|
if (key_state_nr_keys()) {
|
|
|
|
|
should_cancel_cycling_on_next_key_release = true;
|
|
|
|
|
} else {
|
|
|
|
|
end_cycling(server);
|
|
|
|
|
}
|
2022-06-15 02:02:50 +02:00
|
|
|
}
|
|
|
|
|
if (seat->workspace_osd_shown_by_modifier) {
|
|
|
|
|
workspaces_osd_hide(seat);
|
|
|
|
|
}
|
2022-07-06 07:19:28 +02:00
|
|
|
if (server->grabbed_view) {
|
2022-09-13 08:15:33 +02:00
|
|
|
regions_hide_overlay(seat);
|
2022-07-06 07:19:28 +02:00
|
|
|
}
|
2021-08-28 18:42:18 +01:00
|
|
|
}
|
|
|
|
|
}
|
2022-09-26 07:17:19 +01:00
|
|
|
wlr_seat_keyboard_notify_modifiers(seat->seat, &wlr_keyboard->modifiers);
|
2020-05-29 21:44:50 +01:00
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static bool
|
2023-09-05 15:18:41 +02:00
|
|
|
handle_keybinding(struct server *server, uint32_t modifiers, xkb_keysym_t sym, xkb_keycode_t code)
|
2020-06-17 21:21:28 +01:00
|
|
|
{
|
|
|
|
|
struct keybind *keybind;
|
2023-01-29 04:06:46 +01:00
|
|
|
wl_list_for_each(keybind, &rc.keybinds, link) {
|
2020-09-28 20:41:41 +01:00
|
|
|
if (modifiers ^ keybind->modifiers) {
|
2020-06-17 21:21:28 +01:00
|
|
|
continue;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2023-03-05 10:35:56 +01:00
|
|
|
if (server->seat.nr_inhibited_keybind_views
|
|
|
|
|
&& view_inhibits_keybinds(desktop_focused_view(server))
|
2023-03-03 18:16:46 +01:00
|
|
|
&& !actions_contain_toggle_keybinds(&keybind->actions)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2023-09-05 15:18:41 +02:00
|
|
|
if (sym == XKB_KEY_NoSymbol) {
|
|
|
|
|
/* Use keycodes */
|
|
|
|
|
for (size_t i = 0; i < keybind->keycodes_len; i++) {
|
|
|
|
|
if (keybind->keycodes[i] == code) {
|
|
|
|
|
key_state_store_pressed_keys_as_bound();
|
|
|
|
|
actions_run(NULL, server, &keybind->actions, 0);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* Use syms */
|
|
|
|
|
for (size_t i = 0; i < keybind->keysyms_len; i++) {
|
|
|
|
|
if (xkb_keysym_to_lower(sym) == keybind->keysyms[i]) {
|
|
|
|
|
key_state_store_pressed_keys_as_bound();
|
|
|
|
|
actions_run(NULL, server, &keybind->actions, 0);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2020-06-17 21:21:28 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2020-05-29 21:44:50 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-17 22:53:43 +00:00
|
|
|
static bool is_modifier_key(xkb_keysym_t sym)
|
|
|
|
|
{
|
2023-01-31 11:43:45 +01:00
|
|
|
return sym == XKB_KEY_Shift_L
|
|
|
|
|
|| sym == XKB_KEY_Shift_R
|
|
|
|
|
|| sym == XKB_KEY_Alt_L
|
|
|
|
|
|| sym == XKB_KEY_Alt_R
|
|
|
|
|
|| sym == XKB_KEY_Control_L
|
|
|
|
|
|| sym == XKB_KEY_Control_R
|
|
|
|
|
|| sym == XKB_KEY_Super_L
|
|
|
|
|
|| sym == XKB_KEY_Super_R;
|
2021-10-17 22:53:43 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-17 20:05:53 +01:00
|
|
|
struct keysyms {
|
|
|
|
|
const xkb_keysym_t *syms;
|
|
|
|
|
int nr_syms;
|
|
|
|
|
};
|
|
|
|
|
|
2023-08-30 11:20:46 +02:00
|
|
|
static void
|
|
|
|
|
handle_menu_keys(struct server *server, struct keysyms *syms)
|
|
|
|
|
{
|
|
|
|
|
assert(server->input_mode == LAB_INPUT_STATE_MENU);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < syms->nr_syms; i++) {
|
|
|
|
|
switch (syms->syms[i]) {
|
|
|
|
|
case XKB_KEY_Down:
|
|
|
|
|
menu_item_select_next(server);
|
|
|
|
|
break;
|
|
|
|
|
case XKB_KEY_Up:
|
|
|
|
|
menu_item_select_previous(server);
|
|
|
|
|
break;
|
|
|
|
|
case XKB_KEY_Right:
|
|
|
|
|
menu_submenu_enter(server);
|
|
|
|
|
break;
|
|
|
|
|
case XKB_KEY_Left:
|
|
|
|
|
menu_submenu_leave(server);
|
|
|
|
|
break;
|
|
|
|
|
case XKB_KEY_Return:
|
|
|
|
|
if (menu_call_selected_actions(server)) {
|
|
|
|
|
menu_close_root(server);
|
|
|
|
|
cursor_update_focus(server);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case XKB_KEY_Escape:
|
|
|
|
|
menu_close_root(server);
|
|
|
|
|
cursor_update_focus(server);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-21 17:12:02 +01:00
|
|
|
static bool
|
2022-11-02 16:37:24 -04:00
|
|
|
handle_compositor_keybindings(struct keyboard *keyboard,
|
2022-03-19 11:34:11 +00:00
|
|
|
struct wlr_keyboard_key_event *event)
|
2020-05-29 21:44:50 +01:00
|
|
|
{
|
2022-09-26 07:17:19 +01:00
|
|
|
struct seat *seat = keyboard->base.seat;
|
2020-10-02 21:19:56 +01:00
|
|
|
struct server *server = seat->server;
|
2022-09-26 07:17:19 +01:00
|
|
|
struct wlr_keyboard *wlr_keyboard = keyboard->wlr_keyboard;
|
2020-05-29 21:44:50 +01:00
|
|
|
|
|
|
|
|
/* Translate libinput keycode -> xkbcommon */
|
|
|
|
|
uint32_t keycode = event->keycode + 8;
|
2023-07-17 20:05:53 +01:00
|
|
|
|
2020-05-29 21:44:50 +01:00
|
|
|
/* Get a list of keysyms based on the keymap for this keyboard */
|
2023-07-17 20:05:53 +01:00
|
|
|
struct keysyms translated = { 0 };
|
|
|
|
|
translated.nr_syms = xkb_state_key_get_syms(wlr_keyboard->xkb_state,
|
|
|
|
|
keycode, &translated.syms);
|
2020-05-29 21:44:50 +01:00
|
|
|
|
2023-07-17 20:08:32 +01:00
|
|
|
/*
|
|
|
|
|
* Get keysyms from the keyboard as if there was no modifier
|
|
|
|
|
* translations. For example, get Shift+1 rather than Shift+! (with US
|
|
|
|
|
* keyboard layout).
|
|
|
|
|
*/
|
|
|
|
|
struct keysyms raw = { 0 };
|
|
|
|
|
xkb_layout_index_t layout_index =
|
|
|
|
|
xkb_state_key_get_layout(wlr_keyboard->xkb_state, keycode);
|
|
|
|
|
raw.nr_syms = xkb_keymap_key_get_syms_by_level(wlr_keyboard->keymap,
|
|
|
|
|
keycode, layout_index, 0, &raw.syms);
|
|
|
|
|
|
2020-05-29 21:44:50 +01:00
|
|
|
bool handled = false;
|
2021-08-28 18:42:18 +01:00
|
|
|
|
2023-09-26 17:51:54 +01:00
|
|
|
/*
|
|
|
|
|
* keyboard_key_notify() is called before keyboard_key_modifier(), so
|
|
|
|
|
* 'modifiers' refers to modifiers that were pressed before the key
|
|
|
|
|
* event in hand. Consequently, we use is_modifier_key() to find out if
|
|
|
|
|
* the key event being processed is a modifier.
|
|
|
|
|
*
|
|
|
|
|
* Sway solves this differently by saving the 'modifiers' state and
|
|
|
|
|
* checking if it has changed each time we get to the equivalent of this
|
|
|
|
|
* function. If it has changed, it concludes that the last key was a
|
|
|
|
|
* modifier and then deletes it from the buffer of pressed keycodes.
|
|
|
|
|
* For us the equivalent would look something like this:
|
|
|
|
|
*
|
|
|
|
|
* static uint32_t last_modifiers;
|
|
|
|
|
* bool last_key_was_a_modifier = last_modifiers != modifiers;
|
|
|
|
|
* last_modifiers = modifiers;
|
|
|
|
|
* if (last_key_was_a_modifier) {
|
|
|
|
|
* key_state_remove_last_pressed_key(last_pressed_keycode);
|
|
|
|
|
* }
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
bool ismodifier = false;
|
|
|
|
|
for (int i = 0; i < translated.nr_syms; i++) {
|
|
|
|
|
ismodifier |= is_modifier_key(translated.syms[i]);
|
|
|
|
|
}
|
|
|
|
|
if (!ismodifier) {
|
|
|
|
|
key_state_set_pressed(event->keycode,
|
|
|
|
|
event->state == WL_KEYBOARD_KEY_STATE_PRESSED);
|
|
|
|
|
}
|
2021-12-21 22:25:59 +00:00
|
|
|
|
2022-08-30 21:07:27 +01:00
|
|
|
/*
|
|
|
|
|
* Ignore labwc keybindings if input is inhibited
|
|
|
|
|
* It's important to do this after key_state_set_pressed() to ensure
|
|
|
|
|
* _all_ key press/releases are registered
|
|
|
|
|
*/
|
|
|
|
|
if (seat->active_client_while_inhibited) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-03-30 22:19:05 +01:00
|
|
|
if (seat->server->session_lock) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-08-30 21:07:27 +01:00
|
|
|
|
2022-08-30 15:47:00 +01:00
|
|
|
/*
|
|
|
|
|
* If a user lets go of the modifier (e.g. alt) before the 'normal' key
|
|
|
|
|
* (e.g. tab) when window-cycling, we do not end the cycling until both
|
|
|
|
|
* keys have been released. If we end the window-cycling on release of
|
|
|
|
|
* the modifier only, some XWayland clients such as hexchat realise that
|
|
|
|
|
* tab is pressed (even though we did not forward the event) and because
|
|
|
|
|
* we absorb the equivalent release event it gets stuck on repeat.
|
|
|
|
|
*/
|
|
|
|
|
if (should_cancel_cycling_on_next_key_release
|
|
|
|
|
&& event->state == WL_KEYBOARD_KEY_STATE_RELEASED) {
|
|
|
|
|
end_cycling(server);
|
|
|
|
|
handled = true;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-21 22:25:59 +00:00
|
|
|
/*
|
|
|
|
|
* If a press event was handled by a compositor binding, then do not
|
|
|
|
|
* forward the corresponding release event to clients
|
|
|
|
|
*/
|
2022-09-20 20:46:39 +01:00
|
|
|
if (key_state_corresponding_press_event_was_bound(event->keycode)
|
2021-12-21 22:25:59 +00:00
|
|
|
&& event->state == WL_KEYBOARD_KEY_STATE_RELEASED) {
|
2022-09-20 20:46:39 +01:00
|
|
|
key_state_bound_key_remove(event->keycode);
|
2021-12-21 22:25:59 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-26 07:17:19 +01:00
|
|
|
uint32_t modifiers = wlr_keyboard_get_modifiers(wlr_keyboard);
|
2020-05-29 21:44:50 +01:00
|
|
|
|
2021-11-01 22:00:52 +00:00
|
|
|
/* Catch C-A-F1 to C-A-F12 to change tty */
|
|
|
|
|
if (event->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
2023-07-17 20:05:53 +01:00
|
|
|
for (int i = 0; i < translated.nr_syms; i++) {
|
|
|
|
|
unsigned int vt = translated.syms[i] - XKB_KEY_XF86Switch_VT_1 + 1;
|
2021-11-01 22:00:52 +00:00
|
|
|
if (vt >= 1 && vt <= 12) {
|
|
|
|
|
change_vt(server, vt);
|
2022-04-04 20:53:36 +01:00
|
|
|
/*
|
|
|
|
|
* Don't send any key events to clients when
|
|
|
|
|
* changing tty
|
|
|
|
|
*/
|
2022-08-30 15:41:50 +01:00
|
|
|
handled = true;
|
|
|
|
|
goto out;
|
2021-11-01 22:00:52 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-30 11:20:46 +02:00
|
|
|
if (server->input_mode == LAB_INPUT_STATE_MENU) {
|
|
|
|
|
/*
|
|
|
|
|
* Usually, release events are already caught via _press_event_was_bound().
|
|
|
|
|
* But to be on the safe side we will simply ignore them here as well.
|
|
|
|
|
*/
|
|
|
|
|
if (event->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
|
|
|
|
handle_menu_keys(server, &translated);
|
|
|
|
|
}
|
|
|
|
|
handled = true;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-26 22:06:22 +02:00
|
|
|
if (server->osd_state.cycle_view) {
|
2021-08-28 18:42:18 +01:00
|
|
|
if (event->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
2023-07-17 20:05:53 +01:00
|
|
|
for (int i = 0; i < translated.nr_syms; i++) {
|
|
|
|
|
if (translated.syms[i] == XKB_KEY_Escape) {
|
2022-08-30 15:43:57 +01:00
|
|
|
/*
|
|
|
|
|
* Cancel view-cycle
|
|
|
|
|
*
|
|
|
|
|
* osd_finish() additionally resets
|
|
|
|
|
* cycle_view to NULL
|
|
|
|
|
*/
|
2022-04-26 23:56:27 +02:00
|
|
|
osd_preview_restore(server);
|
2022-08-21 15:07:16 -04:00
|
|
|
osd_finish(server);
|
2022-08-30 15:41:50 +01:00
|
|
|
|
|
|
|
|
handled = true;
|
|
|
|
|
goto out;
|
2021-12-04 10:22:34 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-29 21:44:50 +01:00
|
|
|
/* cycle to next */
|
2021-10-17 22:53:43 +00:00
|
|
|
bool backwards = modifiers & WLR_MODIFIER_SHIFT;
|
2023-09-26 17:51:54 +01:00
|
|
|
if (!ismodifier) {
|
2022-04-04 20:53:36 +01:00
|
|
|
enum lab_cycle_dir dir = backwards
|
|
|
|
|
? LAB_CYCLE_DIR_BACKWARD
|
|
|
|
|
: LAB_CYCLE_DIR_FORWARD;
|
2022-04-26 22:06:22 +02:00
|
|
|
server->osd_state.cycle_view = desktop_cycle_view(server,
|
|
|
|
|
server->osd_state.cycle_view, dir);
|
2021-10-17 22:53:43 +00:00
|
|
|
osd_update(server);
|
|
|
|
|
}
|
2020-05-29 21:44:50 +01:00
|
|
|
}
|
2021-08-28 20:37:34 +01:00
|
|
|
/* don't send any key events to clients when osd onscreen */
|
2022-08-30 15:41:50 +01:00
|
|
|
handled = true;
|
|
|
|
|
goto out;
|
2020-05-29 21:44:50 +01:00
|
|
|
}
|
|
|
|
|
|
2023-09-26 17:51:54 +01:00
|
|
|
/*
|
|
|
|
|
* A keybind is not considered valid if other keys are pressed at the
|
|
|
|
|
* same time.
|
|
|
|
|
*
|
|
|
|
|
* In labwc, a keybind is defined by one/many modifier keys + _one_
|
|
|
|
|
* non-modifier key. Returning early on >1 pressed non-modifier keys
|
|
|
|
|
* avoids false positive matches where 'other' keys were pressed at the
|
|
|
|
|
* same time.
|
|
|
|
|
*/
|
|
|
|
|
if (key_state_nr_pressed_keys() > 1) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-05 15:18:41 +02:00
|
|
|
/*
|
|
|
|
|
* Handle compositor keybinds
|
|
|
|
|
*
|
|
|
|
|
* When matching against keybinds, we process the input keys in the
|
|
|
|
|
* following order of precedence:
|
|
|
|
|
* a. Keycodes (of physical keys) (not if keybind is layoutDependent)
|
|
|
|
|
* b. Translated keysyms (taking into account modifiers, so if Shift+1
|
|
|
|
|
* were pressed on a us keyboard, the keysym would be '!')
|
|
|
|
|
* c. Raw keysyms (ignoring modifiers such as shift, so in the above
|
|
|
|
|
* example the keysym would just be '1')
|
|
|
|
|
*
|
|
|
|
|
* The reasons for this approach are:
|
|
|
|
|
* 1. To make keybinds keyboard-layout agnostic (by checking keycodes
|
|
|
|
|
* before keysyms). This means that in a multi-layout situation,
|
|
|
|
|
* keybinds work regardless of which layout is active at the time
|
|
|
|
|
* of the key-press.
|
|
|
|
|
* 2. To support keybinds relating to keysyms that are only available
|
|
|
|
|
* in a particular layout, for example å, ä and ö.
|
|
|
|
|
* 3. To support keybinds that are only valid with a modifier, for
|
|
|
|
|
* example the numpad keys with NumLock enabled: KP_x. These would
|
|
|
|
|
* only be matched by the translated keysyms.
|
|
|
|
|
* 4. To support keybinds such as `S-1` (by checking raw keysyms).
|
|
|
|
|
*
|
|
|
|
|
* Reason 4 will also be satisfied by matching the keycodes. However,
|
|
|
|
|
* when a keybind is configured to be layoutDependent we still need
|
|
|
|
|
* the raw keysym fallback.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-12-01 17:14:59 +00:00
|
|
|
if (event->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
2023-09-05 15:18:41 +02:00
|
|
|
/* First try keycodes */
|
|
|
|
|
handled |= handle_keybinding(server, modifiers, XKB_KEY_NoSymbol, keycode);
|
|
|
|
|
if (handled) {
|
|
|
|
|
wlr_log(WLR_DEBUG, "keycodes matched");
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Then fall back to keysyms */
|
2023-07-17 20:05:53 +01:00
|
|
|
for (int i = 0; i < translated.nr_syms; i++) {
|
2023-09-05 15:18:41 +02:00
|
|
|
handled |= handle_keybinding(server, modifiers,
|
|
|
|
|
translated.syms[i], keycode);
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2023-07-17 20:08:32 +01:00
|
|
|
if (handled) {
|
2023-09-05 15:18:41 +02:00
|
|
|
wlr_log(WLR_DEBUG, "translated keysyms matched");
|
2023-07-17 20:08:32 +01:00
|
|
|
goto out;
|
|
|
|
|
}
|
2023-09-05 15:18:41 +02:00
|
|
|
|
|
|
|
|
/* And finally test for keysyms without modifier */
|
2023-07-17 20:08:32 +01:00
|
|
|
for (int i = 0; i < raw.nr_syms; i++) {
|
2023-09-05 15:18:41 +02:00
|
|
|
handled |= handle_keybinding(server, modifiers, raw.syms[i], keycode);
|
|
|
|
|
}
|
|
|
|
|
if (handled) {
|
|
|
|
|
wlr_log(WLR_DEBUG, "raw keysyms matched");
|
2023-07-17 20:08:32 +01:00
|
|
|
}
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2021-12-21 22:25:59 +00:00
|
|
|
|
2022-08-30 15:41:50 +01:00
|
|
|
out:
|
2021-12-21 22:25:59 +00:00
|
|
|
if (handled) {
|
|
|
|
|
key_state_store_pressed_keys_as_bound();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-21 17:12:02 +01:00
|
|
|
return handled;
|
|
|
|
|
}
|
2021-08-25 19:59:49 +01:00
|
|
|
|
2022-11-02 16:37:24 -04:00
|
|
|
static int
|
|
|
|
|
handle_keybind_repeat(void *data)
|
|
|
|
|
{
|
|
|
|
|
struct keyboard *keyboard = data;
|
|
|
|
|
assert(keyboard->keybind_repeat);
|
2022-11-09 20:29:48 +00:00
|
|
|
assert(keyboard->keybind_repeat_rate > 0);
|
2022-11-02 16:37:24 -04:00
|
|
|
|
|
|
|
|
/* synthesize event */
|
|
|
|
|
struct wlr_keyboard_key_event event = {
|
|
|
|
|
.keycode = keyboard->keybind_repeat_keycode,
|
|
|
|
|
.state = WL_KEYBOARD_KEY_STATE_PRESSED
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
handle_compositor_keybindings(keyboard, &event);
|
2022-11-09 20:29:48 +00:00
|
|
|
int next_repeat_ms = 1000 / keyboard->keybind_repeat_rate;
|
2022-11-02 16:37:24 -04:00
|
|
|
wl_event_source_timer_update(keyboard->keybind_repeat,
|
2022-11-09 20:29:48 +00:00
|
|
|
next_repeat_ms);
|
2022-11-02 16:37:24 -04:00
|
|
|
|
|
|
|
|
return 0; /* ignored per wl_event_loop docs */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
start_keybind_repeat(struct server *server, struct keyboard *keyboard,
|
|
|
|
|
struct wlr_keyboard_key_event *event)
|
|
|
|
|
{
|
|
|
|
|
struct wlr_keyboard *wlr_keyboard = keyboard->wlr_keyboard;
|
|
|
|
|
assert(!keyboard->keybind_repeat);
|
|
|
|
|
|
|
|
|
|
if (wlr_keyboard->repeat_info.rate > 0
|
|
|
|
|
&& wlr_keyboard->repeat_info.delay > 0) {
|
|
|
|
|
keyboard->keybind_repeat_keycode = event->keycode;
|
|
|
|
|
keyboard->keybind_repeat_rate = wlr_keyboard->repeat_info.rate;
|
|
|
|
|
keyboard->keybind_repeat = wl_event_loop_add_timer(
|
|
|
|
|
server->wl_event_loop, handle_keybind_repeat, keyboard);
|
|
|
|
|
wl_event_source_timer_update(keyboard->keybind_repeat,
|
|
|
|
|
wlr_keyboard->repeat_info.delay);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
keyboard_cancel_keybind_repeat(struct keyboard *keyboard)
|
|
|
|
|
{
|
|
|
|
|
if (keyboard->keybind_repeat) {
|
|
|
|
|
wl_event_source_remove(keyboard->keybind_repeat);
|
|
|
|
|
keyboard->keybind_repeat = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-26 07:17:19 +01:00
|
|
|
void
|
2021-08-21 17:12:02 +01:00
|
|
|
keyboard_key_notify(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
/* This event is raised when a key is pressed or released. */
|
2022-09-26 07:17:19 +01:00
|
|
|
struct keyboard *keyboard = wl_container_of(listener, keyboard, key);
|
|
|
|
|
struct seat *seat = keyboard->base.seat;
|
2022-03-19 11:34:11 +00:00
|
|
|
struct wlr_keyboard_key_event *event = data;
|
2022-09-26 07:17:19 +01:00
|
|
|
struct wlr_seat *wlr_seat = seat->seat;
|
|
|
|
|
struct wlr_keyboard *wlr_keyboard = keyboard->wlr_keyboard;
|
2023-07-08 18:27:40 +02:00
|
|
|
idle_manager_notify_activity(seat->seat);
|
2021-08-21 17:12:02 +01:00
|
|
|
|
2022-11-02 16:37:24 -04:00
|
|
|
/* any new press/release cancels current keybind repeat */
|
|
|
|
|
keyboard_cancel_keybind_repeat(keyboard);
|
2021-07-01 17:53:47 +01:00
|
|
|
|
2022-11-02 16:37:24 -04:00
|
|
|
bool handled = handle_compositor_keybindings(keyboard, event);
|
|
|
|
|
if (handled) {
|
|
|
|
|
if (event->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
|
|
|
|
start_keybind_repeat(seat->server, keyboard, event);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2022-09-26 07:17:19 +01:00
|
|
|
wlr_seat_set_keyboard(wlr_seat, wlr_keyboard);
|
2020-10-02 21:19:56 +01:00
|
|
|
wlr_seat_keyboard_notify_key(wlr_seat, event->time_msec,
|
2022-09-20 20:46:39 +01:00
|
|
|
event->keycode, event->state);
|
2020-05-29 21:44:50 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
void
|
2020-10-02 21:19:56 +01:00
|
|
|
keyboard_init(struct seat *seat)
|
2020-05-29 21:44:50 +01:00
|
|
|
{
|
2020-10-02 21:19:56 +01:00
|
|
|
seat->keyboard_group = wlr_keyboard_group_create();
|
|
|
|
|
struct wlr_keyboard *kb = &seat->keyboard_group->keyboard;
|
2020-05-29 21:44:50 +01:00
|
|
|
struct xkb_rule_names rules = { 0 };
|
|
|
|
|
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
2020-10-02 21:19:56 +01:00
|
|
|
struct xkb_keymap *keymap = xkb_map_new_from_names(context, &rules,
|
|
|
|
|
XKB_KEYMAP_COMPILE_NO_FLAGS);
|
2022-09-17 14:47:47 -04:00
|
|
|
if (keymap) {
|
|
|
|
|
wlr_keyboard_set_keymap(kb, keymap);
|
|
|
|
|
xkb_keymap_unref(keymap);
|
|
|
|
|
} else {
|
|
|
|
|
wlr_log(WLR_ERROR, "Failed to create xkb keymap");
|
|
|
|
|
}
|
2020-05-29 21:44:50 +01:00
|
|
|
xkb_context_unref(context);
|
2021-10-09 15:16:02 -04:00
|
|
|
wlr_keyboard_set_repeat_info(kb, rc.repeat_rate, rc.repeat_delay);
|
2023-09-05 15:18:41 +02:00
|
|
|
|
|
|
|
|
keybind_update_keycodes(seat->server);
|
2020-05-29 21:44:50 +01:00
|
|
|
}
|
2021-12-31 23:30:25 +00:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
keyboard_finish(struct seat *seat)
|
|
|
|
|
{
|
2022-09-26 07:17:19 +01:00
|
|
|
/*
|
|
|
|
|
* All keyboard listeners must be removed before this to avoid use after
|
|
|
|
|
* free
|
|
|
|
|
*/
|
2021-12-31 23:30:25 +00:00
|
|
|
if (seat->keyboard_group) {
|
|
|
|
|
wlr_keyboard_group_destroy(seat->keyboard_group);
|
2022-09-15 19:50:07 -04:00
|
|
|
seat->keyboard_group = NULL;
|
2021-12-31 23:30:25 +00:00
|
|
|
}
|
|
|
|
|
}
|