common: add node-type.c/h (renaming ssd_part_type to lab_node_type)

ssd_part_type contains several node types that are not actually part of
server-side decorations (ROOT, MENU, OSD, etc.)

Rename it accordingly and move it to a common location, along with some
related conversion/comparison functions.
This commit is contained in:
John Lindgren 2025-09-03 05:08:52 -04:00
parent 502473f343
commit 1188534876
28 changed files with 345 additions and 315 deletions

View file

@ -3,12 +3,12 @@
#include <wlr/types/wlr_scene.h>
#include <wlr/util/box.h>
#include <wlr/util/log.h>
#include "common/macros.h"
#include "config/rcxml.h"
#include "labwc.h"
#include "resize-indicator.h"
#include "resize-outlines.h"
#include "scaled-buffer/scaled-font-buffer.h"
#include "ssd.h"
#include "theme.h"
#include "view.h"

View file

@ -5,6 +5,7 @@
#include "common/macros.h"
#include "common/scene-helpers.h"
#include "labwc.h"
#include "ssd.h"
#include "ssd-internal.h"
#include "theme.h"
#include "view.h"

View file

@ -32,7 +32,7 @@ handle_node_destroy(struct wl_listener *listener, void *data)
* to is destroyed.
*/
static void
init_ssd_part(struct ssd_part *part, enum ssd_part_type type,
init_ssd_part(struct ssd_part *part, enum lab_node_type type,
struct view *view, struct wlr_scene_node *node)
{
part->type = type;
@ -45,17 +45,17 @@ init_ssd_part(struct ssd_part *part, enum ssd_part_type type,
}
struct ssd_part *
attach_ssd_part(enum ssd_part_type type, struct view *view,
attach_ssd_part(enum lab_node_type type, struct view *view,
struct wlr_scene_node *node)
{
assert(!ssd_part_contains(LAB_SSD_BUTTON, type));
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 ssd_part_type type,
attach_ssd_part_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)
@ -63,7 +63,7 @@ attach_ssd_part_button(struct wl_list *button_parts, enum ssd_part_type type,
struct wlr_scene_tree *root = wlr_scene_tree_create(parent);
wlr_scene_node_set_position(&root->node, x, y);
assert(ssd_part_contains(LAB_SSD_BUTTON, type));
assert(node_type_contains(LAB_NODE_BUTTON, type));
struct ssd_part_button *button = znew(*button);
init_ssd_part(&button->base, type, view, &root->node);
wl_list_append(button_parts, &button->link);
@ -86,7 +86,7 @@ attach_ssd_part_button(struct wl_list *button_parts, enum ssd_part_type type,
*/
int icon_padding = button_width / 10;
if (type == LAB_SSD_BUTTON_WINDOW_ICON) {
if (type == LAB_NODE_BUTTON_WINDOW_ICON) {
struct scaled_icon_buffer *icon_buffer =
scaled_icon_buffer_create(root, view->server,
button_width - 2 * icon_padding, button_height);
@ -120,7 +120,7 @@ attach_ssd_part_button(struct wl_list *button_parts, enum ssd_part_type type,
struct ssd_part_button *
button_try_from_ssd_part(struct ssd_part *part)
{
if (ssd_part_contains(LAB_SSD_BUTTON, part->type)) {
if (node_type_contains(LAB_NODE_BUTTON, part->type)) {
return (struct ssd_part_button *)part;
}
return NULL;

View file

@ -6,6 +6,7 @@
#include "buffer.h"
#include "config/rcxml.h"
#include "labwc.h"
#include "ssd.h"
#include "ssd-internal.h"
#include "theme.h"
#include "view.h"

View file

@ -16,12 +16,13 @@
#include "scaled-buffer/scaled-font-buffer.h"
#include "scaled-buffer/scaled-icon-buffer.h"
#include "scaled-buffer/scaled-img-buffer.h"
#include "ssd.h"
#include "ssd-internal.h"
#include "theme.h"
#include "view.h"
static void set_squared_corners(struct ssd *ssd, bool enable);
static void set_alt_button_icon(struct ssd *ssd, enum ssd_part_type type, bool enable);
static void set_alt_button_icon(struct ssd *ssd, enum lab_node_type type, bool enable);
static void update_visible_buttons(struct ssd *ssd);
void
@ -33,7 +34,7 @@ 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_SSD_PART_TITLEBAR, view, &ssd->titlebar.tree->node);
attach_ssd_part(LAB_NODE_TITLEBAR, view, &ssd->titlebar.tree->node);
enum ssd_active_state active;
FOR_EACH_ACTIVE_STATE(active) {
@ -77,7 +78,7 @@ ssd_titlebar_create(struct ssd *ssd)
subtree->tree, theme->titlebar_height,
theme->window[active].titlebar_pattern);
assert(subtree->title);
attach_ssd_part(LAB_SSD_PART_TITLE,
attach_ssd_part(LAB_NODE_TITLE,
view, &subtree->title->scene_buffer->node);
/* Buttons */
@ -115,7 +116,7 @@ ssd_titlebar_create(struct ssd *ssd)
bool maximized = view->maximized == VIEW_AXIS_BOTH;
bool squared = ssd_should_be_squared(ssd);
if (maximized) {
set_alt_button_icon(ssd, LAB_SSD_BUTTON_MAXIMIZE, true);
set_alt_button_icon(ssd, LAB_NODE_BUTTON_MAXIMIZE, true);
ssd->state.was_maximized = true;
}
if (squared) {
@ -124,11 +125,11 @@ ssd_titlebar_create(struct ssd *ssd)
set_squared_corners(ssd, maximized || squared);
if (view->shaded) {
set_alt_button_icon(ssd, LAB_SSD_BUTTON_SHADE, true);
set_alt_button_icon(ssd, LAB_NODE_BUTTON_SHADE, true);
}
if (view->visible_on_all_workspaces) {
set_alt_button_icon(ssd, LAB_SSD_BUTTON_OMNIPRESENT, true);
set_alt_button_icon(ssd, LAB_NODE_BUTTON_OMNIPRESENT, true);
}
}
@ -189,7 +190,7 @@ set_squared_corners(struct ssd *ssd, bool enable)
}
static void
set_alt_button_icon(struct ssd *ssd, enum ssd_part_type type, bool enable)
set_alt_button_icon(struct ssd *ssd, enum lab_node_type type, bool enable)
{
enum ssd_active_state active;
FOR_EACH_ACTIVE_STATE(active) {
@ -281,19 +282,19 @@ ssd_titlebar_update(struct ssd *ssd)
|| ssd->state.was_squared != squared) {
set_squared_corners(ssd, maximized || squared);
if (ssd->state.was_maximized != maximized) {
set_alt_button_icon(ssd, LAB_SSD_BUTTON_MAXIMIZE, maximized);
set_alt_button_icon(ssd, LAB_NODE_BUTTON_MAXIMIZE, maximized);
}
ssd->state.was_maximized = maximized;
ssd->state.was_squared = squared;
}
if (ssd->state.was_shaded != view->shaded) {
set_alt_button_icon(ssd, LAB_SSD_BUTTON_SHADE, view->shaded);
set_alt_button_icon(ssd, LAB_NODE_BUTTON_SHADE, view->shaded);
ssd->state.was_shaded = view->shaded;
}
if (ssd->state.was_omnipresent != view->visible_on_all_workspaces) {
set_alt_button_icon(ssd, LAB_SSD_BUTTON_OMNIPRESENT,
set_alt_button_icon(ssd, LAB_NODE_BUTTON_OMNIPRESENT,
view->visible_on_all_workspaces);
ssd->state.was_omnipresent = view->visible_on_all_workspaces;
}

View file

@ -6,6 +6,7 @@
* Copyright (C) Johan Malm 2020-2021
*/
#include "ssd.h"
#include <assert.h>
#include <strings.h>
#include <wlr/types/wlr_scene.h>
@ -85,12 +86,12 @@ ssd_max_extents(struct view *view)
* (generally rc.resize_corner_range, but clipped to view size) of the view
* bounds, so check the cursor against the view here.
*/
enum ssd_part_type
enum lab_node_type
ssd_get_resizing_type(const struct ssd *ssd, struct wlr_cursor *cursor)
{
struct view *view = ssd ? ssd->view : NULL;
if (!view || !cursor || !view->ssd_mode || view->fullscreen) {
return LAB_SSD_NONE;
return LAB_NODE_NONE;
}
struct wlr_box view_box = view->current;
@ -105,7 +106,7 @@ ssd_get_resizing_type(const struct ssd *ssd, struct wlr_cursor *cursor)
if (wlr_box_contains_point(&view_box, cursor->x, cursor->y)) {
/* A cursor in bounds of the view is never in an SSD context */
return LAB_SSD_NONE;
return LAB_NODE_NONE;
}
int corner_height = MAX(0, MIN(rc.resize_corner_range, view_box.height / 2));
@ -116,49 +117,24 @@ ssd_get_resizing_type(const struct ssd *ssd, struct wlr_cursor *cursor)
bool bottom = cursor->y > view_box.y + view_box.height - corner_height;
if (top && left) {
return LAB_SSD_PART_CORNER_TOP_LEFT;
return LAB_NODE_CORNER_TOP_LEFT;
} else if (top && right) {
return LAB_SSD_PART_CORNER_TOP_RIGHT;
return LAB_NODE_CORNER_TOP_RIGHT;
} else if (bottom && left) {
return LAB_SSD_PART_CORNER_BOTTOM_LEFT;
return LAB_NODE_CORNER_BOTTOM_LEFT;
} else if (bottom && right) {
return LAB_SSD_PART_CORNER_BOTTOM_RIGHT;
return LAB_NODE_CORNER_BOTTOM_RIGHT;
} else if (top) {
return LAB_SSD_PART_TOP;
return LAB_NODE_BORDER_TOP;
} else if (bottom) {
return LAB_SSD_PART_BOTTOM;
return LAB_NODE_BORDER_BOTTOM;
} else if (left) {
return LAB_SSD_PART_LEFT;
return LAB_NODE_BORDER_LEFT;
} else if (right) {
return LAB_SSD_PART_RIGHT;
return LAB_NODE_BORDER_RIGHT;
}
return LAB_SSD_NONE;
}
enum lab_edge
ssd_resize_edges(enum ssd_part_type type)
{
switch (type) {
case LAB_SSD_PART_TOP:
return LAB_EDGE_TOP;
case LAB_SSD_PART_RIGHT:
return LAB_EDGE_RIGHT;
case LAB_SSD_PART_BOTTOM:
return LAB_EDGE_BOTTOM;
case LAB_SSD_PART_LEFT:
return LAB_EDGE_LEFT;
case LAB_SSD_PART_CORNER_TOP_LEFT:
return LAB_EDGES_TOP_LEFT;
case LAB_SSD_PART_CORNER_TOP_RIGHT:
return LAB_EDGES_TOP_RIGHT;
case LAB_SSD_PART_CORNER_BOTTOM_RIGHT:
return LAB_EDGES_BOTTOM_RIGHT;
case LAB_SSD_PART_CORNER_BOTTOM_LEFT:
return LAB_EDGES_BOTTOM_LEFT;
default:
return LAB_EDGE_NONE;
}
return LAB_NODE_NONE;
}
struct ssd *
@ -169,7 +145,7 @@ ssd_create(struct view *view, bool active)
ssd->view = view;
ssd->tree = wlr_scene_tree_create(view->scene_tree);
attach_ssd_part(LAB_SSD_NONE, view, &ssd->tree->node);
attach_ssd_part(LAB_NODE_NONE, view, &ssd->tree->node);
wlr_scene_node_lower_to_bottom(&ssd->tree->node);
ssd->titlebar.height = view->server->theme->titlebar_height;
ssd_shadow_create(ssd);
@ -305,52 +281,6 @@ ssd_destroy(struct ssd *ssd)
free(ssd);
}
bool
ssd_part_contains(enum ssd_part_type whole, enum ssd_part_type candidate)
{
if (whole == candidate || whole == LAB_SSD_ALL) {
return true;
}
if (whole == LAB_SSD_BUTTON) {
return candidate >= LAB_SSD_BUTTON_CLOSE
&& candidate <= LAB_SSD_BUTTON_OMNIPRESENT;
}
if (whole == LAB_SSD_PART_TITLEBAR) {
return candidate >= LAB_SSD_BUTTON_CLOSE
&& candidate <= LAB_SSD_PART_TITLE;
}
if (whole == LAB_SSD_PART_TITLE) {
/* "Title" includes blank areas of "Titlebar" as well */
return candidate >= LAB_SSD_PART_TITLEBAR
&& candidate <= LAB_SSD_PART_TITLE;
}
if (whole == LAB_SSD_FRAME) {
return candidate >= LAB_SSD_BUTTON_CLOSE
&& candidate <= LAB_SSD_CLIENT;
}
if (whole == LAB_SSD_PART_BORDER) {
return candidate >= LAB_SSD_PART_CORNER_TOP_LEFT
&& candidate <= LAB_SSD_PART_LEFT;
}
if (whole == LAB_SSD_PART_TOP) {
return candidate == LAB_SSD_PART_CORNER_TOP_LEFT
|| candidate == LAB_SSD_PART_CORNER_TOP_RIGHT;
}
if (whole == LAB_SSD_PART_RIGHT) {
return candidate == LAB_SSD_PART_CORNER_TOP_RIGHT
|| candidate == LAB_SSD_PART_CORNER_BOTTOM_RIGHT;
}
if (whole == LAB_SSD_PART_BOTTOM) {
return candidate == LAB_SSD_PART_CORNER_BOTTOM_RIGHT
|| candidate == LAB_SSD_PART_CORNER_BOTTOM_LEFT;
}
if (whole == LAB_SSD_PART_LEFT) {
return candidate == LAB_SSD_PART_CORNER_TOP_LEFT
|| candidate == LAB_SSD_PART_CORNER_BOTTOM_LEFT;
}
return false;
}
enum lab_ssd_mode
ssd_mode_parse(const char *mode)
{
@ -421,10 +351,10 @@ ssd_hover_state_new(void)
return znew(struct ssd_hover_state);
}
enum ssd_part_type
enum lab_node_type
ssd_part_get_type(const struct ssd_part *part)
{
return part ? part->type : LAB_SSD_NONE;
return part ? part->type : LAB_NODE_NONE;
}
struct view *