]> git.mdlowis.com Git - proto/labwc.git/commitdiff
view: Add view_move_to_front/back().
authorJohn Lindgren <john@jlindgren.net>
Sat, 1 Apr 2023 18:06:52 +0000 (14:06 -0400)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Sat, 1 Apr 2023 20:50:01 +0000 (22:50 +0200)
This avoids calling view->impl functions from cursor.c and desktop.c.

v2: Add an explicit recursion guard in cursor_update_focus().

include/labwc.h
include/view.h
src/action.c
src/cursor.c
src/desktop.c
src/foreign.c
src/keyboard.c
src/view-impl-common.c
src/view.c
src/xdg.c
src/xwayland.c

index eee3b47367bbf37d4bc8c87b6dac825390b6e019..834b1b9a1a21a628479144801a83a3f4e8fa647c 100644 (file)
@@ -367,8 +367,6 @@ void foreign_toplevel_update_outputs(struct view *view);
  *              cannot assume this means that the window actually has keyboard
  *              or pointer focus, in this compositor are they called together.
  */
-void desktop_move_to_front(struct view *view);
-void desktop_move_to_back(struct view *view);
 void desktop_focus_and_activate_view(struct seat *seat, struct view *view);
 void desktop_arrange_all_views(struct server *server);
 void desktop_focus_output(struct output *output);
index f3eb0634b797b8c522038c9aed4f81db110bd752..d96ccbcaf16f1b71ad6e375faf64461ef5c1fbc8 100644 (file)
@@ -184,6 +184,10 @@ void view_snap_to_edge(struct view *view, const char *direction,
        bool store_natural_geometry);
 void view_snap_to_region(struct view *view, struct region *region,
        bool store_natural_geometry);
+
+void view_move_to_front(struct view *view);
+void view_move_to_back(struct view *view);
+
 const char *view_get_string_prop(struct view *view, const char *prop);
 void view_update_title(struct view *view);
 void view_update_app_id(struct view *view);
index f606a92439876c46284d8cb23dd39fac5aa83fa9..a6bcfa9ae513399e42a37f5b7170cefcff2b0cb0 100644 (file)
@@ -439,12 +439,12 @@ actions_run(struct view *activator, struct server *server,
                        break;
                case ACTION_TYPE_RAISE:
                        if (view) {
-                               desktop_move_to_front(view);
+                               view_move_to_front(view);
                        }
                        break;
                case ACTION_TYPE_LOWER:
                        if (view) {
-                               desktop_move_to_back(view);
+                               view_move_to_back(view);
                        }
                        break;
                case ACTION_TYPE_RESIZE:
index 7b7c5be84c8ffea8d2f3cf31aab7bce27451735c..1a2b031376d81e508e0101750774ac859e30bbde 100644 (file)
@@ -481,7 +481,7 @@ process_cursor_motion(struct server *server, uint32_t time)
        if (ctx.view && rc.focus_follow_mouse) {
                desktop_focus_and_activate_view(seat, ctx.view);
                if (rc.raise_on_focus) {
-                       desktop_move_to_front(ctx.view);
+                       view_move_to_front(ctx.view);
                }
        }
 
@@ -510,8 +510,8 @@ msec(const struct timespec *t)
        return t->tv_sec * 1000 + t->tv_nsec / 1000000;
 }
 
-void
-cursor_update_focus(struct server *server)
+static void
+_cursor_update_focus(struct server *server)
 {
        struct timespec now;
        clock_gettime(CLOCK_MONOTONIC, &now);
@@ -523,12 +523,7 @@ cursor_update_focus(struct server *server)
                /* Prevent changing keyboard focus during A-Tab */
                desktop_focus_and_activate_view(&server->seat, ctx.view);
                if (rc.raise_on_focus) {
-                       /*
-                        * Call view method directly as desktop_move_to_front()
-                        * contains a call to cursor_update_focus() and thus
-                        * loops inifinitely
-                        */
-                       ctx.view->impl->move_to_front(ctx.view);
+                       view_move_to_front(ctx.view);
                }
        }
 
@@ -536,6 +531,18 @@ cursor_update_focus(struct server *server)
                /*cursor_has_moved*/ false);
 }
 
