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

@ -135,23 +135,10 @@ struct ssd {
struct border margin;
};
/*
* ssd_part wraps a scene-node with ssd-specific information and can be
* accessed with node_ssd_part_from_node(wlr_scene_node *).
* This allows get_cursor_context() in desktop.c to see which SSD part is under
* the cursor.
*/
struct ssd_part {
enum lab_node_type type;
struct view *view;
/* This part represented in scene graph */
struct ssd_button {
struct wlr_scene_node *node;
struct wl_listener node_destroy;
};
enum lab_node_type type;
struct ssd_part_button {
struct ssd_part base;
/*
* Bitmap of lab_button_state that represents a combination of
* hover/toggled/rounded states.
@ -177,13 +164,10 @@ struct wlr_buffer;
struct wlr_scene_tree;
/* SSD internal helpers to create various SSD elements */
struct ssd_part *attach_ssd_part(enum lab_node_type type, struct view *view,
struct wlr_scene_node *node);
struct ssd_part_button *attach_ssd_part_button(struct wl_list *button_parts,
struct ssd_button *attach_ssd_button(struct wl_list *button_parts,
enum lab_node_type type, struct wlr_scene_tree *parent,
struct lab_img *imgs[LAB_BS_ALL + 1], int x, int y,
struct view *view);
struct ssd_part_button *button_try_from_ssd_part(struct ssd_part *part);
/* SSD internal */
void ssd_titlebar_create(struct ssd *ssd);