]> git.mdlowis.com Git - proto/labwc.git/commitdiff
keybind: implement allowWhenLocked
authorTobias Bengfort <tobias.bengfort@posteo.de>
Fri, 2 Aug 2024 12:08:19 +0000 (14:08 +0200)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Tue, 6 Aug 2024 17:15:06 +0000 (19:15 +0200)
fixes #2034

see https://github.com/swaywm/sway/blob/bc258a3be2f946c1c93bcbe40735b2db068e0ea8/sway/sway.5.scd?plain=1#L409

docs/labwc-config.5.scd
include/config/keybind.h
src/config/rcxml.c
src/input/keyboard.c

index ee04c6cb1bf2a7ceaf6f499a5e12bd82d8e438ee..df2ecbe1235369119ec3abcb305207fe0deb733f 100644 (file)
@@ -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.
 
-*<keyboard><keybind key="" layoutDependent="" onRelease="">*
+*<keyboard><keybind key="" layoutDependent="" onRelease="" allowWhenLocked="">*
        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.
        </keybind>
        ```
 
+       *allowWhenLocked* [yes|no]
+       Make this keybind work even if the screen is locked. Default is no.
+
 *<keyboard><keybind key=""><action name="">*
        Keybind action. See labwc-actions(5).
 
index fc573316b4b676b2708408bfe972b72b8a878ef1..36d81373731a48d01eee8d5c775ccd8ccfca0563 100644 (file)
@@ -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;
index 74388b10bc5d4d18ff23b547ae7bc7984e1fe69f..aa0bface58b45f25316c07695a1a8a3c2aee0615 100644 (file)
@@ -407,6 +407,8 @@ fill_keybind(char *nodename, char *content)
                set_bool(content, &current_keybind->on_release);
        } else if (!strcasecmp(nodename, "layoutDependent")) {
                set_bool(content, &current_keybind->use_syms_only);
+       } else if (!strcasecmp(nodename, "allowWhenLocked")) {
+               set_bool(content, &current_keybind->allow_when_locked);
        } else if (!strcmp(nodename, "name.action")) {
                current_keybind_action = action_create(content);
                if (current_keybind_action) {
index a1979aaa601629bfe3d306f75938db9924d9e1b9..4188a826c98ebe87025e3bacc80d435c991a37d0 100644 (file)
@@ -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 (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 (!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->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