define focused_view function and use it for keyboard actions

This commit is contained in:
bi4k8 2021-09-19 22:20:54 +00:00 committed by Johan Malm
parent a15a56bfe1
commit 815cd4aa46
3 changed files with 26 additions and 6 deletions

View file

@ -24,7 +24,7 @@ action(struct server *server, const char *action, const char *command)
if (!action)
return;
if (!strcasecmp(action, "Close")) {
struct view *view = topmost_mapped_view(server);
struct view *view = focused_view(server);
if (view) {
view->impl->close(view);
}
@ -40,7 +40,7 @@ action(struct server *server, const char *action, const char *command)
} else if (!strcasecmp(action, "Exit")) {
wl_display_terminate(server->wl_display);
} else if (!strcasecmp(action, "MoveToEdge")) {
view_move_to_edge(topmost_mapped_view(server), command);
view_move_to_edge(focused_view(server), command);
} else if (!strcasecmp(action, "NextWindow")) {
server->cycle_view =
desktop_cycle_view(server, server->cycle_view);
@ -50,22 +50,22 @@ action(struct server *server, const char *action, const char *command)
} else if (!strcasecmp(action, "ShowMenu")) {
show_menu(server, command);
} else if (!strcasecmp(action, "ToggleMaximize")) {
struct view *view = topmost_mapped_view(server);
struct view *view = focused_view(server);
if (view) {
view_toggle_maximize(view);
}
} else if (!strcasecmp(action, "ToggleFullscreen")) {
struct view *view = topmost_mapped_view(server);
struct view *view = focused_view(server);
if (view) {
view_toggle_fullscreen(view);
}
} else if (!strcasecmp(action, "ToggleDecorations")) {
struct view *view = topmost_mapped_view(server);
struct view *view = focused_view(server);
if (view) {
view_toggle_decorations(view);
}
} else if (!strcasecmp(action, "Iconify")) {
struct view *view = topmost_mapped_view(server);
struct view *view = focused_view(server);
if (view) {
view_minimize(view, true);
}

View file

@ -212,6 +212,25 @@ topmost_mapped_view(struct server *server)
return view;
}
struct view *
focused_view(struct server *server)
{
struct seat *seat = &server->seat;
struct wlr_surface *focused_surface;
focused_surface = seat->seat->keyboard_state.focused_surface;
if (!focused_surface) {
return NULL;
}
struct view *view;
wl_list_for_each (view, &server->views, link) {
if (view->surface == focused_surface) {
return view;
}
}
return NULL;
}
void
desktop_focus_topmost_mapped_view(struct server *server)
{