]> git.mdlowis.com Git - proto/labwc.git/commitdiff
action: remember initial direction of PreviousView
authordroc12345 <80716141+droc12345@users.noreply.github.com>
Wed, 26 Jun 2024 21:03:56 +0000 (16:03 -0500)
committerGitHub <noreply@github.com>
Wed, 26 Jun 2024 21:03:56 +0000 (22:03 +0100)
...when cycling windows. Also make the toggling of direction when shift
is pressed relative to the initial direction. For example if W-j is
bound to PreviousWindow, subsequent key presses will continue to
cycle backwards unless shift if pressed.

Add documentation for using shift/arrow keys in Next/Previous

docs/labwc-actions.5.scd
include/labwc.h
src/action.c
src/input/keyboard.c

index 50f6ad33ad095236ef8f3135730296473f094246..e2edf387d3d09bfef1ef633a0161b7a3674ea34d 100644 (file)
@@ -99,11 +99,14 @@ Actions are used in menus and keyboard/mouse bindings.
        Resize and move active window according to the given region.
        See labwc-config(5) for further information on how to define regions.
 
-*<action name="NextWindow" />*
-       Cycle focus to next window.
-
+*<action name="NextWindow" />*++
 *<action name="PreviousWindow" />*
-       Cycle focus to previous window.
+       Cycle focus to next/previous window respectively.++
+       Default keybind for NextWindow is Alt-Tab.
+
+       The shift key is used to reverse direction while cycling.
+
+       The arrow keys are used to move forwards/backwards while cycling.
 
 *<action name="Reconfigure" />*
        Re-load configuration and theme files.
index e3f1ad2309dd718c9f4e29d82417f23d30c344be..a19f8243d6db5b5d02e63624a24e9859b5b759c9 100644 (file)
@@ -210,6 +210,12 @@ struct seat {
 struct lab_data_buffer;
 struct workspace;
 
+enum lab_cycle_dir {
+       LAB_CYCLE_DIR_NONE,
+       LAB_CYCLE_DIR_FORWARD,
+       LAB_CYCLE_DIR_BACKWARD,
+};
+
 struct server {
        struct wl_display *wl_display;
        struct wl_event_loop *wl_event_loop;  /* Can be used for timer events */
@@ -349,6 +355,8 @@ struct server {
                struct wlr_scene_tree *preview_parent;
                struct wlr_scene_node *preview_anchor;
                struct multi_rect *preview_outline;
+               enum lab_cycle_dir initial_direction;
+               bool initial_keybind_contained_shift;
        } osd_state;
 
        struct theme *theme;
@@ -442,12 +450,6 @@ struct view *desktop_topmost_focusable_view(struct server *server);
  */
 void desktop_update_top_layer_visiblity(struct server *server);
 
-enum lab_cycle_dir {
-       LAB_CYCLE_DIR_NONE,
-       LAB_CYCLE_DIR_FORWARD,
-       LAB_CYCLE_DIR_BACKWARD,
-};
-
 /**
  * desktop_cycle_view - return view to 'cycle' to
  * @start_view: reference point for finding next view to cycle to
index 80231b954cbac0190a9427caf154103f587fb8bd..0aa45d7a863b5e51feeacfeece7e95bbf648e0a5 100644 (file)
@@ -701,6 +701,26 @@ run_if_action(struct view *view, struct server *server, struct action *action)
        return !strcmp(branch, "then");
 }
 
+static bool
+shift_is_pressed(struct server *server)
+{
+       uint32_t modifiers = wlr_keyboard_get_modifiers(
+                       &server->seat.keyboard_group->keyboard);
+       return modifiers & WLR_MODIFIER_SHIFT;
+}
+
+static void
+start_window_cycling(struct server *server, enum lab_cycle_dir direction)
+{
+       /* Remember direction so it can be followed by subsequent key presses */
+       server->osd_state.initial_direction = direction;
+       server->osd_state.initial_keybind_contained_shift =
+               shift_is_pressed(server);
+       server->osd_state.cycle_view = desktop_cycle_view(server,
+               server->osd_state.cycle_view, direction);
+       osd_update(server);
+}
+
 void
 actions_run(struct view *activator, struct server *server,
        struct wl_list *actions, uint32_t resize_edges)
@@ -791,14 +811,10 @@ actions_run(struct view *activator, struct server *server,
                        }
                        break;
                case ACTION_TYPE_NEXT_WINDOW:
-                       server->osd_state.cycle_view = desktop_cycle_view(server,
-                               server->osd_state.cycle_view, LAB_CYCLE_DIR_FORWARD);
-                       osd_update(server);
+                       start_window_cycling(server, LAB_CYCLE_DIR_FORWARD);
                        break;
                case ACTION_TYPE_PREVIOUS_WINDOW:
-                       server->osd_state.cycle_view = desktop_cycle_view(server,
-                               server->osd_state.cycle_view, LAB_CYCLE_DIR_BACKWARD);
-                       osd_update(server);
+                       start_window_cycling(server, LAB_CYCLE_DIR_BACKWARD);
                        break;
                case ACTION_TYPE_RECONFIGURE:
                        kill(getpid(), SIGHUP);
index 147ec4dcbc0728df34b9b86c36fb94b510209238..5806441a00e3134e94bfc749b45f5c7fbde271f6 100644 (file)
@@ -383,6 +383,16 @@ handle_menu_keys(struct server *server, struct keysyms *syms)
        }
 }
 
