osd: refactor to not write server->osd_state outside osd.c

This commit is contained in:
tokyo4j 2024-12-30 01:05:17 +09:00 committed by Hiroaki Yamamoto
parent 8f8e734405
commit 6fe688b3e4
4 changed files with 47 additions and 33 deletions

View file

@ -36,6 +36,13 @@ struct window_switcher_field {
struct buf; struct buf;
struct view; struct view;
struct server; 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 */ /* Updates onscreen display 'alt-tab' buffer */
void osd_update(struct server *server); void osd_update(struct server *server);

View file

@ -789,33 +789,6 @@ run_if_action(struct view *view, struct server *server, struct action *action)
return !strcmp(branch, "then"); 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 * static struct output *
get_target_output(struct output *output, struct server *server, get_target_output(struct output *output, struct server *server,
struct action *action) struct action *action)
@ -982,10 +955,10 @@ actions_run(struct view *activator, struct server *server,
} }
break; break;
case ACTION_TYPE_NEXT_WINDOW: case ACTION_TYPE_NEXT_WINDOW:
start_window_cycling(server, LAB_CYCLE_DIR_FORWARD); osd_begin(server, LAB_CYCLE_DIR_FORWARD);
break; break;
case ACTION_TYPE_PREVIOUS_WINDOW: case ACTION_TYPE_PREVIOUS_WINDOW:
start_window_cycling(server, LAB_CYCLE_DIR_BACKWARD); osd_begin(server, LAB_CYCLE_DIR_BACKWARD);
break; break;
case ACTION_TYPE_RECONFIGURE: case ACTION_TYPE_RECONFIGURE:
kill(getpid(), SIGHUP); kill(getpid(), SIGHUP);

View file

@ -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 */ /* Only one direction modifier is allowed, either arrow keys OR shift */
miss_shift_toggle: miss_shift_toggle:
osd_cycle(server, direction);
server->osd_state.cycle_view = desktop_cycle_view(server,
server->osd_state.cycle_view, direction);
osd_update(server);
} }
} }

View file

@ -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 void
osd_finish(struct server *server) osd_finish(struct server *server)
{ {