wayland: fix button background color mismatch with titlebar

When the titlebar is rendered into the parent frame buffer (fallback
for undersized titlebar child), buttons sampled their background
color from the stale titlebar child buffer. This caused color
mismatch in inactive state or after theme changes.

Fix: detect when the titlebar child is too small and sample the
button background from the parent frame buffer instead.
This commit is contained in:
lkn 2026-06-25 07:51:21 +02:00
parent db96843a2f
commit 72d6e31f24
1 changed files with 12 additions and 1 deletions

View File

@ -911,9 +911,12 @@ wl_frame_paint_button(WCoreWindow *button, WTexture *texture,
if (!icon)
return;
struct wl_frame_buf *parent_fb = frame_buf_find(fwin->core->window);
struct wl_frame_buf *tb_fb = fwin->titlebar ? frame_buf_find(fwin->titlebar->window) : NULL;
uint32_t bg_pixel = 0xFF333333;
if (tb_fb && tb_fb->image) {
/* Sample button background from the titlebar buffer, or from the
* parent frame buffer if the titlebar was rendered there (fallback). */
if (tb_fb && tb_fb->image && tb_fb->width >= btn_fb->rel_x + bw) {
uint32_t *tb_data = pixman_image_get_data(tb_fb->image);
int tb_stride = pixman_image_get_stride(tb_fb->image) / 4;
int sample_y = btn_fb->rel_y + bh / 2;
@ -921,6 +924,14 @@ wl_frame_paint_button(WCoreWindow *button, WTexture *texture,
if (sample_y >= 0 && sample_y < tb_fb->height &&
sample_x >= 0 && sample_x < tb_fb->width)
bg_pixel = tb_data[sample_y * tb_stride + sample_x];
} else if (parent_fb && parent_fb->image) {
uint32_t *p_data = pixman_image_get_data(parent_fb->image);
int p_stride = pixman_image_get_stride(parent_fb->image) / 4;
int sample_y = btn_fb->rel_y + bh / 2;
int sample_x = btn_fb->rel_x + bw / 2;
if (sample_y >= 0 && sample_y < parent_fb->height &&
sample_x >= 0 && sample_x < parent_fb->width)
bg_pixel = p_data[sample_y * p_stride + sample_x];
}
uint32_t fg_pixel = 0xFF000000 | ((color >> 16 & 0xFF) << 16) |