From b510b7b473e56ce4f5096eefc3ea557d9fdc2c76 Mon Sep 17 00:00:00 2001 From: Zedhugh Chen Date: Sat, 6 Jun 2026 09:23:15 +0800 Subject: [PATCH] =?UTF-8?q?feat(bar):=20=E5=88=9D=E5=A7=8B=E5=8C=96=20bar?= =?UTF-8?q?=20=E7=AA=97=E5=8F=A3=E5=B9=B6=E5=B0=86=20bar=20=E9=9B=86?= =?UTF-8?q?=E6=88=90=E5=88=B0=20runtime=20=E5=90=AF=E5=8A=A8=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bar/bar.h | 6 ++++++ src/config/defaults.c | 14 ++++++++++++++ src/runtime/runtime.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/src/bar/bar.h b/src/bar/bar.h index e71763e..a2d453f 100644 --- a/src/bar/bar.h +++ b/src/bar/bar.h @@ -6,6 +6,7 @@ #include #include "bar/types.h" +#include "base/color.h" typedef struct bar_output_t { cairo_t *cr; @@ -14,6 +15,10 @@ typedef struct bar_output_t { bar_side_t sides[ZDWM_BAR_SIDE_COUNT]; } bar_output_t; +typedef struct bar_palette_t { + color_t bg; +} bar_palette_t; + typedef struct bar_t { bar_output_t *bars; size_t count; @@ -21,4 +26,5 @@ typedef struct bar_t { bool visible; zdwm_bar_config_t config; + bar_palette_t palette; } bar_t; diff --git a/src/config/defaults.c b/src/config/defaults.c index ce5bd2f..b89f5d1 100644 --- a/src/config/defaults.c +++ b/src/config/defaults.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "base/log.h" @@ -167,5 +168,18 @@ bool config_defaults_build( api->set_initial_mode(builder, default_mode); api->set_border_config(builder, 2, "#1c2022", "#606060"); + zdwm_bar_config_t bar_config = { + .height = 28, + .show_top = true, + .padding_x = 10, + .fps = 30, + .font_family = "Terminus, Sarasa Term SC", + .font_size = 10, + .dpi = 144, + + .bg = "#222222", + }; + api->set_bar_config(builder, bar_config); + return true; } diff --git a/src/runtime/runtime.c b/src/runtime/runtime.c index 0a55db1..5634222 100644 --- a/src/runtime/runtime.c +++ b/src/runtime/runtime.c @@ -7,6 +7,7 @@ #include "bar/bar.h" #include "base/array.h" +#include "base/color.h" #include "base/log.h" #include "base/memory.h" #include "base/window_list.h" @@ -186,6 +187,46 @@ static void runtime_notify_initial_state(runtime_t *runtime) { listeners_notify_binding_mode(listeners, runtime->binding_table); } +static void runtime_init_bar(runtime_t *runtime) { + auto bar_height = runtime->bar.config.height; + if (bar_height <= 0) return; + + auto show_top = runtime->bar.config.show_top; + inset_t inset = { + .top = show_top ? bar_height : 0, + .bottom = show_top ? 0 : bar_height, + }; + + auto state = &runtime->state; + auto count = state_output_count(state); + + auto bar = &runtime->bar; + bar->bars = p_new(bar_output_t, count); + bar->count = count; + bar->visible = true; + + color_parse(bar->config.bg, &bar->palette.bg); + + auto backend = runtime->backend; + for (size_t i = 0; i < count; ++i) { + auto output = state_output_at(state, i); + state_output_inset_workarea(state, output->id, inset); + auto geometry = output->geometry; + rect_t bar_rect = { + .x = geometry.x, + .y = show_top ? 0 : geometry.y + geometry.height - bar_height, + .width = geometry.width, + .height = bar_height, + }; + auto color = bar->palette.bg.argb; + auto bar_window = backend_create_bar_window(backend, bar_rect, color); + auto bar_output = &bar->bars[i]; + bar_output->cr = bar_window.cr; + bar_output->window_id = bar_window.window_id; + bar_output->output_id = output->id; + } +} + static void runtime_setup(runtime_t *runtime) { size_t bind_count = 0; auto bindings = @@ -211,6 +252,8 @@ static void runtime_setup(runtime_t *runtime) { backend_apply_effect(backend, plan->effects, plan->count); plan_reset(plan); runtime_notify_initial_state(runtime); + + runtime_init_bar(runtime); } static const layout_result_t *runtime_layout_calc(runtime_t *runtime) {