]> git.mdlowis.com Git - proto/labwc.git/commitdiff
view: avoid raising same view over and over
authorJohn Lindgren <john@jlindgren.net>
Sat, 21 Oct 2023 15:28:00 +0000 (11:28 -0400)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sat, 21 Oct 2023 20:42:24 +0000 (21:42 +0100)
Since view_move_to_front() now does more work than it used to
(updating XWayland server stacking order), try to avoid doing that
work unnecessarily.

include/labwc.h
src/view-impl-common.c
src/view.c

index bae2dfb9e4bec560bc74c2e0d8e0f8b7910aff69..a870345ed14c391072077e7d01194d14bd870b95 100644 (file)
@@ -238,12 +238,17 @@ struct server {
        struct wlr_box grab_box;
        uint32_t resize_edges;
 
-       /* SSD state */
        /*
         * Currently focused view. Updated with each "focus change"
         * event. This view is drawn with "active" SSD coloring.
         */
        struct view *focused_view;
+       /*
+        * Most recently raised view. Used to avoid unnecessarily
+        * raising the same view over and over.
+        */
+       struct view *last_raised_view;
+
        struct ssd_hover_state *ssd_hover_state;
 
        /* Tree for all non-layer xdg/xwayland-shell surfaces */
index f8bdb3eee19e185a0e83a7f8d0a9a7bc83fa6656..ede58bf1b0566ccff6f8cc9f866d860bfe2ca958 100644 (file)
@@ -55,9 +55,12 @@ view_impl_map(struct view *view)
 void
 view_impl_unmap(struct view *view)
 {
-       struct seat *seat = &view->server->seat;
-       if (seat->seat->keyboard_state.focused_surface == view->surface) {
-               desktop_focus_topmost_view(view->server);
+       struct server *server = view->server;
+       if (view == server->focused_view) {
+               desktop_focus_topmost_view(server);
+       }
+       if (view == server->last_raised_view) {
+               server->last_raised_view = NULL;
        }
 }
 
index 38cac17ebd86cd73bb3d16306d387a81af5984f4..106a2aa7b157d8ee24ee1038df219fd1efec392a 100644 (file)
@@ -1345,6 +1345,7 @@ move_to_front(struct view *view)
        if (view->impl->move_to_front) {
                view->impl->move_to_front(view);
        }
+       view->server->last_raised_view = view;
 }
 
 static void
@@ -1353,6 +1354,9 @@ move_to_back(struct view *view)
        if (view->impl->move_to_back) {
                view->impl->move_to_back(view);
        }
+       if (view == view->server->last_raised_view) {
+               view->server->last_raised_view = NULL;
+       }
 }
 
 /*
@@ -1365,6 +1369,17 @@ void
 view_move_to_front(struct view *view)
 {
        assert(view);
+       /*
+        * This function is called often, generally on every mouse
+        * button press (more often for focus-follows-mouse). Avoid
+        * unnecessarily raising the same view over and over, or
+        * attempting to raise a root view above its own sub-view.
+        */
+       struct view *last = view->server->last_raised_view;
+       if (view == last || (last && view == view_get_root(last))) {
+               return;
+       }
+
        struct view *root = view_get_root(view);
        assert(root);
 
@@ -1517,6 +1532,10 @@ view_destroy(struct view *view)
                need_cursor_update = true;
        }
 
+       if (server->last_raised_view == view) {
+               server->last_raised_view = NULL;
+       }
+
        if (server->seat.pressed.view == view) {
                seat_reset_pressed(&server->seat);
        }