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

@ -0,0 +1,63 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LABWC_NODE_TYPE_H
#define LABWC_NODE_TYPE_H
#include "common/edge.h"
/*
* In labwc, "node type" indicates the role of a wlr_scene_node in the
* overall desktop. It also maps more-or-less to the openbox concept of
* "context" (as used when defining mouse bindings).
*
* Some types (BUTTON, BORDER, etc.) refer to groups or categories of
* other node types rather than individual nodes. These categories are
* defined as ranges (e.g. BUTTON means anything from BUTTON_FIRST to
* BUTTON_LAST), therefore order is significant.
*
* Be sure to keep node_type_contains() in sync with any changes!
*/
enum lab_node_type {
LAB_NODE_NONE = 0,
LAB_NODE_BUTTON_CLOSE = 1,
LAB_NODE_BUTTON_MAXIMIZE,
LAB_NODE_BUTTON_ICONIFY,
LAB_NODE_BUTTON_WINDOW_ICON,
LAB_NODE_BUTTON_WINDOW_MENU,
LAB_NODE_BUTTON_SHADE,
LAB_NODE_BUTTON_OMNIPRESENT,
LAB_NODE_BUTTON_FIRST = LAB_NODE_BUTTON_CLOSE,
LAB_NODE_BUTTON_LAST = LAB_NODE_BUTTON_OMNIPRESENT,
LAB_NODE_BUTTON,
LAB_NODE_TITLEBAR,
LAB_NODE_TITLE,
LAB_NODE_CORNER_TOP_LEFT,
LAB_NODE_CORNER_TOP_RIGHT,
LAB_NODE_CORNER_BOTTOM_RIGHT,
LAB_NODE_CORNER_BOTTOM_LEFT,
LAB_NODE_BORDER_TOP,
LAB_NODE_BORDER_RIGHT,
LAB_NODE_BORDER_BOTTOM,
LAB_NODE_BORDER_LEFT,
LAB_NODE_BORDER,
LAB_NODE_CLIENT,
LAB_NODE_FRAME,
LAB_NODE_ROOT,
LAB_NODE_MENU,
LAB_NODE_OSD,
LAB_NODE_LAYER_SURFACE,
LAB_NODE_LAYER_SUBSURFACE,
LAB_NODE_UNMANAGED,
LAB_NODE_ALL,
};
enum lab_node_type node_type_parse(const char *context);
bool node_type_contains(enum lab_node_type whole, enum lab_node_type part);
enum lab_edge node_type_to_edges(enum lab_node_type type);
#endif /* LABWC_NODE_TYPE_H */

View file

