ssd: unify struct ssd_part with struct node_descriptor

struct ssd_part and struct node_descriptor seem to have essentially the
same purpose: tag a wlr_scene_node with some extra data indicating what
we're using it for.

Also, as with enum ssd_part_type (now lab_node_type), ssd_part is used
for several types of nodes that are not part of SSD.

So instead of the current chaining (node_descriptor -> ssd_part), let's
flatten/unify the two structs.

In detail:

- First, merge node_descriptor_type into lab_node_type.
- Add a separate view pointer in node_descriptor, since in the case of
  SSD buttons we need separate view and button data pointers.
- Rename ssd_part_button to simply ssd_button. It no longer contains
  an ssd_part as base.
- Add node_try_ssd_button_from_node() which replaces
  node_ssd_part_from_node() + button_try_from_ssd_part().
- Factor out ssd_button_free() to be called in node descriptor destroy.
- Finally, get_cursor_context() needs a little reorganization to handle
  the unified structs.

Overall, this simplifies the code a bit, and in my opinion makes it
easier to understand. No functional change intended.
This commit is contained in:
John Lindgren 2025-09-03 05:32:44 -04:00
parent ba426e2271
commit f129571779
22 changed files with 169 additions and 239 deletions

View file

@ -247,11 +247,11 @@ get_surface_from_layer_node(struct wlr_scene_node *node)
{
assert(node->data);
struct node_descriptor *desc = (struct node_descriptor *)node->data;
if (desc->type == LAB_NODE_DESC_LAYER_SURFACE) {
if (desc->type == LAB_NODE_LAYER_SURFACE) {
struct lab_layer_surface *surface;
surface = node_layer_surface_from_node(node);
return surface->scene_layer_surface->layer_surface->surface;
} else if (desc->type == LAB_NODE_DESC_LAYER_POPUP) {
} else if (desc->type == LAB_NODE_LAYER_POPUP) {
struct lab_layer_popup *popup;
popup = node_layer_popup_from_node(node);
return popup->wlr_popup->base->surface;
@ -299,9 +299,9 @@ get_cursor_context(struct server *server)
struct node_descriptor *desc = node->data;
if (desc) {
switch (desc->type) {
case LAB_NODE_DESC_VIEW:
case LAB_NODE_DESC_XDG_POPUP:
ret.view = desc->data;
case LAB_NODE_VIEW:
case LAB_NODE_XDG_POPUP:
ret.view = desc->view;
if (ret.node->type == WLR_SCENE_NODE_BUFFER
&& lab_wlr_surface_from_node(ret.node)) {
ret.type = LAB_NODE_CLIENT;
@ -311,10 +311,43 @@ get_cursor_context(struct server *server)
wlr_log(WLR_ERROR, "cursor not on client or ssd");
}
return ret;
case LAB_NODE_DESC_SSD_PART: {
struct ssd_part *part = node_ssd_part_from_node(node);
case LAB_NODE_LAYER_SURFACE:
ret.node = node;
ret.view = ssd_part_get_view(part);
ret.type = LAB_NODE_LAYER_SURFACE;
ret.surface = get_surface_from_layer_node(node);
return ret;
case LAB_NODE_LAYER_POPUP:
ret.node = node;
ret.type = LAB_NODE_CLIENT;
ret.surface = get_surface_from_layer_node(node);
return ret;
case LAB_NODE_SESSION_LOCK_SURFACE: /* fallthrough */
case LAB_NODE_IME_POPUP:
ret.type = LAB_NODE_CLIENT;
ret.surface = lab_wlr_surface_from_node(ret.node);
return ret;
case LAB_NODE_MENUITEM:
/* Always return the top scene node for menu items */
ret.node = node;
ret.type = LAB_NODE_MENUITEM;
return ret;
case LAB_NODE_TREE:
case LAB_NODE_SCALED_BUFFER:
/* Continue to parent node */
break;
default:
/*
* All other node descriptors (buttons, title,
* etc.) should have an associated view.
*/
if (!desc->view) {
wlr_log(WLR_ERROR, "cursor not on any view "
"(node type %d)", desc->type);
return ret;
}
ret.node = node;
ret.view = desc->view;
/* Detect mouse contexts like Top, Left and TRCorner */
ret.type = ssd_get_resizing_type(ret.view->ssd, cursor);
@ -323,36 +356,11 @@ get_cursor_context(struct server *server)
* Otherwise, detect mouse contexts like
* Title, Titlebar and Iconify
*/
ret.type = ssd_part_get_type(part);
ret.type = desc->type;
}
return ret;
}
case LAB_NODE_DESC_LAYER_SURFACE:
ret.node = node;
ret.type = LAB_NODE_LAYER_SURFACE;
ret.surface = get_surface_from_layer_node(node);
return ret;
case LAB_NODE_DESC_LAYER_POPUP:
ret.node = node;
ret.type = LAB_NODE_CLIENT;
ret.surface = get_surface_from_layer_node(node);
return ret;
case LAB_NODE_DESC_SESSION_LOCK_SURFACE: /* fallthrough */
case LAB_NODE_DESC_IME_POPUP:
ret.type = LAB_NODE_CLIENT;
ret.surface = lab_wlr_surface_from_node(ret.node);
return ret;
case LAB_NODE_DESC_MENUITEM:
/* Always return the top scene node for menu items */
ret.node = node;
ret.type = LAB_NODE_MENU;
return ret;
case LAB_NODE_DESC_NODE:
case LAB_NODE_DESC_TREE:
case LAB_NODE_DESC_SCALED_BUFFER:
break;
}
}
/* Edge-case nodes without node-descriptors */