mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	Add node-descriptor for wlr_scene_nodes
Support identification of wlr_scene_node role to enable simplification of codebase including the avoidance of iterating over lists of layer-surface, menuitems, and so on. Use node-descriptors for xdg toplevels and popups
This commit is contained in:
		
							parent
							
								
									4c981b845f
								
							
						
					
					
						commit
						2891ff245e
					
				
					 7 changed files with 92 additions and 6 deletions
				
			
		
							
								
								
									
										23
									
								
								include/node-descriptor.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								include/node-descriptor.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,23 @@
 | 
			
		|||
/* SPDX-License-Identifier: GPL-2.0-only */
 | 
			
		||||
#ifndef __LABWC_NODE_DESCRIPTOR_H
 | 
			
		||||
#define __LABWC_NODE_DESCRIPTOR_H
 | 
			
		||||
#include <wlr/types/wlr_scene.h>
 | 
			
		||||
 | 
			
		||||
enum node_descriptor_type {
 | 
			
		||||
	LAB_NODE_DESC_NODE = 0,
 | 
			
		||||
	LAB_NODE_DESC_VIEW,		/* *data --> struct view */
 | 
			
		||||
	LAB_NODE_DESC_XDG_POPUP,	/* *data --> struct view */
 | 
			
		||||
	LAB_NODE_DESC_LAYER_SURFACE,	/* *data --> struct lab_layer_surface */
 | 
			
