mirror of
https://github.com/labwc/labwc.git
synced 2025-11-02 09:01:47 -05:00
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:
parent
ba426e2271
commit
f129571779
22 changed files with 169 additions and 239 deletions
|
|
@ -34,7 +34,8 @@ ssd_titlebar_create(struct ssd *ssd)
|
|||
int corner_width = ssd_get_corner_width();
|
||||
|
||||
ssd->titlebar.tree = wlr_scene_tree_create(ssd->tree);
|
||||
attach_ssd_part(LAB_NODE_TITLEBAR, view, &ssd->titlebar.tree->node);
|
||||
node_descriptor_create(&ssd->titlebar.tree->node,
|
||||
LAB_NODE_TITLEBAR, view, /*data*/ NULL);
|
||||
|
||||
enum ssd_active_state active;
|
||||
FOR_EACH_ACTIVE_STATE(active) {
|
||||
|
|
@ -78,8 +79,8 @@ ssd_titlebar_create(struct ssd *ssd)
|
|||
subtree->tree, theme->titlebar_height,
|
||||
theme->window[active].titlebar_pattern);
|
||||
assert(subtree->title);
|
||||
attach_ssd_part(LAB_NODE_TITLE,
|
||||
view, &subtree->title->scene_buffer->node);
|
||||
node_descriptor_create(&subtree->title->scene_buffer->node,
|
||||
LAB_NODE_TITLE, view, /*data*/ NULL);
|
||||
|
||||
/* Buttons */
|
||||
struct title_button *b;
|
||||
|
|
@ -94,7 +95,7 @@ ssd_titlebar_create(struct ssd *ssd)
|
|||
wl_list_for_each(b, &rc.title_buttons_left, link) {
|
||||
struct lab_img **imgs =
|
||||
theme->window[active].button_imgs[b->type];
|
||||
attach_ssd_part_button(&subtree->buttons_left, b->type, parent,
|
||||
attach_ssd_button(&subtree->buttons_left, b->type, parent,
|
||||
imgs, x, y, view);
|
||||
x += theme->window_button_width + theme->window_button_spacing;
|
||||
}
|
||||
|
|
@ -104,7 +105,7 @@ ssd_titlebar_create(struct ssd *ssd)
|
|||
x -= theme->window_button_width + theme->window_button_spacing;
|
||||
struct lab_img **imgs =
|
||||
theme->window[active].button_imgs[b->type];
|
||||
attach_ssd_part_button(&subtree->buttons_right, b->type, parent,
|
||||
attach_ssd_button(&subtree->buttons_right, b->type, parent,
|
||||
imgs, x, y, view);
|
||||
}
|
||||
}
|
||||
|
|
@ -134,7 +135,7 @@ ssd_titlebar_create(struct ssd *ssd)
|
|||
}
|
||||
|
||||
static void
|
||||
update_button_state(struct ssd_part_button *button, enum lab_button_state state,
|
||||
update_button_state(struct ssd_button *button, enum lab_button_state state,
|
||||
bool enable)
|
||||
{
|
||||
if (enable) {
|
||||
|
|
@ -177,7 +178,7 @@ set_squared_corners(struct ssd *ssd, bool enable)
|
|||
wlr_scene_node_set_enabled(&subtree->corner_right->node, !enable);
|
||||
|
||||
/* (Un)round the corner buttons */
|
||||
struct ssd_part_button *button;
|
||||
struct ssd_button *button;
|
||||
wl_list_for_each(button, &subtree->buttons_left, link) {
|
||||
update_button_state(button, LAB_BS_ROUNDED, !enable);
|
||||
break;
|
||||
|
|
@ -196,15 +197,15 @@ set_alt_button_icon(struct ssd *ssd, enum lab_node_type type, bool enable)
|
|||
FOR_EACH_ACTIVE_STATE(active) {
|
||||
struct ssd_titlebar_subtree *subtree = &ssd->titlebar.subtrees[active];
|
||||
|
||||
struct ssd_part_button *button;
|
||||
struct ssd_button *button;
|
||||
wl_list_for_each(button, &subtree->buttons_left, link) {
|
||||
if (button->base.type == type) {
|
||||
if (button->type == type) {
|
||||
update_button_state(button,
|
||||
LAB_BS_TOGGLED, enable);
|
||||
}
|
||||
}
|
||||
wl_list_for_each(button, &subtree->buttons_right, link) {
|
||||
if (button->base.type == type) {
|
||||
if (button->type == type) {
|
||||
update_button_state(button,
|
||||
LAB_BS_TOGGLED, enable);
|
||||
}
|
||||
|
|
@ -251,16 +252,16 @@ update_visible_buttons(struct ssd *ssd)
|
|||
struct ssd_titlebar_subtree *subtree = &ssd->titlebar.subtrees[active];
|
||||
int button_count = 0;
|
||||
|
||||
struct ssd_part_button *button;
|
||||
struct ssd_button *button;
|
||||
wl_list_for_each(button, &subtree->buttons_left, link) {
|
||||
wlr_scene_node_set_enabled(button->base.node,
|
||||
wlr_scene_node_set_enabled(button->node,
|
||||
button_count < button_count_left);
|
||||
button_count++;
|
||||
}
|
||||
|
||||
button_count = 0;
|
||||
wl_list_for_each(button, &subtree->buttons_right, link) {
|
||||
wlr_scene_node_set_enabled(button->base.node,
|
||||
wlr_scene_node_set_enabled(button->node,
|
||||
button_count < button_count_right);
|
||||
button_count++;
|
||||
}
|
||||
|
|
@ -317,9 +318,9 @@ ssd_titlebar_update(struct ssd *ssd)
|
|||
MAX(width - bg_offset * 2, 0), theme->titlebar_height);
|
||||
|
||||
x = theme->window_titlebar_padding_width;
|
||||
struct ssd_part_button *button;
|
||||
struct ssd_button *button;
|
||||
wl_list_for_each(button, &subtree->buttons_left, link) {
|
||||
wlr_scene_node_set_position(button->base.node, x, y);
|
||||
wlr_scene_node_set_position(button->node, x, y);
|
||||
x += theme->window_button_width + theme->window_button_spacing;
|
||||
}
|
||||
|
||||
|
|
@ -330,7 +331,7 @@ ssd_titlebar_update(struct ssd *ssd)
|
|||
x = width - theme->window_titlebar_padding_width + theme->window_button_spacing;
|
||||
wl_list_for_each(button, &subtree->buttons_right, link) {
|
||||
x -= theme->window_button_width + theme->window_button_spacing;
|
||||
wlr_scene_node_set_position(button->base.node, x, y);
|
||||
wlr_scene_node_set_position(button->node, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -419,14 +420,14 @@ get_title_offsets(struct ssd *ssd, int *offset_left, int *offset_right)
|
|||
*offset_left = padding_width;
|
||||
*offset_right = padding_width;
|
||||
|
||||
struct ssd_part_button *button;
|
||||
struct ssd_button *button;
|
||||
wl_list_for_each(button, &subtree->buttons_left, link) {
|
||||
if (button->base.node->enabled) {
|
||||
if (button->node->enabled) {
|
||||
*offset_left += button_width + button_spacing;
|
||||
}
|
||||
}
|
||||
wl_list_for_each(button, &subtree->buttons_right, link) {
|
||||
if (button->base.node->enabled) {
|
||||
if (button->node->enabled) {
|
||||
*offset_right += button_width + button_spacing;
|
||||
}
|
||||
}
|
||||
|
|
@ -494,17 +495,13 @@ ssd_update_title(struct ssd *ssd)
|
|||
void
|
||||
ssd_update_hovered_button(struct server *server, struct wlr_scene_node *node)
|
||||
{
|
||||
struct ssd_part_button *button = NULL;
|
||||
struct ssd_button *button = NULL;
|
||||
|
||||
if (node && node->data) {
|
||||
struct node_descriptor *desc = node->data;
|
||||
if (desc->type == LAB_NODE_DESC_SSD_PART) {
|
||||
button = button_try_from_ssd_part(
|
||||
node_ssd_part_from_node(node));
|
||||
if (button == server->hovered_button) {
|
||||
/* Cursor is still on the same button */
|
||||
return;
|
||||
}
|
||||
button = node_try_ssd_button_from_node(node);
|
||||
if (button == server->hovered_button) {
|
||||
/* Cursor is still on the same button */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue