From 116382fd896e82b9a1823143519b7cbee208c10b Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Fri, 2 Aug 2024 14:08:19 +0200 Subject: [PATCH] keybind: implement allowWhenLocked fixes #2034 see https://github.com/swaywm/sway/blob/bc258a3be2f946c1c93bcbe40735b2db068e0ea8/sway/sway.5.scd?plain=1#L409 --- docs/labwc-config.5.scd | 5 ++++- include/config/keybind.h | 1 + src/config/rcxml.c | 2 ++ src/input/keyboard.c | 29 ++++++++++++++--------------- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/docs/labwc-config.5.scd b/docs/labwc-config.5.scd index ee04c6cb..df2ecbe1 100644 --- a/docs/labwc-config.5.scd +++ b/docs/labwc-config.5.scd @@ -499,7 +499,7 @@ extending outward from the snapped edge. Stores the keyboard layout either globally or per window and restores it when switching back to the window. Default is global. -** +** Define a *key* binding in the format *modifier-key*, where supported modifiers are: - S (shift) @@ -541,6 +541,9 @@ extending outward from the snapped edge. ``` + *allowWhenLocked* [yes|no] + Make this keybind work even if the screen is locked. Default is no. + ** Keybind action. See labwc-actions(5). diff --git a/include/config/keybind.h b/include/config/keybind.h index fc573316..36d81373 100644 --- a/include/config/keybind.h +++ b/include/config/keybind.h @@ -18,6 +18,7 @@ struct keybind { xkb_keycode_t keycodes[MAX_KEYCODES]; size_t keycodes_len; int keycodes_layout; + bool allow_when_locked; struct wl_list actions; /* struct action.link */ struct wl_list link; /* struct rcxml.keybinds */ bool on_release; diff --git a/src/config/rcxml.c b/src/config/rcxml.c index 74388b10..aa0bface 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -407,6 +407,8 @@ fill_keybind(char *nodename, char *content) set_bool(content, ¤t_keybind->on_release); } else if (!strcasecmp(nodename, "layoutDependent")) { set_bool(content, ¤t_keybind->use_syms_only); + } else if (!strcasecmp(nodename, "allowWhenLocked")) { + set_bool(content, ¤t_keybind->allow_when_locked); } else if (!strcmp(nodename, "name.action")) { current_keybind_action = action_create(content); if (current_keybind_action) { diff --git a/src/input/keyboard.c b/src/input/keyboard.c index a1979aaa..4188a826 100644 --- a/src/input/keyboard.c +++ b/src/input/keyboard.c @@ -449,6 +449,7 @@ handle_compositor_keybindings(struct keyboard *keyboard, struct server *server = seat->server; struct wlr_keyboard *wlr_keyboard = keyboard->wlr_keyboard; struct keyinfo keyinfo = get_keyinfo(wlr_keyboard, event->keycode); + bool locked = seat->server->session_lock_manager->locked; key_state_set_pressed(event->keycode, event->state == WL_KEYBOARD_KEY_STATE_PRESSED, @@ -457,7 +458,7 @@ handle_compositor_keybindings(struct keyboard *keyboard, if (event->state == WL_KEYBOARD_KEY_STATE_RELEASED) { if (cur_keybind && cur_keybind->on_release) { key_state_bound_key_remove(event->keycode); - if (seat->server->session_lock_manager->locked) { + if (locked && !cur_keybind->allow_when_locked) { cur_keybind = NULL; return true; } @@ -479,27 +480,25 @@ handle_compositor_keybindings(struct keyboard *keyboard, * It's important to do this after key_state_set_pressed() to ensure * _all_ key press/releases are registered */ - if (seat->server->session_lock_manager->locked) { - return false; - } + if (!locked) { + if (server->input_mode == LAB_INPUT_STATE_MENU) { + key_state_store_pressed_key_as_bound(event->keycode); + handle_menu_keys(server, &keyinfo.translated); + return true; + } - if (server->input_mode == LAB_INPUT_STATE_MENU) { - key_state_store_pressed_key_as_bound(event->keycode); - handle_menu_keys(server, &keyinfo.translated); - return true; - } - - if (server->osd_state.cycle_view) { - key_state_store_pressed_key_as_bound(event->keycode); - handle_cycle_view_key(server, &keyinfo); - return true; + if (server->osd_state.cycle_view) { + key_state_store_pressed_key_as_bound(event->keycode); + handle_cycle_view_key(server, &keyinfo); + return true; + } } /* * Handle compositor keybinds */ cur_keybind = match_keybinding(server, &keyinfo, keyboard->is_virtual); - if (cur_keybind) { + if (cur_keybind && (!locked || cur_keybind->allow_when_locked)) { /* * Update key-state before action_run() because the action * might lead to seat_focus() in which case we pass the