]> git.mdlowis.com Git - proto/labwc.git/commitdiff
define focused_view function and use it for keyboard actions
authorbi4k8 <bi4k8@github>
Sun, 19 Sep 2021 22:20:54 +0000 (22:20 +0000)
committerJohan Malm <johanmalm@users.noreply.github.com>
Mon, 20 Sep 2021 20:14:24 +0000 (21:14 +0100)
include/labwc.h
src/action.c
src/desktop.c

index a0284e143ae6511e52a3ef8ac7db77d1c9868d89..84b90e665b57b6794379942807cf7d95ca8285c7 100644 (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 *topmost_mapped_view(struct server *server);
+struct view *focused_view(struct server *server);
 void desktop_focus_topmost_mapped_view(struct server *server);
 bool isfocusable(struct view *view);
 
index c1ed2172a3bc6b2757321a170478a6765e1b4e59..3f1f1d343bdf5b5cca0779a8d323d954d18258dd 100644 (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);
                }
index ad3edcdac2003980d22dac9822449fcde7b5bd2d..ca8b99e26364afbd181c2d868eef9603385a3357 100644 (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)
 {