From 625127d5d376848fae4dc12eec5b2225d1a0ca3a Mon Sep 17 00:00:00 2001 From: ookami Date: Wed, 13 Nov 2024 16:02:04 +0800 Subject: [PATCH 1/2] Fix cursor events on lock/unlock See https://github.com/labwc/labwc/pull/1858 Delay refocus operations because only the role-specific surface commit/map handler has been processed in wlroots at this moment and node_at_coords returns the WLR_SCENE_NODE_RECT as a buffer has not been actually attached to the surface. --- sway/lock.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sway/lock.c b/sway/lock.c index 43f313308..168d469a1 100644 --- a/sway/lock.c +++ b/sway/lock.c @@ -59,7 +59,8 @@ static void refocus_output(struct sway_session_lock_output *output) { } } -static void handle_surface_map(struct wl_listener *listener, void *data) { +static void update_focus(void *data) { + struct wl_listener *listener = data; struct sway_session_lock_output *surf = wl_container_of(listener, surf, surface_map); if (surf->lock->focused == NULL) { focus_surface(surf->lock, surf->surface->surface); @@ -67,6 +68,10 @@ static void handle_surface_map(struct wl_listener *listener, void *data) { cursor_rebase_all(); } +static void handle_surface_map(struct wl_listener *listener, void *data) { + wl_event_loop_add_idle(server.wl_event_loop, update_focus, listener); +} + static void handle_surface_destroy(struct wl_listener *listener, void *data) { struct sway_session_lock_output *output = wl_container_of(listener, output, surface_destroy); @@ -234,6 +239,7 @@ static void handle_unlock(struct wl_listener *listener, void *data) { struct sway_output *output = root->outputs->items[i]; arrange_layers(output); } + cursor_rebase_all(); } static void handle_abandon(struct wl_listener *listener, void *data) { From 97c2204a1a901cea2ee9309ce91c77361e80272e Mon Sep 17 00:00:00 2001 From: ookami Date: Sun, 17 Nov 2024 03:15:14 +0800 Subject: [PATCH 2/2] Fix sway_session_lock_has_surface Before this commit, if the cursor is at screen center, and the lock is swaylock, the cursor would be at swaylock's subsurface(the indicator). Since it's not the lock surface, `handle_rebase` would refuse to rebase the cursor to there. Thereby the cursor enter event won't be sent to swaylock. This commit fix the issue. --- sway/lock.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/sway/lock.c b/sway/lock.c index 168d469a1..4b6c7bded 100644 --- a/sway/lock.c +++ b/sway/lock.c @@ -331,11 +331,31 @@ void sway_session_lock_add_output(struct sway_session_lock *lock, } } +struct is_lock_surface_data { + struct wlr_surface *surface; + bool is_lock_surface; +}; + +static void is_lock_surface(struct wlr_surface *surface, int sx, int sy, void *data) { + struct is_lock_surface_data *is_lock_surface_data = data; + if (is_lock_surface_data->surface == surface) { + is_lock_surface_data->is_lock_surface = true; + } +} + bool sway_session_lock_has_surface(struct sway_session_lock *lock, struct wlr_surface *surface) { struct sway_session_lock_output *lock_output; wl_list_for_each(lock_output, &lock->outputs, link) { - if (lock_output->surface && lock_output->surface->surface == surface) { + if (!lock_output->surface) { + continue; + } + struct is_lock_surface_data data = { + .surface = surface, + .is_lock_surface = false, + }; + wlr_surface_for_each_surface(lock_output->surface->surface, is_lock_surface, &data); + if (data.is_lock_surface) { return true; } }