+void
+cursor_update_focus(struct server *server)
+{
+       /* Prevent recursion via view_move_to_front() */
+       static bool updating_focus = false;
+       if (!updating_focus) {
+               updating_focus = true;
+               _cursor_update_focus(server);
+               updating_focus = false;
+       }
+}
+
 static void
 handle_constraint_commit(struct wl_listener *listener, void *data)
 {
index 1e43c382f4a3644ceab4adb1ffe9961906a5be92..91c15ce8c8a75b99c721bc95dabd6e8de1d61a1f 100644 (file)
 #include "workspaces.h"
 #include "xwayland.h"
 
-void
-desktop_move_to_front(struct view *view)
-{
-       if (!view) {
-               return;
-       }
-       if (view->impl->move_to_front) {
-               view->impl->move_to_front(view);
-               cursor_update_focus(view->server);
-       }
-}
-
-void
-desktop_move_to_back(struct view *view)
-{
-       if (!view) {
-               return;
-       }
-       if (view->impl->move_to_back) {
-               view->impl->move_to_back(view);
-               cursor_update_focus(view->server);
-       }
-}
-
 void
 desktop_arrange_all_views(struct server *server)
 {
@@ -267,7 +243,9 @@ desktop_focus_topmost_mapped_view(struct server *server)
 {
        struct view *view = topmost_mapped_view(server);
        desktop_focus_and_activate_view(&server->seat, view);
-       desktop_move_to_front(view);
+       if (view) {
+               view_move_to_front(view);
+       }
 }
 
 void
index 9b7c324d6cef99e89f2750e43818fbb916aecbb8..32d09e1985058b1b83433fc304e2af5836ef9871 100644 (file)
@@ -38,7 +38,7 @@ handle_request_activate(struct wl_listener *listener, void *data)
                workspaces_switch_to(view->workspace);
        }
        desktop_focus_and_activate_view(&view->server->seat, view);
-       desktop_move_to_front(view);
+       view_move_to_front(view);
 }
 
 static void
index d4d7ff75dba62d6f536cc5cfa3d1e6998ebd8510..f48b6dbce47883449066f62f5ad16d840306b9c7 100644 (file)
@@ -40,7 +40,9 @@ static void
 end_cycling(struct server *server)
 {
        desktop_focus_and_activate_view(&server->seat, server->osd_state.cycle_view);
-       desktop_move_to_front(server->osd_state.cycle_view);
+       if (server->osd_state.cycle_view) {
+               view_move_to_front(server->osd_state.cycle_view);
+       }
 
        /* osd_finish() additionally resets cycle_view to NULL */
        osd_finish(server);
index e4d13f840209e5b812d56a38b753c69a54b6ae46..98d92529e12801f21bbda33fad046c49b50c2ead 100644 (file)
@@ -27,7 +27,7 @@ void
 view_impl_map(struct view *view)
 {
        desktop_focus_and_activate_view(&view->server->seat, view);
-       desktop_move_to_front(view);
+       view_move_to_front(view);
        view_update_title(view);
        view_update_app_id(view);
 }
index bfa0e035e3ea34c7f8b704c54ddba82d20e8d293..0f72887273c2509ffdc7453498a93a0b8df54414 100644 (file)
@@ -982,6 +982,26 @@ view_snap_to_region(struct view *view, struct region *region,
        view_apply_region_geometry(view);
 }
 
+void
+view_move_to_front(struct view *view)
+{
+       assert(view);
+       if (view->impl->move_to_front) {
+               view->impl->move_to_front(view);
+               cursor_update_focus(view->server);
+       }
+}
+
+void
+view_move_to_back(struct view *view)
+{
+       assert(view);
+       if (view->impl->move_to_back) {
+               view->impl->move_to_back(view);
+               cursor_update_focus(view->server);
+       }
+}
+
 const char *
 view_get_string_prop(struct view *view, const char *prop)
 {
index 1c4160029ed757646b26cbb4caf8fe786d7536ee..1afc1f227376d6dac4293e38ae9d4d9ef851fe10 100644 (file)
--- a/src/xdg.c
+++ b/src/xdg.c
@@ -495,7 +495,7 @@ xdg_activation_handle_request(struct wl_listener *listener, void *data)
                workspaces_switch_to(view->workspace);
        }
        desktop_focus_and_activate_view(&view->server->seat, view);
-       desktop_move_to_front(view);
+       view_move_to_front(view);
 }
 
 /*
index 1a849513f51559adb2fa12e06094c7e7d24c6e00..7029da3cdac53235150ac925188c8afd5136b6f9 100644 (file)
@@ -270,7 +270,7 @@ handle_request_activate(struct wl_listener *listener, void *data)
                wl_container_of(listener, xwayland_view, request_activate);
        struct view *view = &xwayland_view->base;
        desktop_focus_and_activate_view(&view->server->seat, view);
-       desktop_move_to_front(view);
+       view_move_to_front(view);
 }
 
 static void