Replace multi_rect with lab_scene_rect

lab_scene_rect accepts the arbitrary number of borders and a background
color.
This commit is contained in:
tokyo4j 2025-06-09 16:27:17 +09:00 committed by Hiroaki Yamamoto
parent 4cc6b354b0
commit ffd400503e
12 changed files with 187 additions and 140 deletions

View file

@ -3,41 +3,9 @@
#define LABWC_GRAPHIC_HELPERS_H
#include <cairo.h>
#include <wayland-server-core.h>
struct wlr_scene_tree;
struct wlr_scene_rect;
struct wlr_fbox;
struct multi_rect {
struct wlr_scene_tree *tree;
int line_width; /* read-only */
/* Private */
struct wlr_scene_rect *top[3];
struct wlr_scene_rect *bottom[3];
struct wlr_scene_rect *left[3];
struct wlr_scene_rect *right[3];
struct wl_listener destroy;
};
/**
* Create a new multi_rect.
* A multi_rect consists of 3 nested rectangular outlines.
* Each of the rectangular outlines is using the same @line_width
* but its own color based on the @colors argument.
*
* The multi-rect can be positioned by positioning multi_rect->tree->node.
*
* It can be destroyed by destroying its tree node (or one of its
* parent nodes). Once the tree node has been destroyed the struct
* will be free'd automatically.
*/
struct multi_rect *multi_rect_create(struct wlr_scene_tree *parent,
float *colors[3], int line_width);
void multi_rect_set_size(struct multi_rect *rect, int width, int height);
/**
* Sets the cairo color.
* Splits a float[4] single color array into its own arguments

View file

@ -0,0 +1,40 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LABWC_LAB_SCENE_RECT_H
#define LABWC_LAB_SCENE_RECT_H
#include <wayland-server-core.h>
struct wlr_scene_tree;
struct lab_scene_rect_options {
float **border_colors;
int nr_borders;
int border_width;
float *bg_color; /* can be NULL */
int width;
int height;
};
struct lab_scene_rect {
struct wlr_scene_tree *tree;
int border_width;
int nr_borders;
struct border_scene *borders;
struct wlr_scene_rect *fill;
struct wl_listener node_destroy;
};
/**
* Create a new rectangle with borders.
*
* The rectangle can be positioned by positioning border_rect->tree->node.
*
* It can be destroyed by destroying its tree node (or one of its parent nodes).
* Once the tree node has been destroyed the struct will be free'd automatically.
*/
struct lab_scene_rect *lab_scene_rect_create(struct wlr_scene_tree *parent,
struct lab_scene_rect_options *opts);
void lab_scene_rect_set_size(struct lab_scene_rect *rect, int width, int height);
#endif /* LABWC_LAB_SCENE_RECT_H */

View file

@ -392,7 +392,7 @@ struct server {
struct wlr_scene_node *preview_node;
struct wlr_scene_tree *preview_parent;
struct wlr_scene_node *preview_anchor;
struct multi_rect *preview_outline;
struct lab_scene_rect *preview_outline;
} osd_state;
struct theme *theme;

View file

@ -7,6 +7,7 @@
#include "regions.h"
#include "view.h"
/* TODO: replace this with single lab_scene_rect */
struct overlay_rect {
struct wlr_scene_tree *tree;
@ -14,7 +15,7 @@ struct overlay_rect {
struct wlr_scene_rect *bg_rect;
bool border_enabled;
struct multi_rect *border_rect;
struct lab_scene_rect *border_rect;
};
struct overlay {

View file

@ -264,7 +264,7 @@ struct view {
} resize_indicator;
struct resize_outlines {
struct wlr_box view_geo;
struct multi_rect *rect;
struct lab_scene_rect *rect;
} resize_outlines;
struct mappable mappable;