action.c: split actions_run()

This commit is contained in:
tokyo4j 2025-08-01 16:06:58 +09:00 committed by Johan Malm
parent 6c50a62817
commit 15e3c32b5b

View file

@ -862,42 +862,10 @@ warp_cursor(struct server *server, struct view *view, const char *to, const char
cursor_update_focus(server); cursor_update_focus(server);
} }
void static void
actions_run(struct view *activator, struct server *server, run_action(struct view *view, struct server *server, struct action *action,
struct wl_list *actions, struct cursor_context *cursor_ctx) struct cursor_context *ctx)
{ {
if (!actions) {
wlr_log(WLR_ERROR, "empty actions");
return;
}
/* This cancels any pending on-release keybinds */
keyboard_reset_current_keybind();
struct cursor_context ctx = {0};
if (cursor_ctx) {
ctx = *cursor_ctx;
}
struct action *action;
wl_list_for_each(action, actions, link) {
if (server->input_mode == LAB_INPUT_STATE_WINDOW_SWITCHER
&& action->type != ACTION_TYPE_NEXT_WINDOW
&& action->type != ACTION_TYPE_PREVIOUS_WINDOW) {
wlr_log(WLR_INFO, "Only NextWindow or PreviousWindow "
"actions are accepted while window switching.");
continue;
}
wlr_log(WLR_DEBUG, "Handling action %u: %s", action->type,
action_names[action->type]);
/*
* Refetch view because it may have been changed due to the
* previous action
*/
struct view *view = view_for_action(activator, server, action, &ctx);
switch (action->type) { switch (action->type) {
case ACTION_TYPE_CLOSE: case ACTION_TYPE_CLOSE:
if (view) { if (view) {
@ -989,7 +957,7 @@ actions_run(struct view *activator, struct server *server,
kill(getpid(), SIGHUP); kill(getpid(), SIGHUP);
break; break;
case ACTION_TYPE_SHOW_MENU: case ACTION_TYPE_SHOW_MENU:
show_menu(server, view, &ctx, show_menu(server, view, ctx,
action_get_str(action, "menu", NULL), action_get_str(action, "menu", NULL),
action_get_bool(action, "atCursor", true), action_get_bool(action, "atCursor", true),
action_get_str(action, "x.position", NULL), action_get_str(action, "x.position", NULL),
@ -1083,7 +1051,7 @@ actions_run(struct view *activator, struct server *server,
case ACTION_TYPE_RESIZE: case ACTION_TYPE_RESIZE:
if (view) { if (view) {
uint32_t resize_edges = cursor_get_resize_edges( uint32_t resize_edges = cursor_get_resize_edges(
server->seat.cursor, &ctx); server->seat.cursor, ctx);
interactive_begin(view, LAB_INPUT_STATE_RESIZE, interactive_begin(view, LAB_INPUT_STATE_RESIZE,
resize_edges); resize_edges);
} }
@ -1374,5 +1342,44 @@ actions_run(struct view *activator, struct server *server,
"Not executing invalid action (%u)" "Not executing invalid action (%u)"
" This is a BUG. Please report.", action->type); " This is a BUG. Please report.", action->type);
} }
}
void
actions_run(struct view *activator, struct server *server,
struct wl_list *actions, struct cursor_context *cursor_ctx)
{
if (!actions) {
wlr_log(WLR_ERROR, "empty actions");
return;
}
/* This cancels any pending on-release keybinds */
keyboard_reset_current_keybind();
struct cursor_context ctx = {0};
if (cursor_ctx) {
ctx = *cursor_ctx;
}
struct action *action;
wl_list_for_each(action, actions, link) {
if (server->input_mode == LAB_INPUT_STATE_WINDOW_SWITCHER
&& action->type != ACTION_TYPE_NEXT_WINDOW
&& action->type != ACTION_TYPE_PREVIOUS_WINDOW) {
wlr_log(WLR_INFO, "Only NextWindow or PreviousWindow "
"actions are accepted while window switching.");
continue;
}
wlr_log(WLR_DEBUG, "Handling action %u: %s", action->type,
action_names[action->type]);
/*
* Refetch view because it may have been changed due to the
* previous action
*/
struct view *view = view_for_action(activator, server, action, &ctx);
run_action(view, server, action, &ctx);
} }
} }