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

@ -8,6 +8,7 @@
#include <wlr/util/log.h>
#include "common/list.h"
#include "common/mem.h"
#include "config/keybind.h"
#include "config/rcxml.h"
uint32_t
@ -103,60 +104,6 @@ mousebind_event_from_str(const char *str)
return MOUSE_ACTION_NONE;
}
static enum ssd_part_type
context_from_str(const char *str)
{
if (!strcasecmp(str, "Close")) {
return LAB_SSD_BUTTON_CLOSE;
} else if (!strcasecmp(str, "Maximize")) {
return LAB_SSD_BUTTON_MAXIMIZE;
} else if (!strcasecmp(str, "Iconify")) {
return LAB_SSD_BUTTON_ICONIFY;
} else if (!strcasecmp(str, "WindowMenu")) {
return LAB_SSD_BUTTON_WINDOW_MENU;
} else if (!strcasecmp(str, "Icon")) {
return LAB_SSD_BUTTON_WINDOW_ICON;
} else if (!strcasecmp(str, "Shade")) {
return LAB_SSD_BUTTON_SHADE;
} else if (!strcasecmp(str, "AllDesktops")) {
return LAB_SSD_BUTTON_OMNIPRESENT;
} else if (!strcasecmp(str, "Titlebar")) {
return LAB_SSD_PART_TITLEBAR;
} else if (!strcasecmp(str, "Title")) {
return LAB_SSD_PART_TITLE;
} else if (!strcasecmp(str, "TLCorner")) {
return LAB_SSD_PART_CORNER_TOP_LEFT;
} else if (!strcasecmp(str, "TRCorner")) {
return LAB_SSD_PART_CORNER_TOP_RIGHT;
} else if (!strcasecmp(str, "BRCorner")) {
return LAB_SSD_PART_CORNER_BOTTOM_RIGHT;
} else if (!strcasecmp(str, "BLCorner")) {
return LAB_SSD_PART_CORNER_BOTTOM_LEFT;
} else if (!strcasecmp(str, "Border")) {
return LAB_SSD_PART_BORDER;
} else if (!strcasecmp(str, "Top")) {
return LAB_SSD_PART_TOP;
} else if (!strcasecmp(str, "Right")) {
return LAB_SSD_PART_RIGHT;
} else if (!strcasecmp(str, "Bottom")) {
return LAB_SSD_PART_BOTTOM;
} else if (!strcasecmp(str, "Left")) {
return LAB_SSD_PART_LEFT;
} else if (!strcasecmp(str, "Frame")) {
return LAB_SSD_FRAME;
} else if (!strcasecmp(str, "Client")) {
return LAB_SSD_CLIENT;
} else if (!strcasecmp(str, "Desktop")) {
return LAB_SSD_ROOT;
} else if (!strcasecmp(str, "Root")) {
return LAB_SSD_ROOT;
} else if (!strcasecmp(str, "All")) {
return LAB_SSD_ALL;
}
wlr_log(WLR_ERROR, "unknown mouse context (%s)", str);
return LAB_SSD_NONE;
}
bool
mousebind_the_same(struct mousebind *a, struct mousebind *b)
{
@ -176,8 +123,8 @@ mousebind_create(const char *context)
return NULL;
}
struct mousebind *m = znew(*m);
m->context = context_from_str(context);
if (m->context != LAB_SSD_NONE) {
m->context = node_type_parse(context);
if (m->context != LAB_NODE_NONE) {
wl_list_append(&rc.mousebinds, &m->link);
}
wl_list_init(&m->actions);

View file

@ -35,6 +35,7 @@
#include "labwc.h"
#include "osd.h"
#include "regions.h"
#include "ssd.h"
#include "view.h"
#include "window-rules.h"
#include "workspaces.h"
@ -126,34 +127,34 @@ fill_section(const char *content, struct wl_list *list, uint32_t *found_buttons)
if (string_null_or_empty(identifier)) {
continue;
}
enum ssd_part_type type = LAB_SSD_NONE;
enum lab_node_type type = LAB_NODE_NONE;
if (!strcmp(identifier, "icon")) {
#if HAVE_LIBSFDO
type = LAB_SSD_BUTTON_WINDOW_ICON;
type = LAB_NODE_BUTTON_WINDOW_ICON;
#else
wlr_log(WLR_ERROR, "libsfdo is not linked. "
"Replacing 'icon' in titlebar layout with 'menu'.");
type = LAB_SSD_BUTTON_WINDOW_MENU;
type = LAB_NODE_BUTTON_WINDOW_MENU;
#endif
} else if (!strcmp(identifier, "menu")) {
type = LAB_SSD_BUTTON_WINDOW_MENU;
type = LAB_NODE_BUTTON_WINDOW_MENU;
} else if (!strcmp(identifier, "iconify")) {
type = LAB_SSD_BUTTON_ICONIFY;
type = LAB_NODE_BUTTON_ICONIFY;
} else if (!strcmp(identifier, "max")) {
type = LAB_SSD_BUTTON_MAXIMIZE;
type = LAB_NODE_BUTTON_MAXIMIZE;
} else if (!strcmp(identifier, "close")) {
type = LAB_SSD_BUTTON_CLOSE;
type = LAB_NODE_BUTTON_CLOSE;
} else if (!strcmp(identifier, "shade")) {
type = LAB_SSD_BUTTON_SHADE;
type = LAB_NODE_BUTTON_SHADE;
} else if (!strcmp(identifier, "desk")) {
type = LAB_SSD_BUTTON_OMNIPRESENT;
type = LAB_NODE_BUTTON_OMNIPRESENT;
} else {
wlr_log(WLR_ERROR, "invalid titleLayout identifier '%s'",
identifier);
continue;
}
assert(type != LAB_SSD_NONE);
assert(type != LAB_NODE_NONE);
/* We no longer need this check, but let's keep it just in case */
if (*found_buttons & (1 << type)) {