+static void
+toggle_direction(enum lab_cycle_dir *direction)
+{
+       if (*direction == LAB_CYCLE_DIR_FORWARD) {
+               *direction = LAB_CYCLE_DIR_BACKWARD;
+       } else if (*direction == LAB_CYCLE_DIR_BACKWARD) {
+               *direction = LAB_CYCLE_DIR_FORWARD;
+       }
+}
+
 static void
 handle_cycle_view_key(struct server *server, struct keyinfo *keyinfo)
 {
@@ -397,21 +407,36 @@ handle_cycle_view_key(struct server *server, struct keyinfo *keyinfo)
 
        /* cycle to next */
        if (!keyinfo->is_modifier) {
-               bool back_key = false;
+               enum lab_cycle_dir direction = server->osd_state.initial_direction;
                for (int i = 0; i < keyinfo->translated.nr_syms; i++) {
                        if (keyinfo->translated.syms[i] == XKB_KEY_Up
                                        || keyinfo->translated.syms[i] == XKB_KEY_Left) {
-                               back_key = true;
-                               break;
+                               direction = LAB_CYCLE_DIR_BACKWARD;
+                               goto miss_shift_toggle;
                        }
+                       if (keyinfo->translated.syms[i] == XKB_KEY_Down
+                                       || keyinfo->translated.syms[i] == XKB_KEY_Right) {
+                               direction = LAB_CYCLE_DIR_FORWARD;
+                               goto miss_shift_toggle;
+                       }
+               }
+
+               bool shift_is_pressed = keyinfo->modifiers & WLR_MODIFIER_SHIFT;
+               if (shift_is_pressed != server->osd_state.initial_keybind_contained_shift) {
+                       /*
+                        * Shift reverses the direction - unless shift was part of the
+                        * original keybind in which case we do the opposite.
+                        * For example with S-A-Tab bound to PreviousWindow, shift with
+                        * subsequent key presses should carry on cycling backwards.
+                        */
+                       toggle_direction(&direction);
                }
-               bool backwards = (keyinfo->modifiers & WLR_MODIFIER_SHIFT) || back_key;
 
-               enum lab_cycle_dir dir = backwards
-                       ? LAB_CYCLE_DIR_BACKWARD
-                       : LAB_CYCLE_DIR_FORWARD;
+       /* Only one direction modifier is allowed, either arrow keys OR shift */
+miss_shift_toggle:
+
                server->osd_state.cycle_view = desktop_cycle_view(server,
-                       server->osd_state.cycle_view, dir);
+                       server->osd_state.cycle_view, direction);
                osd_update(server);
        }
 }