feat(bar): bar item 扩展钩子功能 bar cell 添加 fixed_width 属性与操作接口

- item type 加入可为空的 after_layout 和 after_draw 钩子
- cell 加 fixed_width 属性, cell api 添加 cell_set_fixed_width 和
  cell_get_region 两个接口
- cell api 改为 const 避免外部修改
This commit is contained in:
2026-06-28 02:04:20 +08:00
parent 27aab6f0e9
commit 6b75cda128
5 changed files with 134 additions and 32 deletions

View File

@@ -48,6 +48,11 @@ typedef struct zdwm_bar_config_t {
typedef struct zdwm_bar_item_t zdwm_bar_item_t;
typedef struct zdwm_bar_x_region_t {
int32_t start;
int32_t end;
} zdwm_bar_x_region_t;
typedef struct zdwm_bar_cell_api_t {
size_t (*get_cell_count)(zdwm_bar_item_t *item);
void (*set_cell_count)(zdwm_bar_item_t *item, size_t count);
@@ -57,6 +62,13 @@ typedef struct zdwm_bar_cell_api_t {
void (*cell_set_fg)(zdwm_bar_item_t *item, size_t index, const char *color);
void (*cell_set_icon)(zdwm_bar_item_t *item, size_t index, zdwm_icon_t icon);
void (*cell_set_indicator)(zdwm_bar_item_t *item, size_t index, bool show);
void (*cell_set_fixed_width)(
zdwm_bar_item_t *item,
size_t index,
int32_t width
);
zdwm_bar_x_region_t (*cell_get_region)(zdwm_bar_item_t *item, size_t index);
} zdwm_bar_cell_api_t;
typedef struct zdwm_bar_click_params_t {
@@ -68,6 +80,13 @@ typedef struct zdwm_bar_click_params_t {
void *state;
} zdwm_bar_click_params_t;
typedef struct zdwm_bar_item_hook_params_t {
zdwm_bar_item_t *item;
const zdwm_bar_cell_api_t *cell_api;
zdwm_bar_x_region_t region;
void *state;
} zdwm_bar_item_hook_params_t;
typedef struct zdwm_bar_item_type_t {
void *(*create_state)(zdwm_output_id_t output_id, void *config);
void (*update)(
@@ -75,6 +94,8 @@ typedef struct zdwm_bar_item_type_t {
const zdwm_bar_cell_api_t *cells,
void *state
);
void (*after_layout)(const zdwm_bar_item_hook_params_t *params);
void (*after_draw)(const zdwm_bar_item_hook_params_t *params);
zdwm_action_t (*on_click)(zdwm_bar_click_params_t *params);
void (*destroy_state)(void *state);
zdwm_bar_item_t *instance;