action: remember initial direction of PreviousView

...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
This commit is contained in:
droc12345 2024-06-26 16:03:56 -05:00 committed by GitHub
parent 7f94486773
commit f2755a4e2e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 70 additions and 24 deletions

View 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.

View 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

View 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);

View 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 backwards = (keyinfo->modifiers & WLR_MODIFIER_SHIFT) || back_key;
enum lab_cycle_dir dir = backwards
? LAB_CYCLE_DIR_BACKWARD
: LAB_CYCLE_DIR_FORWARD;
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);
}
/* 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);
}
}