feat(tray): 添加 tray 相关接口并融入现有启动流程

This commit is contained in:
2026-06-27 22:52:19 +08:00
parent eaad539a0b
commit 27aab6f0e9
4 changed files with 43 additions and 3 deletions

View File

@@ -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;

View File

@@ -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);

35
src/interface/tray.h Normal file
View File

@@ -0,0 +1,35 @@
#pragma once
#include <stddef.h>
#include <stdint.h>
#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;

View File

@@ -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;