From f8e3d167d4a0fe32269402af8e6417f71801a1d9 Mon Sep 17 00:00:00 2001 From: Jente Hidskes Date: Fri, 24 Dec 2021 08:58:19 +0100 Subject: [PATCH] view: implement view_from_wlr_surface in terms of wlr_surface->data pointer --- seat.c | 2 +- view.c | 20 ++++++++++---------- view.h | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/seat.c b/seat.c index f155506..b0d6ea1 100644 --- a/seat.c +++ b/seat.c @@ -817,7 +817,7 @@ struct cg_view * seat_get_focus(struct cg_seat *seat) { struct wlr_surface *prev_surface = seat->seat->keyboard_state.focused_surface; - return view_from_wlr_surface(seat->server, prev_surface); + return view_from_wlr_surface(prev_surface); } void diff --git a/view.c b/view.c index 745f4e5..8c064a9 100644 --- a/view.c +++ b/view.c @@ -1,7 +1,7 @@ /* * Cage: A Wayland kiosk. * - * Copyright (C) 2018-2020 Jente Hidskes + * Copyright (C) 2018-2021 Jente Hidskes * * See the LICENSE file accompanying this file. */ @@ -103,14 +103,13 @@ view_unmap(struct cg_view *view) wlr_scene_node_destroy(view->scene_node); + view->wlr_surface->data = NULL; view->wlr_surface = NULL; } void view_map(struct cg_view *view, struct wlr_surface *surface) { - view->wlr_surface = surface; - view->scene_node = wlr_scene_subsurface_tree_create(&view->server->scene->node, surface); if (!view->scene_node) { wl_resource_post_no_memory(surface->resource); @@ -118,6 +117,9 @@ view_map(struct cg_view *view, struct wlr_surface *surface) } view->scene_node->data = view; + view->wlr_surface = surface; + surface->data = view; + #if CAGE_HAS_XWAYLAND /* We shouldn't position override-redirect windows. They set their own (x,y) coordinates in handle_wayland_surface_map. */ @@ -159,13 +161,11 @@ view_init(struct cg_view *view, struct cg_server *server, enum cg_view_type type } struct cg_view * -view_from_wlr_surface(struct cg_server *server, struct wlr_surface *surface) +view_from_wlr_surface(struct wlr_surface *surface) { - struct cg_view *view; - wl_list_for_each (view, &server->views, link) { - if (view->wlr_surface == surface) { - return view; - } + if (!surface) { + return NULL; } - return NULL; + + return surface->data; } diff --git a/view.h b/view.h index 10a4e4a..677a949 100644 --- a/view.h +++ b/view.h @@ -54,6 +54,6 @@ void view_map(struct cg_view *view, struct wlr_surface *surface); 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 cg_view *view_from_wlr_surface(struct wlr_surface *surface); #endif