From 89f11d1e24826d2b20695a49e250428c819e4409 Mon Sep 17 00:00:00 2001 From: Zedhugh Chen Date: Tue, 28 Jul 2026 05:46:15 +0800 Subject: [PATCH] =?UTF-8?q?feat(tray):=20tray=5Finit=20=E4=BC=A0=E5=85=A5?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E9=A2=9C=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/x11/backend.c | 10 +++++++++- src/backend/x11/tray.c | 28 ++++++---------------------- src/backend/x11/tray.h | 15 ++++++++------- 3 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/backend/x11/backend.c b/src/backend/x11/backend.c index eec744d..4120203 100644 --- a/src/backend/x11/backend.c +++ b/src/backend/x11/backend.c @@ -848,7 +848,15 @@ backend_bar_window_t backend_create_bar_window( fatal("cannot create cairo context: %s", cairo_status_to_string(statue)); } - if (enable_tray) tray_init(backend, window_id, width, height); + if (enable_tray) { + tray_host_window_t host_window = { + .window = window_id, + .width = width, + .height = height, + .bg_pixel = bg_pixel, + }; + tray_init(backend, host_window); + } return (backend_bar_window_t){ .window_id = window_id, diff --git a/src/backend/x11/tray.c b/src/backend/x11/tray.c index 495731d..9cadaee 100644 --- a/src/backend/x11/tray.c +++ b/src/backend/x11/tray.c @@ -238,12 +238,6 @@ static bool tray_intern_selection_atom(tray_host_t *tray, backend_t *backend) { return true; } -typedef struct tray_host_window_t { - xcb_window_t window; - int32_t width; - int32_t height; -} tray_host_window_t; - static bool tray_create_container_window( tray_host_t *tray, backend_t *backend, @@ -266,7 +260,7 @@ static bool tray_create_container_window( XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK | XCB_CW_COLORMAP; xcb_create_window_value_list_t value_list = { - .background_pixel = 0, + .background_pixel = host_window.bg_pixel, .border_pixel = 0, .override_redirect = true, .event_mask = @@ -360,12 +354,7 @@ static void tray_broadcast_manager(tray_host_t *tray, backend_t *backend) { xcb_send_event(conn, false, root, event_mask, (char *)&event); } -void tray_init( - backend_t *backend, - xcb_window_t host_window, - int32_t host_width, - int32_t host_height -) { +void tray_init(backend_t *backend, tray_host_window_t host_window) { auto tray = get_tray_host(backend); if (!tray) { tray = p_new(tray_host_t, 1); @@ -376,12 +365,7 @@ void tray_init( if (!tray_intern_selection_atom(tray, backend)) return; - tray_host_window_t host_window_params = { - .window = host_window, - .width = host_width, - .height = host_height - }; - if (!tray_create_container_window(tray, backend, host_window_params)) return; + if (!tray_create_container_window(tray, backend, host_window)) return; if (!tray_take_selection_owner(tray, backend)) { tray_cleanup(backend); return; @@ -389,11 +373,11 @@ void tray_init( tray->enabled = true; tray->initialized = true; - tray->host_window = host_window; - tray->icon_size = host_height; + tray->host_window = host_window.window; + tray->icon_size = host_window.height; tray_broadcast_manager(tray, backend); - tray_layout_icons(backend, host_width); + tray_layout_icons(backend, host_window.width); xcb_flush(backend->conn); } diff --git a/src/backend/x11/tray.h b/src/backend/x11/tray.h index 71b3454..3f4584f 100644 --- a/src/backend/x11/tray.h +++ b/src/backend/x11/tray.h @@ -9,13 +9,14 @@ extern const tray_api_t tray_api; typedef struct backend_t backend_t; -/* TODO: 添加窗口背景色 */ -void tray_init( - backend_t *backend, - xcb_window_t host_window, - int32_t host_width, - int32_t host_height -); +typedef struct tray_host_window_t { + xcb_window_t window; + int32_t width; + int32_t height; + uint32_t bg_pixel; +} tray_host_window_t; + +void tray_init(backend_t *backend, tray_host_window_t host_window); void tray_cleanup(backend_t *backend); bool tray_handle_client_message(