From d7dd366bad842edeea7db885b0c366353620edcd Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Sat, 1 Apr 2023 14:06:52 -0400 Subject: [PATCH] view: Add view_move_to_front/back(). 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 | 2 -- include/view.h | 4 ++++ src/action.c | 4 ++-- src/cursor.c | 25 ++++++++++++++++--------- src/desktop.c | 28 +++------------------------- src/foreign.c | 2 +- src/keyboard.c | 4 +++- src/view-impl-common.c | 2 +- src/view.c | 20 ++++++++++++++++++++ src/xdg.c | 2 +- src/xwayland.c | 2 +- 11 files changed, 52 insertions(+), 43 deletions(-) diff --git a/include/labwc.h b/include/labwc.h index eee3b473..834b1b9a 100644 --- a/include/labwc.h +++ b/include/labwc.h @@ -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); diff --git a/include/view.h b/include/view.h index f3eb0634..d96ccbca 100644 --- a/include/view.h +++ b/include/view.h @@ -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); diff --git a/src/action.c b/src/action.c index f606a924..a6bcfa9a 100644 --- a/src/action.c +++ b/src/action.c @@ -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: diff --git a/src/cursor.c b/src/cursor.c index 7b7c5be8..1a2b0313 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -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) { diff --git a/src/desktop.c b/src/desktop.c index 1e43c382..91c15ce8 100644 --- a/src/desktop.c +++ b/src/desktop.c @@ -12,30 +12,6 @@ #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 diff --git a/src/foreign.c b/src/foreign.c index 9b7c324d..32d09e19 100644 --- a/src/foreign.c +++ b/src/foreign.c @@ -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 diff --git a/src/keyboard.c b/src/keyboard.c index d4d7ff75..f48b6dbc 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -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); diff --git a/src/view-impl-common.c b/src/view-impl-common.c index e4d13f84..98d92529 100644 --- a/src/view-impl-common.c +++ b/src/view-impl-common.c @@ -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); } diff --git a/src/view.c b/src/view.c index bfa0e035..0f728872 100644 --- a/src/view.c +++ b/src/view.c @@ -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) { diff --git a/src/xdg.c b/src/xdg.c index 1c416002..1afc1f22 100644 --- 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); } /* diff --git a/src/xwayland.c b/src/xwayland.c index 1a849513..7029da3c 100644 --- a/src/xwayland.c +++ b/src/xwayland.c @@ -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