From d00711bc454851cdf7137552d0fb1cccf71f7abc Mon Sep 17 00:00:00 2001 From: tokyo4j Date: Thu, 30 May 2024 00:53:52 +0900 Subject: [PATCH] session-lock: allow client to update cursor shape --- include/node.h | 1 + src/desktop.c | 1 + src/session-lock.c | 29 +++++++++++++++++++++++++---- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/include/node.h b/include/node.h index d0a41c71..538fc98f 100644 --- a/include/node.h +++ b/include/node.h @@ -15,6 +15,7 @@ enum node_descriptor_type { LAB_NODE_DESC_XDG_POPUP, LAB_NODE_DESC_LAYER_SURFACE, LAB_NODE_DESC_LAYER_POPUP, + LAB_NODE_DESC_SESSION_LOCK_SURFACE, LAB_NODE_DESC_IME_POPUP, LAB_NODE_DESC_MENUITEM, LAB_NODE_DESC_TREE, diff --git a/src/desktop.c b/src/desktop.c index 58f87a1f..2c0db207 100644 --- a/src/desktop.c +++ b/src/desktop.c @@ -336,6 +336,7 @@ get_cursor_context(struct server *server) ret.type = LAB_SSD_CLIENT; ret.surface = get_surface_from_layer_node(node); return ret; + case LAB_NODE_DESC_SESSION_LOCK_SURFACE: /* fallthrough */ case LAB_NODE_DESC_IME_POPUP: ret.type = LAB_SSD_CLIENT; ret.surface = lab_wlr_surface_from_node(ret.node); diff --git a/src/session-lock.c b/src/session-lock.c index d9968f08..72db111f 100644 --- a/src/session-lock.c +++ b/src/session-lock.c @@ -3,6 +3,7 @@ #include #include "common/mem.h" #include "labwc.h" +#include "node.h" struct session_lock_output { struct wlr_scene_tree *tree; @@ -49,15 +50,31 @@ refocus_output(struct session_lock_output *output) } static void -handle_surface_map(struct wl_listener *listener, void *data) +update_focus(void *data) { - struct session_lock_output *output = - wl_container_of(listener, output, surface_map); + struct session_lock_output *output = data; + cursor_update_focus(output->manager->server); if (!output->manager->focused) { focus_surface(output->manager, output->surface->surface); } } +static void +handle_surface_map(struct wl_listener *listener, void *data) +{ + struct session_lock_output *output = + wl_container_of(listener, output, surface_map); + /* + * In order to update cursor shape on map, the call to + * cursor_update_focus() should be delayed because only the + * role-specific surface commit/map handler has been processed in + * wlroots at this moment and get_cursor_context() returns NULL as a + * buffer has not been actually attached to the surface. + */ + wl_event_loop_add_idle( + output->manager->server->wl_event_loop, update_focus, output); +} + static void handle_surface_destroy(struct wl_listener *listener, void *data) { @@ -103,7 +120,10 @@ handle_new_surface(struct wl_listener *listener, void *data) found_lock_output: lock_output->surface = lock_surface; - wlr_scene_subsurface_tree_create(lock_output->tree, lock_surface->surface); + struct wlr_scene_tree *surface_tree = + wlr_scene_subsurface_tree_create(lock_output->tree, lock_surface->surface); + node_descriptor_create(&surface_tree->node, + LAB_NODE_DESC_SESSION_LOCK_SURFACE, NULL); lock_output->surface_destroy.notify = handle_surface_destroy; wl_signal_add(&lock_surface->events.destroy, &lock_output->surface_destroy); @@ -247,6 +267,7 @@ handle_lock_unlock(struct wl_listener *listener, void *data) session_lock_destroy(manager); manager->locked = false; desktop_focus_topmost_view(manager->server); + cursor_update_focus(manager->server); } static void -- 2.52.0