ssd: allow arbitrary cairo pattern as titlebar background

The titlebar background is now first rendered to a 1px wide buffer,
then stretched horizontally. This allows vertical gradients to be used.
This commit is contained in:
John Lindgren 2025-04-22 12:20:15 -04:00
parent 54b236e027
commit 990706b081
3 changed files with 72 additions and 15 deletions

View file

@ -35,8 +35,8 @@ ssd_titlebar_create(struct ssd *ssd)
int width = view->current.width;
int corner_width = ssd_get_corner_width();
float *color;
struct wlr_scene_tree *parent;
struct wlr_buffer *titlebar_fill;
struct wlr_buffer *corner_top_left;
struct wlr_buffer *corner_top_right;
int active;
@ -49,7 +49,7 @@ ssd_titlebar_create(struct ssd *ssd)
parent = subtree->tree;
active = (subtree == &ssd->titlebar.active) ?
THEME_ACTIVE : THEME_INACTIVE;
color = theme->window[active].title_bg_color;
titlebar_fill = &theme->window[active].titlebar_fill->base;
corner_top_left = &theme->window[active].corner_top_left_normal->base;
corner_top_right = &theme->window[active].corner_top_right_normal->base;
wlr_scene_node_set_enabled(&parent->node, active);
@ -57,9 +57,8 @@ ssd_titlebar_create(struct ssd *ssd)
wl_list_init(&subtree->parts);
/* Background */
add_scene_rect(&subtree->parts, LAB_SSD_PART_TITLEBAR, parent,
MAX(width - corner_width * 2, 0), theme->titlebar_height,
corner_width, 0, color);
add_scene_buffer(&subtree->parts, LAB_SSD_PART_TITLEBAR, parent,
titlebar_fill, corner_width, 0);
add_scene_buffer(&subtree->parts, LAB_SSD_PART_TITLEBAR_CORNER_LEFT, parent,
corner_top_left, -rc.theme->border_width, -rc.theme->border_width);
add_scene_buffer(&subtree->parts, LAB_SSD_PART_TITLEBAR_CORNER_RIGHT, parent,
@ -151,7 +150,8 @@ set_squared_corners(struct ssd *ssd, bool enable)
FOR_EACH_STATE(ssd, subtree) {
part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLEBAR);
wlr_scene_node_set_position(part->node, x, 0);
wlr_scene_rect_set_size(wlr_scene_rect_from_node(part->node),
wlr_scene_buffer_set_dest_size(
wlr_scene_buffer_from_node(part->node),
MAX(width - 2 * x, 0), theme->titlebar_height);
part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLEBAR_CORNER_LEFT);
@ -299,8 +299,8 @@ ssd_titlebar_update(struct ssd *ssd)
int bg_offset = maximized || squared ? 0 : corner_width;
FOR_EACH_STATE(ssd, subtree) {
part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLEBAR);
wlr_scene_rect_set_size(
wlr_scene_rect_from_node(part->node),
wlr_scene_buffer_set_dest_size(
wlr_scene_buffer_from_node(part->node),
MAX(width - bg_offset * 2, 0), theme->titlebar_height);
x = theme->window_titlebar_padding_width;
@ -458,7 +458,7 @@ ssd_update_title(struct ssd *ssd)
bool title_unchanged = state->text && !strcmp(title, state->text);
const float *text_color;
const float *bg_color;
const float bg_color[4] = {0, 0, 0, 0}; /* ignored */
struct font *font = NULL;
struct ssd_part *part;
struct ssd_sub_tree *subtree;
@ -474,7 +474,6 @@ ssd_update_title(struct ssd *ssd)
THEME_ACTIVE : THEME_INACTIVE;
dstate = active ? &state->active : &state->inactive;
text_color = theme->window[active].label_text_color;
bg_color = theme->window[active].title_bg_color;
font = active ? &rc.font_activewindow : &rc.font_inactivewindow;
if (title_bg_width <= 0) {
@ -492,7 +491,9 @@ ssd_update_title(struct ssd *ssd)
if (!part) {
/* Initialize part and wlr_scene_buffer without attaching a buffer */
part = add_scene_part(&subtree->parts, LAB_SSD_PART_TITLE);
part->buffer = scaled_font_buffer_create(subtree->tree);
part->buffer = scaled_font_buffer_create_for_titlebar(
subtree->tree, theme->titlebar_height,
theme->window[active].titlebar_pattern);
if (part->buffer) {
part->node = &part->buffer->scene_buffer->node;
} else {