mirror of
https://github.com/cage-kiosk/cage.git
synced 2025-10-29 05:40:19 -04:00
Replace view_wlr_surface_at with scene-graph
This commit is contained in:
parent
6d60c6c464
commit
fb3dc58237
5 changed files with 22 additions and 54 deletions
52
seat.c
52
seat.c
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <linux/input-event-codes.h>
|
#include <linux/input-event-codes.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <wayland-server-core.h>
|
#include <wayland-server-core.h>
|
||||||
|
|
@ -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
|
* 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
|
* 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
|
* surface pointer to that wlr_surface and the sx and sy coordinates to the
|
||||||
* coordinates relative to that surface's top-left corner. */
|
* 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)
|
* 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
|
||||||
double view_sx = lx - view->lx;
|
* surface. There cannot be a surface without a view, either. It's both or
|
||||||
double view_sy = ly - view->ly;
|
* nothing.
|
||||||
|
*/
|
||||||
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. */
|
|
||||||
static struct cg_view *
|
static struct cg_view *
|
||||||
desktop_view_at(struct cg_server *server, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy)
|
desktop_view_at(struct cg_server *server, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy)
|
||||||
{
|
{
|
||||||
struct cg_view *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) {
|
||||||
wl_list_for_each (view, &server->views, link) {
|
return NULL;
|
||||||
if (view_at(view, lx, ly, surface, sx, sy)) {
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
static void
|
||||||
|
|
|
||||||
7
view.c
7
view.c
|
|
@ -231,6 +231,7 @@ view_map(struct cg_view *view, struct wlr_surface *surface)
|
||||||
wl_resource_post_no_memory(surface->resource);
|
wl_resource_post_no_memory(surface->resource);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
view->scene_surface->node.data = view;
|
||||||
|
|
||||||
struct wlr_subsurface *subsurface;
|
struct wlr_subsurface *subsurface;
|
||||||
wl_list_for_each (subsurface, &view->wlr_surface->current.subsurfaces_below, current.link) {
|
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;
|
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);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
2
view.h
2
view.h
|
|
@ -45,7 +45,6 @@ struct cg_view_impl {
|
||||||
void (*activate)(struct cg_view *view, bool activate);
|
void (*activate)(struct cg_view *view, bool activate);
|
||||||
void (*maximize)(struct cg_view *view, int output_width, int output_height);
|
void (*maximize)(struct cg_view *view, int output_width, int output_height);
|
||||||
void (*destroy)(struct cg_view *view);
|
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 {
|
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);
|
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 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_finish(struct cg_view_child *child);
|
||||||
void view_child_init(struct cg_view_child *child, struct cg_view *view, struct wlr_surface *wlr_surface);
|
void view_child_init(struct cg_view_child *child, struct cg_view *view, struct wlr_surface *wlr_surface);
|
||||||
|
|
|
||||||
|
|
@ -225,13 +225,6 @@ destroy(struct cg_view *view)
|
||||||
free(xdg_shell_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
|
static void
|
||||||
handle_xdg_shell_surface_request_fullscreen(struct wl_listener *listener, void *data)
|
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,
|
.activate = activate,
|
||||||
.maximize = maximize,
|
.maximize = maximize,
|
||||||
.destroy = destroy,
|
.destroy = destroy,
|
||||||
.wlr_surface_at = wlr_surface_at,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
||||||
|
|
@ -95,12 +95,6 @@ destroy(struct cg_view *view)
|
||||||
free(xwayland_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
|
static void
|
||||||
handle_xwayland_surface_request_fullscreen(struct wl_listener *listener, void *data)
|
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,
|
.activate = activate,
|
||||||
.maximize = maximize,
|
.maximize = maximize,
|
||||||
.destroy = destroy,
|
.destroy = destroy,
|
||||||
.wlr_surface_at = wlr_surface_at,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue