diff --git a/src/backend/x11/backend.c b/src/backend/x11/backend.c index d1c11d6..0ec2729 100644 --- a/src/backend/x11/backend.c +++ b/src/backend/x11/backend.c @@ -774,7 +774,8 @@ void backend_scan_result_destroy(backend_scan_result_t *result) { backend_bar_window_t backend_create_bar_window( backend_t *backend, rect_t geometry, - uint32_t bg_pixel + uint32_t bg_pixel, + bool enable_tray ) { auto conn = backend->conn; auto root = backend->screen->root; diff --git a/src/interface/backend.h b/src/interface/backend.h index 164a9cc..7086d33 100644 --- a/src/interface/backend.h +++ b/src/interface/backend.h @@ -5,6 +5,7 @@ #include "interface/effect.h" #include "interface/event.h" +#include "interface/tray.h" #include "interface/types.h" typedef struct backend_t backend_t; @@ -69,11 +70,13 @@ void backend_scan_result_destroy(backend_scan_result_t *result); typedef struct backend_bar_window_t { window_id_t window_id; cairo_t *cr; + tray_t tray; } backend_bar_window_t; backend_bar_window_t backend_create_bar_window( backend_t *backend, rect_t geometry, - uint32_t bg_pixel + uint32_t bg_pixel, + bool enable_tray ); void backend_flush(backend_t *backend); diff --git a/src/interface/tray.h b/src/interface/tray.h new file mode 100644 index 0000000..4d7c512 --- /dev/null +++ b/src/interface/tray.h @@ -0,0 +1,35 @@ +#pragma once + +#include +#include + +#include "interface/types.h" + +typedef void (*tray_icons_change_cb_t)(void *user_data); + +typedef struct tray_api_t { + /** + * @brief 获取 tray 当前挂载的 bar window id + * + * @detail 如果返回的 window_id 是 ZDWM_WINDOW_ID_INVALID 则表示 tray + * 功能未开启,无 tray 需要挂载 + */ + window_id_t (*host_window)(void *handle); + /* 获取当前 icon 数量 */ + size_t (*icon_count)(void *handle); + /* 获取每个 icon 的边长, icon 长宽一样,都等于 bar_height */ + int32_t (*icon_size)(void *handle); + /* 将 tray 的 icon 容器窗口起点放到 bar 中 x 这个位置 */ + void (*place)(void *handle, int32_t x); + /* 设置 icon 数量变化回调 */ + void (*set_listener)( + void *handle, + tray_icons_change_cb_t cb, + void *user_data + ); +} tray_api_t; + +typedef struct tray_t { + tray_api_t api; + void *handle; +} tray_t; diff --git a/src/runtime/runtime.c b/src/runtime/runtime.c index 31b27d4..022a65b 100644 --- a/src/runtime/runtime.c +++ b/src/runtime/runtime.c @@ -121,7 +121,8 @@ static void runtime_init_bar(runtime_t *runtime) { .height = bar_height, }; auto color = bar->palette.bg.argb; - auto bar_window = backend_create_bar_window(backend, bar_rect, color); + auto bar_window = + backend_create_bar_window(backend, bar_rect, color, false); auto bar_output = &bar->bars[i]; bar_output->cr = bar_window.cr; bar_output->window_id = bar_window.window_id;