@ -2,9 +2,9 @@
#ifndef LABWC_MOUSEBIND_H
#define LABWC_MOUSEBIND_H
#include <stdbool.h>
#include <wayland-util.h>
#include "ssd.h"
#include "config/keybind.h"
#include "common/node-type.h"
enum mouse_event {
MOUSE_ACTION_NONE = 0,
@ -25,7 +25,7 @@ enum direction {
};
struct mousebind {
enum ssd_part_type context;
enum lab_node_type context;
/* ex: BTN_LEFT, BTN_RIGHT from linux/input_event_codes.h */
uint32_t button;

View file

@ -10,8 +10,8 @@
#include "common/border.h"
#include "common/buf.h"
#include "common/font.h"
#include "common/node-type.h"
#include "config/types.h"
#include "ssd.h"
#define BUTTON_MAP_MAX 16
@ -48,7 +48,7 @@ struct button_map_entry {
};
struct title_button {
enum ssd_part_type type;
enum lab_node_type type;
struct wl_list link;
};

View file

@ -4,7 +4,7 @@
#include <wlr/types/wlr_cursor.h>
#include "common/edge.h"
#include "ssd.h"
#include "common/node-type.h"
struct view;
struct seat;
@ -32,7 +32,7 @@ struct cursor_context {
struct view *view;
struct wlr_scene_node *node;
struct wlr_surface *surface;
enum ssd_part_type type;
enum lab_node_type type;
double sx, sy;
};

View file

@ -3,7 +3,7 @@
#define LABWC_SSD_INTERNAL_H
#include <wlr/util/box.h>
#include "ssd.h"
#include "common/border.h"
#include "theme.h"
#include "view.h"
@ -142,7 +142,7 @@ struct ssd {
* the cursor.
*/
struct ssd_part {
enum ssd_part_type type;
enum lab_node_type type;
struct view *view;
/* This part represented in scene graph */
@ -183,10 +183,10 @@ struct wlr_buffer;
struct wlr_scene_tree;
/* SSD internal helpers to create various SSD elements */
struct ssd_part *attach_ssd_part(enum ssd_part_type type, struct view *view,
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,
enum ssd_part_type type, struct wlr_scene_tree *parent,
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);

View file

@ -3,7 +3,7 @@
#define LABWC_SSD_H
#include "common/border.h"
#include "common/edge.h"
#include "common/node-type.h"
#include "config/types.h"
enum ssd_active_state {
@ -22,51 +22,6 @@ struct wlr_cursor;
*/
#define SSD_SHADOW_INSET 0.3
/*
* Sequence these according to the order they should be processed for
* press and hover events. Bear in mind that some of their respective
* interactive areas overlap, so for example buttons need to come before title.
*/
enum ssd_part_type {
LAB_SSD_NONE = 0,
LAB_SSD_BUTTON_CLOSE = 1,
LAB_SSD_BUTTON_MAXIMIZE,
LAB_SSD_BUTTON_ICONIFY,
LAB_SSD_BUTTON_WINDOW_ICON,
LAB_SSD_BUTTON_WINDOW_MENU,
LAB_SSD_BUTTON_SHADE,
LAB_SSD_BUTTON_OMNIPRESENT,
/* only for internal use */
LAB_SSD_BUTTON_FIRST = LAB_SSD_BUTTON_CLOSE,
LAB_SSD_BUTTON_LAST = LAB_SSD_BUTTON_OMNIPRESENT,
LAB_SSD_BUTTON,
LAB_SSD_PART_TITLEBAR,
LAB_SSD_PART_TITLE,
LAB_SSD_PART_CORNER_TOP_LEFT,
LAB_SSD_PART_CORNER_TOP_RIGHT,
LAB_SSD_PART_CORNER_BOTTOM_RIGHT,
LAB_SSD_PART_CORNER_BOTTOM_LEFT,
LAB_SSD_PART_TOP,
LAB_SSD_PART_RIGHT,
LAB_SSD_PART_BOTTOM,
LAB_SSD_PART_LEFT,
LAB_SSD_PART_BORDER,
LAB_SSD_CLIENT,
LAB_SSD_FRAME,
LAB_SSD_ROOT,
LAB_SSD_MENU,
LAB_SSD_OSD,
LAB_SSD_LAYER_SURFACE,
LAB_SSD_LAYER_SUBSURFACE,
LAB_SSD_UNMANAGED,
LAB_SSD_ALL,
LAB_SSD_END_MARKER
};
/* Forward declare arguments */
struct ssd;
struct ssd_hover_state;
@ -101,7 +56,7 @@ struct ssd_hover_state *ssd_hover_state_new(void);
void ssd_update_button_hover(struct wlr_scene_node *node,
struct ssd_hover_state *hover_state);
enum ssd_part_type ssd_part_get_type(const struct ssd_part *part);
enum lab_node_type ssd_part_get_type(const struct ssd_part *part);
struct view *ssd_part_get_view(const struct ssd_part *part);
/* Public SSD helpers */
@ -110,10 +65,8 @@ struct view *ssd_part_get_view(const struct ssd_part *part);
* Returns a part type that represents a mouse context like "Top", "Left" and
* "TRCorner" when the cursor is on the window border or resizing handle.
*/
enum ssd_part_type ssd_get_resizing_type(const struct ssd *ssd,
enum lab_node_type ssd_get_resizing_type(const struct ssd *ssd,
struct wlr_cursor *cursor);
enum lab_edge ssd_resize_edges(enum ssd_part_type type);
bool ssd_part_contains(enum ssd_part_type whole, enum ssd_part_type candidate);
enum lab_ssd_mode ssd_mode_parse(const char *mode);
/* TODO: clean up / update */

View file

@ -10,7 +10,7 @@
#include <cairo.h>
#include <wlr/render/wlr_renderer.h>
#include "ssd.h"
#include "common/node-type.h"
struct lab_img;
@ -90,7 +90,7 @@ struct theme {
struct theme_background title_bg;
/* TODO: add toggled/hover/pressed/disabled colors for buttons */
float button_colors[LAB_SSD_BUTTON_LAST + 1][4];
float button_colors[LAB_NODE_BUTTON_LAST + 1][4];
float border_color[4];
float toggled_keybinds_color[4];
@ -109,7 +109,7 @@ struct theme {
* Elements in buttons[0] are all NULL since LAB_SSD_BUTTON_FIRST is 1.
*/
struct lab_img *button_imgs
[LAB_SSD_BUTTON_LAST + 1][LAB_BS_ALL + 1];
[LAB_NODE_BUTTON_LAST + 1][LAB_BS_ALL + 1];
/*
* The titlebar background is specified as a cairo_pattern