mirror of
https://github.com/labwc/labwc.git
synced 2025-11-11 13:30:04 -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
|
|
@ -1,7 +1,7 @@
|
|||
labwc_sources += files(
|
||||
'resize-indicator.c',
|
||||
'ssd.c',
|
||||
'ssd-part.c',
|
||||
'ssd-button.c',
|
||||
'ssd-titlebar.c',
|
||||
'ssd-border.c',
|
||||
'ssd-extents.c',
|
||||
|
|
|
|||
|
|
@ -7,55 +7,13 @@
|
|||
#include "node.h"
|
||||
#include "scaled-buffer/scaled-icon-buffer.h"
|
||||
#include "scaled-buffer/scaled-img-buffer.h"
|
||||
#include "ssd.h"
|
||||
#include "ssd-internal.h"
|
||||
|
||||
/* Internal helpers */
|
||||
static void
|
||||
handle_node_destroy(struct wl_listener *listener, void *data)
|
||||
{
|
||||
struct ssd_part *part = wl_container_of(listener, part, node_destroy);
|
||||
wl_list_remove(&part->node_destroy.link);
|
||||
|
||||
struct ssd_part_button *button = button_try_from_ssd_part(part);
|
||||
if (button) {
|
||||
wl_list_remove(&button->link);
|
||||
}
|
||||
|
||||
free(part);
|
||||
}
|
||||
|
||||
/* Internal API */
|
||||
|
||||
/*
|
||||
* Create a new node_descriptor containing a link to a new ssd_part struct.
|
||||
* Both will be destroyed automatically once the scene_node they are attached
|
||||
* to is destroyed.
|
||||
*/
|
||||
static void
|
||||
init_ssd_part(struct ssd_part *part, enum lab_node_type type,
|
||||
struct view *view, struct wlr_scene_node *node)
|
||||
{
|
||||
part->type = type;
|
||||
part->node = node;
|
||||
part->view = view;
|
||||
|
||||
node_descriptor_create(node, LAB_NODE_DESC_SSD_PART, part);
|
||||
part->node_destroy.notify = handle_node_destroy;
|
||||
wl_signal_add(&node->events.destroy, &part->node_destroy);
|
||||
}
|
||||
|
||||
struct ssd_part *
|
||||
attach_ssd_part(enum lab_node_type type, struct view *view,
|
||||
struct wlr_scene_node *node)
|
||||
{
|
||||
assert(!node_type_contains(LAB_NODE_BUTTON, type));
|
||||
struct ssd_part *part = znew(*part);
|
||||
init_ssd_part(part, type, view, node);
|
||||
return part;
|
||||
}
|
||||
|
||||
struct ssd_part_button *
|
||||
attach_ssd_part_button(struct wl_list *button_parts, enum lab_node_type type,
|
||||
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)
|
||||
|
|
@ -64,8 +22,10 @@ attach_ssd_part_button(struct wl_list *button_parts, enum lab_node_type type,
|
|||
wlr_scene_node_set_position(&root->node, x, y);
|
||||
|
||||
assert(node_type_contains(LAB_NODE_BUTTON, type));
|
||||
struct ssd_part_button *button = znew(*button);
|
||||
init_ssd_part(&button->base, type, view, &root->node);
|
||||
struct ssd_button *button = znew(*button);
|
||||
button->node = &root->node;
|
||||
button->type = type;
|
||||
node_descriptor_create(&root->node, type, view, button);
|
||||
wl_list_append(button_parts, &button->link);
|
||||
|
||||
/* Hitbox */
|
||||
|
|
@ -117,11 +77,9 @@ attach_ssd_part_button(struct wl_list *button_parts, enum lab_node_type type,
|
|||
return button;
|
||||
}
|
||||
|
||||
struct ssd_part_button *
|
||||
button_try_from_ssd_part(struct ssd_part *part)
|
||||
/* called from node descriptor destroy */
|
||||
void ssd_button_free(struct ssd_button *button)
|
||||
{
|
||||
if (node_type_contains(LAB_NODE_BUTTON, part->type)) {
|
||||
return (struct ssd_part_button *)part;
|
||||
}
|
||||
return NULL;
|
||||
wl_list_remove(&button->link);
|
||||
free(button);
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#include "common/scene-helpers.h"
|
||||
#include "config/rcxml.h"
|
||||
#include "labwc.h"
|
||||
#include "node.h"
|
||||
#include "ssd-internal.h"
|
||||
#include "theme.h"
|
||||
#include "view.h"
|
||||
|
|
@ -145,7 +146,8 @@ ssd_create(struct view *view, bool active)
|
|||
|
||||
ssd->view = view;
|
||||
ssd->tree = wlr_scene_tree_create(view->scene_tree);
|
||||
attach_ssd_part(LAB_NODE_NONE, view, &ssd->tree->node);
|
||||
node_descriptor_create(&ssd->tree->node,
|
||||
LAB_NODE_NONE, view, /*data*/ NULL);
|
||||
wlr_scene_node_lower_to_bottom(&ssd->tree->node);
|
||||
ssd->titlebar.height = view->server->theme->titlebar_height;
|
||||
ssd_shadow_create(ssd);
|
||||
|
|
@ -265,7 +267,8 @@ ssd_destroy(struct ssd *ssd)
|
|||
/* Maybe reset hover view */
|
||||
struct view *view = ssd->view;
|
||||
struct server *server = view->server;
|
||||
if (server->hovered_button && server->hovered_button->base.view == view) {
|
||||
if (server->hovered_button && node_view_from_node(
|
||||
server->hovered_button->node) == view) {
|
||||
server->hovered_button = NULL;
|
||||
}
|
||||
|
||||
|
|
@ -343,18 +346,6 @@ ssd_enable_keybind_inhibit_indicator(struct ssd *ssd, bool enable)
|
|||
wlr_scene_rect_set_color(ssd->border.subtrees[SSD_ACTIVE].top, color);
|
||||
}
|
||||
|
||||
enum lab_node_type
|
||||
ssd_part_get_type(const struct ssd_part *part)
|
||||
{
|
||||
return part ? part->type : LAB_NODE_NONE;
|
||||
}
|
||||
|
||||
struct view *
|
||||
ssd_part_get_view(const struct ssd_part *part)
|
||||
{
|
||||
return part ? part->view : NULL;
|
||||
}
|
||||
|
||||
bool
|
||||
ssd_debug_is_root_node(const struct ssd *ssd, struct wlr_scene_node *node)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue