From d51d9cc6d6b6c7346bb96228e9e7a36c50697b3f Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 10 Aug 2021 11:40:54 +0200 Subject: [PATCH] Replace view_wlr_surface_at with scene-graph --- seat.c | 52 +++++++++++++++++++++------------------------------- view.c | 7 +------ view.h | 2 -- xdg_shell.c | 8 -------- xwayland.c | 7 ------- 5 files changed, 22 insertions(+), 54 deletions(-) diff --git a/seat.c b/seat.c index 0ac976c..3366351 100644 --- a/seat.c +++ b/seat.c @@ -8,6 +8,7 @@ #include "config.h" +#include #include #include #include @@ -42,42 +43,31 @@ static void drag_icon_update_position(struct cg_drag_icon *drag_icon); * menus or tooltips. This function tests if any of those are underneath the * coordinates lx and ly (in output Layout Coordinates). If so, it sets the * surface pointer to that wlr_surface and the sx and sy coordinates to the - * coordinates relative to that surface's top-left corner. */ -static bool -view_at(struct cg_view *view, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) -{ - double view_sx = lx - view->lx; - double view_sy = ly - view->ly; - - double _sx, _sy; - struct wlr_surface *_surface = view_wlr_surface_at(view, view_sx, view_sy, &_sx, &_sy); - if (_surface != NULL) { - *sx = _sx; - *sy = _sy; - *surface = _surface; - return true; - } - - return false; -} - -/* This iterates over all of our surfaces and attempts to find one - * under the cursor. This relies on server->views being ordered from - * top-to-bottom. If desktop_view_at returns a view, there is also a - * surface. There cannot be a surface without a view, either. It's - * both or nothing. */ + * coordinates relative to that surface's top-left corner. + * + * This function iterates over all of our surfaces and attempts to find one + * under the cursor. If desktop_view_at returns a view, there is also a + * surface. There cannot be a surface without a view, either. It's both or + * nothing. + */ static struct cg_view * desktop_view_at(struct cg_server *server, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { - struct cg_view *view; - - wl_list_for_each (view, &server->views, link) { - if (view_at(view, lx, ly, surface, sx, sy)) { - return view; - } + struct wlr_scene_node *node = wlr_scene_node_at(&server->scene->node, lx, ly, sx, sy); + if (node == NULL || node->type != WLR_SCENE_NODE_SURFACE) { + return NULL; } - return NULL; + *surface = wlr_scene_surface_from_node(node)->surface; + + /* Walk up the tree until we find a node with a data pointer. When done, + * we've found the node representing the view. */ + while (node != NULL && node->data == NULL) { + node = node->parent; + } + assert(node != NULL); + + return node->data; } static void diff --git a/view.c b/view.c index 70af974..faf4fe7 100644 --- a/view.c +++ b/view.c @@ -231,6 +231,7 @@ view_map(struct cg_view *view, struct wlr_surface *surface) wl_resource_post_no_memory(surface->resource); return; } + view->scene_surface->node.data = view; struct wlr_subsurface *subsurface; wl_list_for_each (subsurface, &view->wlr_surface->current.subsurfaces_below, current.link) { @@ -296,9 +297,3 @@ view_from_wlr_surface(struct cg_server *server, struct wlr_surface *surface) } return NULL; } - -struct wlr_surface * -view_wlr_surface_at(struct cg_view *view, double sx, double sy, double *sub_x, double *sub_y) -{ - return view->impl->wlr_surface_at(view, sx, sy, sub_x, sub_y); -} diff --git a/view.h b/view.h index a0be53d..3c0da5b 100644 --- a/view.h +++ b/view.h @@ -45,7 +45,6 @@ struct cg_view_impl { void (*activate)(struct cg_view *view, bool activate); void (*maximize)(struct cg_view *view, int output_width, int output_height); void (*destroy)(struct cg_view *view); - struct wlr_surface *(*wlr_surface_at)(struct cg_view *view, double sx, double sy, double *sub_x, double *sub_y); }; struct cg_view_child { @@ -79,7 +78,6 @@ void view_destroy(struct cg_view *view); void view_init(struct cg_view *view, struct cg_server *server, enum cg_view_type type, const struct cg_view_impl *impl); struct cg_view *view_from_wlr_surface(struct cg_server *server, struct wlr_surface *surface); -struct wlr_surface *view_wlr_surface_at(struct cg_view *view, double sx, double sy, double *sub_x, double *sub_y); void view_child_finish(struct cg_view_child *child); void view_child_init(struct cg_view_child *child, struct cg_view *view, struct wlr_surface *wlr_surface); diff --git a/xdg_shell.c b/xdg_shell.c index efb9d8b..bba2986 100644 --- a/xdg_shell.c +++ b/xdg_shell.c @@ -225,13 +225,6 @@ destroy(struct cg_view *view) free(xdg_shell_view); } -static struct wlr_surface * -wlr_surface_at(struct cg_view *view, double sx, double sy, double *sub_x, double *sub_y) -{ - struct cg_xdg_shell_view *xdg_shell_view = xdg_shell_view_from_view(view); - return wlr_xdg_surface_surface_at(xdg_shell_view->xdg_surface, sx, sy, sub_x, sub_y); -} - static void handle_xdg_shell_surface_request_fullscreen(struct wl_listener *listener, void *data) { @@ -301,7 +294,6 @@ static const struct cg_view_impl xdg_shell_view_impl = { .activate = activate, .maximize = maximize, .destroy = destroy, - .wlr_surface_at = wlr_surface_at, }; void diff --git a/xwayland.c b/xwayland.c index ccfca5f..47e1a2b 100644 --- a/xwayland.c +++ b/xwayland.c @@ -95,12 +95,6 @@ destroy(struct cg_view *view) free(xwayland_view); } -static struct wlr_surface * -wlr_surface_at(struct cg_view *view, double sx, double sy, double *sub_x, double *sub_y) -{ - return wlr_surface_surface_at(view->wlr_surface, sx, sy, sub_x, sub_y); -} - static void handle_xwayland_surface_request_fullscreen(struct wl_listener *listener, void *data) { @@ -172,7 +166,6 @@ static const struct cg_view_impl xwayland_view_impl = { .activate = activate, .maximize = maximize, .destroy = destroy, - .wlr_surface_at = wlr_surface_at, }; void