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.
This commit is contained in:
John Lindgren 2023-10-21 11:28:00 -04:00 committed by Johan Malm
parent 0ddf3c43ad
commit db591d1400
3 changed files with 31 additions and 4 deletions

View file

@ -238,12 +238,17 @@ struct server {
struct wlr_box grab_box; struct wlr_box grab_box;
uint32_t resize_edges; uint32_t resize_edges;
/* SSD state */
/* /*
* Currently focused view. Updated with each "focus change" * Currently focused view. Updated with each "focus change"
* event. This view is drawn with "active" SSD coloring. * event. This view is drawn with "active" SSD coloring.
*/ */
struct view *focused_view; 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; struct ssd_hover_state *ssd_hover_state;
/* Tree for all non-layer xdg/xwayland-shell surfaces */ /* Tree for all non-layer xdg/xwayland-shell surfaces */

View file

@ -55,9 +55,12 @@ view_impl_map(struct view *view)
void void
view_impl_unmap(struct view *view) view_impl_unmap(struct view *view)
{ {
struct seat *seat = &view->server->seat; struct server *server = view->server;
if (seat->seat->keyboard_state.focused_surface == view->surface) { if (view == server->focused_view) {
desktop_focus_topmost_view(view->server); desktop_focus_topmost_view(server);
}
if (view == server->last_raised_view) {
server->last_raised_view = NULL;
} }
} }

View file

@ -1345,6 +1345,7 @@ move_to_front(struct view *view)
if (view->impl->move_to_front) { if (view->impl->move_to_front) {
view->impl->move_to_front(view); view->impl->move_to_front(view);
} }
view->server->last_raised_view = view;
} }
static void static void
@ -1353,6 +1354,9 @@ move_to_back(struct view *view)
if (view->impl->move_to_back) { if (view->impl->move_to_back) {
view->impl->move_to_back(view); 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) view_move_to_front(struct view *view)
{ {
assert(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); struct view *root = view_get_root(view);
assert(root); assert(root);
@ -1517,6 +1532,10 @@ view_destroy(struct view *view)
need_cursor_update = true; need_cursor_update = true;
} }
if (server->last_raised_view == view) {
server->last_raised_view = NULL;
}
if (server->seat.pressed.view == view) { if (server->seat.pressed.view == view) {
seat_reset_pressed(&server->seat); seat_reset_pressed(&server->seat);
} }