From 5a4d989a782c0da540d1f17b074bf65a2279d258 Mon Sep 17 00:00:00 2001 From: lkn Date: Sat, 23 May 2026 14:16:44 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20titlebar=20button=20rendering=20?= =?UTF-8?q?=E2=80=94=20proper=20colors=20and=20bevel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Background: matches titlebar background (sampled) - Foreground: uses title text color (the color parameter) - Pressed state: swaps fg/bg (inverted colors) - Border: raised bevel when normal, sunken when pushed - Icon pixels rendered in fg color (not raw XPM colors) --- src/backend/wayland/wl_backend.c | 42 +++++++++++++++++++------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/backend/wayland/wl_backend.c b/src/backend/wayland/wl_backend.c index cbe958c..56a6aec 100644 --- a/src/backend/wayland/wl_backend.c +++ b/src/backend/wayland/wl_backend.c @@ -7581,7 +7581,7 @@ static void wl_noop_frame_update_texture(struct WFrameWindow *fwin) { (void)fwin static void wl_frame_paint_button(WCoreWindow *button, WTexture *texture, unsigned long color, WPixmap *image, int pushed) { - (void)texture; (void)color; (void)image; + (void)texture; (void)image; WFrameWindow *fwin = (WFrameWindow *)button->descriptor.parent; if (!fwin || !fwin->core) return; @@ -7609,11 +7609,10 @@ static void wl_frame_paint_button(WCoreWindow *button, WTexture *texture, if (!icon) return; - /* Clear button buffer with titlebar background */ + /* Get titlebar background color */ 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 background color from titlebar at button position */ 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; @@ -7622,13 +7621,28 @@ static void wl_frame_paint_button(WCoreWindow *button, WTexture *texture, sample_x >= 0 && sample_x < tb_fb->width) bg_pixel = tb_data[sample_y * tb_stride + sample_x]; } + + /* Foreground = title text color; when pushed, swap fg/bg */ + uint32_t fg_pixel = 0xFF000000 | ((color >> 16 & 0xFF) << 16) | + ((color >> 8 & 0xFF) << 8) | (color & 0xFF); + uint32_t fill_bg = pushed ? fg_pixel : bg_pixel; + uint32_t fill_fg = pushed ? bg_pixel : fg_pixel; + uint32_t *dst = pixman_image_get_data(btn_fb->image); int dst_stride = pixman_image_get_stride(btn_fb->image) / 4; + + /* Fill background */ for (int y = 0; y < bh; y++) for (int x = 0; x < bw; x++) - dst[y * dst_stride + x] = bg_pixel; + dst[y * dst_stride + x] = fill_bg; - /* Blit icon centered in button area */ + /* Draw border bevel (raised when normal, sunken when pushed) */ + uint32_t hi = pushed ? 0xFF222222 : 0xFFDDDDDD; + uint32_t lo = pushed ? 0xFFDDDDDD : 0xFF222222; + for (int x = 0; x < bw; x++) { dst[x] = hi; dst[(bh-1) * dst_stride + x] = lo; } + for (int y = 0; y < bh; y++) { dst[y * dst_stride] = hi; dst[y * dst_stride + bw - 1] = lo; } + + /* Blit icon centered, using fill_fg color for opaque pixels */ int ix = (bw - icon->width) / 2 + (pushed ? 1 : 0); int iy = (bh - icon->height) / 2 + (pushed ? 1 : 0); @@ -7639,19 +7653,13 @@ static void wl_frame_paint_button(WCoreWindow *button, WTexture *texture, for (int x = 0; x < icon->width; x++) { int dx = ix + x; if (dx < 0 || dx >= bw) continue; - unsigned char r, g, b, a; - if (icon->format == RRGBAFormat) { - int off = (y * icon->width + x) * 4; - r = icon->data[off]; g = icon->data[off+1]; - b = icon->data[off+2]; a = icon->data[off+3]; - } else { - int off = (y * icon->width + x) * 3; - r = icon->data[off]; g = icon->data[off+1]; - b = icon->data[off+2]; a = 255; - } + unsigned char a; + if (icon->format == RRGBAFormat) + a = icon->data[(y * icon->width + x) * 4 + 3]; + else + a = 255; if (a == 0) continue; - dst_row[dx] = ((uint32_t)a << 24) | ((uint32_t)r << 16) | - ((uint32_t)g << 8) | (uint32_t)b; + dst_row[dx] = fill_fg; } }