		||||
	LAB_NODE_DESC_LAYER_POPUP,	/* *data --> struct lab_layer_popup */
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct node_descriptor {
 | 
			
		||||
	enum node_descriptor_type type;
 | 
			
		||||
	void *data;
 | 
			
		||||
	struct wl_listener destroy;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void node_descriptor_create(struct wlr_scene_node *node,
 | 
			
		||||
	enum node_descriptor_type type, void *data);
 | 
			
		||||
 | 
			
		||||
#endif /* __LABWC_NODE_DESCRIPTOR_H */
 | 
			
		||||
| 
						 | 
				
			
			@ -3,6 +3,7 @@
 | 
			
		|||
#include <assert.h>
 | 
			
		||||
#include "labwc.h"
 | 
			
		||||
#include "layers.h"
 | 
			
		||||
#include "node-descriptor.h"
 | 
			
		||||
#include "ssd.h"
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
| 
						 | 
				
			
			@ -285,7 +286,21 @@ desktop_node_and_view_at(struct server *server, double lx, double ly,
 | 
			
		|||
	}
 | 
			
		||||
	struct wlr_scene_node *osd = &server->osd_tree->node;
 | 
			
		||||
	struct wlr_scene_node *menu = &server->menu_tree->node;
 | 
			
		||||
	while (node && !node->data) {
 | 
			
		||||
	while (node) {
 | 
			
		||||
		struct node_descriptor *desc = node->data;
 | 
			
		||||
		if (desc) {
 | 
			
		||||
			if (desc->type == LAB_NODE_DESC_VIEW) {
 | 
			
		||||
				goto has_view_data;
 | 
			
		||||
			}
 | 
			
		||||
			if (desc->type == LAB_NODE_DESC_XDG_POPUP) {
 | 
			
		||||
				goto has_view_data;
 | 
			
		||||
			}
 | 
			
		||||
			if (desc->type == LAB_NODE_DESC_LAYER_POPUP) {
 | 
			
		||||
				/* FIXME: we shouldn't have to set *view_area */
 | 
			
		||||
				*view_area = LAB_SSD_LAYER_SURFACE;
 | 
			
		||||
				return NULL;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		if (node == osd) {
 | 
			
		||||
			*view_area = LAB_SSD_OSD;
 | 
			
		||||
			return NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -297,10 +312,13 @@ desktop_node_and_view_at(struct server *server, double lx, double ly,
 | 
			
		|||
	}
 | 
			
		||||
	if (!node) {
 | 
			
		||||
		wlr_log(WLR_ERROR, "Unknown node detected");
 | 
			
		||||
		*view_area = LAB_SSD_NONE;
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
	struct view *view = node->data;
 | 
			
		||||
	*view_area = LAB_SSD_NONE;
 | 
			
		||||
	return NULL;
 | 
			
		||||
 | 
			
		||||
has_view_data:
 | 
			
		||||
	struct node_descriptor *desc = node->data;
 | 
			
		||||
	struct view *view = desc->data;
 | 
			
		||||
	*view_area = ssd_get_part_type(view, *scene_node);
 | 
			
		||||
	return view;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,6 +11,7 @@ labwc_sources = files(
 | 
			
		|||
  'key-state.c',
 | 
			
		||||
  'layers.c',
 | 
			
		||||
  'main.c',
 | 
			
		||||
  'node-descriptor.c',
 | 
			
		||||
  'osd.c',
 | 
			
		||||
  'output.c',
 | 
			
		||||
  'resistance.c',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										37
									
								
								src/node-descriptor.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								src/node-descriptor.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,37 @@
 | 
			
		|||
// SPDX-License-Identifier: GPL-2.0-only
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include "node-descriptor.h"
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
descriptor_destroy(struct node_descriptor *node_descriptor)
 | 
			
		||||
{
 | 
			
		||||
	if (!node_descriptor) {
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	wl_list_remove(&node_descriptor->destroy.link);
 | 
			
		||||
	free(node_descriptor);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
destroy_notify(struct wl_listener *listener, void *data)
 | 
			
		||||
{
 | 
			
		||||
	struct node_descriptor *node_descriptor =
 | 
			
		||||
		wl_container_of(listener, node_descriptor, destroy);
 | 
			
		||||
	descriptor_destroy(node_descriptor);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
node_descriptor_create(struct wlr_scene_node *node,
 | 
			
		||||
		enum node_descriptor_type type, void *data)
 | 
			
		||||
{
 | 
			
		||||
	struct node_descriptor *node_descriptor =
 | 
			
		||||
		calloc(1, sizeof(struct node_descriptor));
 | 
			
		||||
	if (!node_descriptor) {
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	node_descriptor->type = type;
 | 
			
		||||
	node_descriptor->data = data;
 | 
			
		||||
	node_descriptor->destroy.notify = destroy_notify;
 | 
			
		||||
	wl_signal_add(&node->events.destroy, &node_descriptor->destroy);
 | 
			
		||||
	node->data = node_descriptor;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -8,6 +8,7 @@
 | 
			
		|||
 */
 | 
			
		||||
 | 
			
		||||
#include "labwc.h"
 | 
			
		||||
#include "node-descriptor.h"
 | 
			
		||||
 | 
			
		||||
struct view_child {
 | 
			
		||||
	struct wlr_surface *surface;
 | 
			
		||||
| 
						 | 
				
			
			@ -93,6 +94,8 @@ xdg_popup_create(struct view *view, struct wlr_xdg_popup *wlr_popup)
 | 
			
		|||
	struct wlr_scene_node *parent_node = parent->surface->data;
 | 
			
		||||
	wlr_popup->base->surface->data =
 | 
			
		||||
		wlr_scene_xdg_surface_create(parent_node, wlr_popup->base);
 | 
			
		||||
	node_descriptor_create(wlr_popup->base->surface->data,
 | 
			
		||||
		LAB_NODE_DESC_XDG_POPUP, view);
 | 
			
		||||
 | 
			
		||||
	popup_unconstrain(view, wlr_popup);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
// SPDX-License-Identifier: GPL-2.0-only
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
#include "labwc.h"
 | 
			
		||||
#include "node-descriptor.h"
 | 
			
		||||
#include "ssd.h"
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
| 
						 | 
				
			
			@ -404,7 +405,8 @@ xdg_surface_new(struct wl_listener *listener, void *data)
 | 
			
		|||
		wl_resource_post_no_memory(view->surface->resource);
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	view->scene_tree->node.data = view;
 | 
			
		||||
	node_descriptor_create(&view->scene_tree->node,
 | 
			
		||||
		LAB_NODE_DESC_VIEW, view);
 | 
			
		||||
 | 
			
		||||
	/* In support of xdg_toplevel_decoration */
 | 
			
		||||
	xdg_surface->data = view;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
// SPDX-License-Identifier: GPL-2.0-only
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
#include "labwc.h"
 | 
			
		||||
#include "node-descriptor.h"
 | 
			
		||||
#include "ssd.h"
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
| 
						 | 
				
			
			@ -394,7 +395,8 @@ xwayland_surface_new(struct wl_listener *listener, void *data)
 | 
			
		|||
	view->xwayland_surface = xsurface;
 | 
			
		||||
 | 
			
		||||
	view->scene_tree = wlr_scene_tree_create(&view->server->view_tree->node);
 | 
			
		||||
	view->scene_tree->node.data = view;
 | 
			
		||||
	node_descriptor_create(&view->scene_tree->node,
 | 
			
		||||
		LAB_NODE_DESC_VIEW, view);
 | 
			
		||||
	xsurface->data = view;
 | 
			
		||||
 | 
			
		||||
	view->map.notify = handle_map;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue