mirror of
https://github.com/labwc/labwc.git
synced 2025-11-04 13:30:07 -05:00
node.c: add helpers for returning structs from node data
Support returning the following structs: - view from LAB_NODE_DESC_VIEW or LAB_NODE_DESC_XDG_POPUP - lab_layer_surface form LAB_NODE_DESC_LAYER_SURFACE - lab_layer_popup from LAB_NODE_DESC_LAYER_POPUP
This commit is contained in:
parent
30298228e3
commit
b4cbc20e8c
3 changed files with 66 additions and 13 deletions
|
|
@ -3,12 +3,16 @@
|
||||||
#define __LABWC_NODE_DESCRIPTOR_H
|
#define __LABWC_NODE_DESCRIPTOR_H
|
||||||
#include <wlr/types/wlr_scene.h>
|
#include <wlr/types/wlr_scene.h>
|
||||||
|
|
||||||
|
struct view;
|
||||||
|
struct lab_layer_surface;
|
||||||
|
struct lab_layer_popup;
|
||||||
|
|
||||||
enum node_descriptor_type {
|
enum node_descriptor_type {
|
||||||
LAB_NODE_DESC_NODE = 0,
|
LAB_NODE_DESC_NODE = 0,
|
||||||
LAB_NODE_DESC_VIEW, /* *data --> struct view */
|
LAB_NODE_DESC_VIEW,
|
||||||
LAB_NODE_DESC_XDG_POPUP, /* *data --> struct view */
|
LAB_NODE_DESC_XDG_POPUP,
|
||||||
LAB_NODE_DESC_LAYER_SURFACE, /* *data --> struct lab_layer_surface */
|
LAB_NODE_DESC_LAYER_SURFACE,
|
||||||
LAB_NODE_DESC_LAYER_POPUP, /* *data --> struct lab_layer_popup */
|
LAB_NODE_DESC_LAYER_POPUP,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct node_descriptor {
|
struct node_descriptor {
|
||||||
|
|
@ -17,7 +21,37 @@ struct node_descriptor {
|
||||||
struct wl_listener destroy;
|
struct wl_listener destroy;
|
||||||
};
|
};
|
||||||
|
|
||||||
void node_descriptor_create(struct wlr_scene_node *node,
|
/**
|
||||||
|
* node_descriptor_create - create node descriptor for wlr_scene_node user_data
|
||||||
|
* @scene_node: wlr_scene_node to attached node_descriptor to
|
||||||
|
* @type: node descriptor type
|
||||||
|
* @data: struct to point to as follows:
|
||||||
|
* - LAB_NODE_DESC_VIEW struct view
|
||||||
|
* - LAB_NODE_DESC_XDG_POPUP struct view
|
||||||
|
* - LAB_NODE_DESC_LAYER_SURFACE struct lab_layer_surface
|
||||||
|
* - LAB_NODE_DESC_LAYER_POPUP struct lab_layer_popup
|
||||||
|
*/
|
||||||
|
void node_descriptor_create(struct wlr_scene_node *scene_node,
|
||||||
enum node_descriptor_type type, void *data);
|
enum node_descriptor_type type, void *data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* node_view_from_node - return view struct from node
|
||||||
|
* @node_descriptor: node_descriptor from which to return data
|
||||||
|
*/
|
||||||
|
struct view *node_view_from_node(struct node_descriptor *node_descriptor);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* node_lab_surface_from_node - return lab_layer_surface struct from node
|
||||||
|
* @node_descriptor: node_descriptor from which to return data
|
||||||
|
*/
|
||||||
|
struct lab_layer_surface *node_layer_surface_from_node(
|
||||||
|
struct node_descriptor *node_descriptor);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* node_layer_popup_from_node - return lab_layer_popup struct from node
|
||||||
|
* @node_descriptor: node_descriptor from which to return data
|
||||||
|
*/
|
||||||
|
struct lab_layer_popup *node_layer_popup_from_node(
|
||||||
|
struct node_descriptor *node_descriptor);
|
||||||
|
|
||||||
#endif /* __LABWC_NODE_DESCRIPTOR_H */
|
#endif /* __LABWC_NODE_DESCRIPTOR_H */
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0-only
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
#include <assert.h>
|
|
||||||
#include <wlr/types/wlr_layer_shell_v1.h>
|
#include <wlr/types/wlr_layer_shell_v1.h>
|
||||||
#include <wlr/types/wlr_scene.h>
|
#include <wlr/types/wlr_scene.h>
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
|
|
@ -113,10 +112,7 @@ get_special(struct server *server, struct wlr_scene_node *node,
|
||||||
return "server->view_tree";
|
return "server->view_tree";
|
||||||
}
|
}
|
||||||
if (node->parent == &server->view_tree->node) {
|
if (node->parent == &server->view_tree->node) {
|
||||||
struct node_descriptor *desc = node->data;
|
*last_view = node_view_from_node(node->data);
|
||||||
assert(desc->type == LAB_NODE_DESC_VIEW
|
|
||||||
|| desc->type == LAB_NODE_DESC_XDG_POPUP);
|
|
||||||
*last_view = desc->data;
|
|
||||||
}
|
}
|
||||||
const char *view_part = get_view_part(*last_view, node);
|
const char *view_part = get_view_part(*last_view, node);
|
||||||
if (view_part) {
|
if (view_part) {
|
||||||
|
|
|
||||||
29
src/node.c
29
src/node.c
|
|
@ -1,4 +1,5 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0-only
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
|
|
||||||
|
|
@ -21,7 +22,7 @@ destroy_notify(struct wl_listener *listener, void *data)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
node_descriptor_create(struct wlr_scene_node *node,
|
node_descriptor_create(struct wlr_scene_node *scene_node,
|
||||||
enum node_descriptor_type type, void *data)
|
enum node_descriptor_type type, void *data)
|
||||||
{
|
{
|
||||||
struct node_descriptor *node_descriptor =
|
struct node_descriptor *node_descriptor =
|
||||||
|
|
@ -32,6 +33,28 @@ node_descriptor_create(struct wlr_scene_node *node,
|
||||||
node_descriptor->type = type;
|
node_descriptor->type = type;
|
||||||
node_descriptor->data = data;
|
node_descriptor->data = data;
|
||||||
node_descriptor->destroy.notify = destroy_notify;
|
node_descriptor->destroy.notify = destroy_notify;
|
||||||
wl_signal_add(&node->events.destroy, &node_descriptor->destroy);
|
wl_signal_add(&scene_node->events.destroy, &node_descriptor->destroy);
|
||||||
node->data = node_descriptor;
|
scene_node->data = node_descriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct view *
|
||||||
|
node_view_from_node(struct node_descriptor *node_descriptor)
|
||||||
|
{
|
||||||
|
assert(node_descriptor->type == LAB_NODE_DESC_VIEW
|
||||||
|
|| node_descriptor->type == LAB_NODE_DESC_XDG_POPUP);
|
||||||
|
return (struct view *)node_descriptor->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct lab_layer_surface *
|
||||||
|
node_layer_surface_from_node(struct node_descriptor *node_descriptor)
|
||||||
|
{
|
||||||
|
assert(node_descriptor->type == LAB_NODE_DESC_LAYER_SURFACE);
|
||||||
|
return (struct lab_layer_surface *)node_descriptor->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct lab_layer_popup *
|
||||||
|
node_layer_popup_from_node(struct node_descriptor *node_descriptor)
|
||||||
|
{
|
||||||
|
assert(node_descriptor->type == LAB_NODE_DESC_LAYER_POPUP);
|
||||||
|
return (struct lab_layer_popup *)node_descriptor->data;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue