From db591d1400d275e836a80dfaa2b2ef5b9b57bc64 Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Sat, 21 Oct 2023 11:28:00 -0400 Subject: [PATCH] view: avoid raising same view over and over 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 | 7 ++++++- src/view-impl-common.c | 9 ++++++--- src/view.c | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/include/labwc.h b/include/labwc.h index bae2dfb9..a870345e 100644 --- a/include/labwc.h +++ b/include/labwc.h @@ -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 */ diff --git a/src/view-impl-common.c b/src/view-impl-common.c index f8bdb3ee..ede58bf1 100644 --- a/src/view-impl-common.c +++ b/src/view-impl-common.c @@ -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; } } diff --git a/src/view.c b/src/view.c index 38cac17e..106a2aa7 100644 --- a/src/view.c +++ b/src/view.c @@ -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); } -- 2.52.0