diff --git a/include/osd.h b/include/osd.h index 2eefbf71..8b206953 100644 --- a/include/osd.h +++ b/include/osd.h @@ -36,6 +36,13 @@ struct window_switcher_field { struct buf; struct view; struct server; +enum lab_cycle_dir; + +/* Begin window switcher */ +void osd_begin(struct server *server, enum lab_cycle_dir direction); + +/* Cycle the selected view in the window switcher */ +void osd_cycle(struct server *server, enum lab_cycle_dir direction); /* Updates onscreen display 'alt-tab' buffer */ void osd_update(struct server *server); diff --git a/src/action.c b/src/action.c index 121f4b0c..c38b1f05 100644 --- a/src/action.c +++ b/src/action.c @@ -789,33 +789,6 @@ 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) -{ - if (server->input_mode != LAB_INPUT_STATE_PASSTHROUGH) { - return; - } - - /* 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); - - seat_focus_override_begin(&server->seat, - LAB_INPUT_STATE_WINDOW_SWITCHER, LAB_CURSOR_DEFAULT); - osd_update(server); -} - static struct output * get_target_output(struct output *output, struct server *server, struct action *action) @@ -982,10 +955,10 @@ actions_run(struct view *activator, struct server *server, } break; case ACTION_TYPE_NEXT_WINDOW: - start_window_cycling(server, LAB_CYCLE_DIR_FORWARD); + osd_begin(server, LAB_CYCLE_DIR_FORWARD); break; case ACTION_TYPE_PREVIOUS_WINDOW: - start_window_cycling(server, LAB_CYCLE_DIR_BACKWARD); + osd_begin(server, LAB_CYCLE_DIR_BACKWARD); break; case ACTION_TYPE_RECONFIGURE: kill(getpid(), SIGHUP); diff --git a/src/input/keyboard.c b/src/input/keyboard.c index 7460fec5..6ab5fb91 100644 --- a/src/input/keyboard.c +++ b/src/input/keyboard.c @@ -497,10 +497,7 @@ handle_cycle_view_key(struct server *server, struct keyinfo *keyinfo) /* 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, direction); - osd_update(server); + osd_cycle(server, direction); } } diff --git a/src/osd.c b/src/osd.c index 7eb3ad5a..43f051bf 100644 --- a/src/osd.c +++ b/src/osd.c @@ -128,6 +128,43 @@ restore_preview_node(struct server *server) } } +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; +} + +void +osd_begin(struct server *server, enum lab_cycle_dir direction) +{ + if (server->input_mode != LAB_INPUT_STATE_PASSTHROUGH) { + return; + } + + /* 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); + + seat_focus_override_begin(&server->seat, + LAB_INPUT_STATE_WINDOW_SWITCHER, LAB_CURSOR_DEFAULT); + osd_update(server); +} + +void +osd_cycle(struct server *server, enum lab_cycle_dir direction) +{ + assert(server->input_mode == LAB_INPUT_STATE_WINDOW_SWITCHER); + + server->osd_state.cycle_view = desktop_cycle_view(server, + server->osd_state.cycle_view, direction); + osd_update(server); +} + void osd_finish(struct server *server) {