67 lines
2.6 KiB
C
67 lines
2.6 KiB
C
#define _POSIX_C_SOURCE 200112L
|
|
#include <stdlib.h>
|
|
#include <assert.h>
|
|
#include "node.h"
|
|
|
|
static void destroy_notify(struct wl_listener *listener, void *data)
|
|
{
|
|
struct diyac_node_descriptor *node_descriptor =
|
|
wl_container_of(listener, node_descriptor, destroy);
|
|
wl_list_remove(&node_descriptor->destroy.link);
|
|
free(node_descriptor);
|
|
}
|
|
|
|
void diyac_node_descriptor_create(struct wlr_scene_node *scene_node, enum diyac_node_descriptor_type type, void *data)
|
|
{
|
|
struct diyac_node_descriptor *node_descriptor = calloc(1, sizeof(*node_descriptor));
|
|
node_descriptor->type = type;
|
|
node_descriptor->data = data;
|
|
node_descriptor->destroy.notify = destroy_notify;
|
|
wl_signal_add(&scene_node->events.destroy, &node_descriptor->destroy);
|
|
scene_node->data = node_descriptor;
|
|
}
|
|
|
|
struct diyac_layer_surface *diyac_layer_surface_from_node(struct wlr_scene_node *wlr_scene_node)
|
|
{
|
|
assert(wlr_scene_node->data);
|
|
struct diyac_node_descriptor *node_descriptor = wlr_scene_node->data;
|
|
assert(node_descriptor->type == DIYAC_NODE_LAYER_SURFACE);
|
|
return (struct diyac_layer_surface *)node_descriptor->data;
|
|
}
|
|
struct diyac_view *diyac_view_from_node(struct wlr_scene_node *wlr_scene_node)
|
|
{
|
|
assert(wlr_scene_node->data);
|
|
struct diyac_node_descriptor *node_descriptor = wlr_scene_node->data;
|
|
assert(node_descriptor->type == DIYAC_NODE_VIEW || node_descriptor->type == DIYAC_NODE_XDG_POPUP);
|
|
return (struct diyac_view *)node_descriptor->data;
|
|
}
|
|
|
|
struct diyac_node_descriptor * diyac_node_at(struct diyac_server* server, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy)
|
|
{
|
|
/* This returns the topmost node in the scene at the given layout coords.
|
|
* We only care about surface nodes as we are specifically looking for a
|
|
* surface in the surface tree of a diyac_view. */
|
|
struct wlr_scene_node *node = wlr_scene_node_at(
|
|
&server->scene->tree.node, lx, ly, sx, sy);
|
|
if (node == NULL || node->type != WLR_SCENE_NODE_BUFFER)
|
|
{
|
|
return NULL;
|
|
}
|
|
struct wlr_scene_buffer *scene_buffer = wlr_scene_buffer_from_node(node);
|
|
struct wlr_scene_surface *scene_surface =
|
|
wlr_scene_surface_try_from_buffer(scene_buffer);
|
|
if (!scene_surface)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
*surface = scene_surface->surface;
|
|
/* Find the node corresponding to the diyac_view at the root of this
|
|
* surface tree, it is the only one for which we set the data field. */
|
|
struct wlr_scene_tree *tree = node->parent;
|
|
while (tree != NULL && tree->node.data == NULL)
|
|
{
|
|
tree = tree->node.parent;
|
|
}
|
|
return tree->node.data;
|
|
} |