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

@ -338,6 +338,7 @@ void desktop_focus_view(struct seat *seat, struct view *view);
*/ */
struct view *desktop_cycle_view(struct server *server, struct view *current); struct view *desktop_cycle_view(struct server *server, struct view *current);
struct view *topmost_mapped_view(struct server *server); struct view *topmost_mapped_view(struct server *server);
struct view *focused_view(struct server *server);
void desktop_focus_topmost_mapped_view(struct server *server); void desktop_focus_topmost_mapped_view(struct server *server);
bool isfocusable(struct view *view); bool isfocusable(struct view *view);

View file

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

View file

@ -212,6 +212,25 @@ topmost_mapped_view(struct server *server)
return view; 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 void
desktop_focus_topmost_mapped_view(struct server *server) desktop_focus_topmost_mapped_view(struct server *server)
{ {