action: If we have a view that is an activator, use that instead of the current focus window

If we don't switch focus, we want the close button to close the window associated with it, not the current focus window.

Signed-off-by: Joshua Ashton <joshua@froggi.es>
This commit is contained in:
Joshua Ashton 2021-12-03 16:37:53 +00:00 committed by Johan Malm
parent f9f9d809c8
commit d568c60003
5 changed files with 26 additions and 20 deletions

View file

@ -19,13 +19,19 @@ show_menu(struct server *server, const char *menu)
damage_all_outputs(server);
}
static struct view *
activator_or_focused_view(struct view *activator, struct server *server)
{
return activator ? activator : desktop_focused_view(server);
}
void
action(struct server *server, const char *action, const char *command, uint32_t resize_edges)
action(struct view *activator, struct server *server, const char *action, const char *command, uint32_t resize_edges)
{
if (!action)
return;
if (!strcasecmp(action, "Close")) {
struct view *view = desktop_focused_view(server);
struct view *view = activator_or_focused_view(activator, server);
if (view) {
view->impl->close(view);
}
@ -41,9 +47,9 @@ action(struct server *server, const char *action, const char *command, uint32_t
} else if (!strcasecmp(action, "Exit")) {
wl_display_terminate(server->wl_display);
} else if (!strcasecmp(action, "MoveToEdge")) {
view_move_to_edge(desktop_focused_view(server), command);
view_move_to_edge(activator_or_focused_view(activator, server), command);
} else if (!strcasecmp(action, "SnapToEdge")) {
view_snap_to_edge(desktop_focused_view(server), command);
view_snap_to_edge(activator_or_focused_view(activator, server), command);
} else if (!strcasecmp(action, "NextWindow")) {
server->cycle_view =
desktop_cycle_view(server, server->cycle_view, LAB_CYCLE_DIR_NONE);
@ -53,17 +59,17 @@ action(struct server *server, const char *action, const char *command, uint32_t
} else if (!strcasecmp(action, "ShowMenu")) {
show_menu(server, command);
} else if (!strcasecmp(action, "ToggleMaximize")) {
struct view *view = desktop_focused_view(server);
struct view *view = activator_or_focused_view(activator, server);
if (view) {
view_toggle_maximize(view);
}
} else if (!strcasecmp(action, "ToggleFullscreen")) {
struct view *view = desktop_focused_view(server);
struct view *view = activator_or_focused_view(activator, server);
if (view) {
view_toggle_fullscreen(view);
}
} else if (!strcasecmp(action, "ToggleDecorations")) {
struct view *view = desktop_focused_view(server);
struct view *view = activator_or_focused_view(activator, server);
if (view) {
view_toggle_decorations(view);
}
@ -74,7 +80,7 @@ action(struct server *server, const char *action, const char *command, uint32_t
damage_all_outputs(server);
}
} else if (!strcasecmp(action, "Iconify")) {
struct view *view = desktop_focused_view(server);
struct view *view = activator_or_focused_view(activator, server);
if (view) {
view_minimize(view, true);
}
@ -84,7 +90,7 @@ action(struct server *server, const char *action, const char *command, uint32_t
interactive_begin(view, LAB_INPUT_STATE_MOVE, 0);
}
} else if (!strcasecmp(action, "Raise")) {
struct view *view = desktop_focused_view(server);
struct view *view = activator_or_focused_view(activator, server);
if (view) {
desktop_raise_view(view);
damage_all_outputs(server);