feat(bar): 初始化 bar 窗口并将 bar 集成到 runtime 启动流程中
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
#include <zdwm/types.h>
|
#include <zdwm/types.h>
|
||||||
|
|
||||||
#include "bar/types.h"
|
#include "bar/types.h"
|
||||||
|
#include "base/color.h"
|
||||||
|
|
||||||
typedef struct bar_output_t {
|
typedef struct bar_output_t {
|
||||||
cairo_t *cr;
|
cairo_t *cr;
|
||||||
@@ -14,6 +15,10 @@ typedef struct bar_output_t {
|
|||||||
bar_side_t sides[ZDWM_BAR_SIDE_COUNT];
|
bar_side_t sides[ZDWM_BAR_SIDE_COUNT];
|
||||||
} bar_output_t;
|
} bar_output_t;
|
||||||
|
|
||||||
|
typedef struct bar_palette_t {
|
||||||
|
color_t bg;
|
||||||
|
} bar_palette_t;
|
||||||
|
|
||||||
typedef struct bar_t {
|
typedef struct bar_t {
|
||||||
bar_output_t *bars;
|
bar_output_t *bars;
|
||||||
size_t count;
|
size_t count;
|
||||||
@@ -21,4 +26,5 @@ typedef struct bar_t {
|
|||||||
bool visible;
|
bool visible;
|
||||||
|
|
||||||
zdwm_bar_config_t config;
|
zdwm_bar_config_t config;
|
||||||
|
bar_palette_t palette;
|
||||||
} bar_t;
|
} bar_t;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <zdwm/action.h>
|
#include <zdwm/action.h>
|
||||||
|
#include <zdwm/bar.h>
|
||||||
#include <zdwm/types.h>
|
#include <zdwm/types.h>
|
||||||
|
|
||||||
#include "base/log.h"
|
#include "base/log.h"
|
||||||
@@ -167,5 +168,18 @@ bool config_defaults_build(
|
|||||||
api->set_initial_mode(builder, default_mode);
|
api->set_initial_mode(builder, default_mode);
|
||||||
api->set_border_config(builder, 2, "#1c2022", "#606060");
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "bar/bar.h"
|
#include "bar/bar.h"
|
||||||
#include "base/array.h"
|
#include "base/array.h"
|
||||||
|
#include "base/color.h"
|
||||||
#include "base/log.h"
|
#include "base/log.h"
|
||||||
#include "base/memory.h"
|
#include "base/memory.h"
|
||||||
#include "base/window_list.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);
|
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) {
|
static void runtime_setup(runtime_t *runtime) {
|
||||||
size_t bind_count = 0;
|
size_t bind_count = 0;
|
||||||
auto bindings =
|
auto bindings =
|
||||||
@@ -211,6 +252,8 @@ static void runtime_setup(runtime_t *runtime) {
|
|||||||
backend_apply_effect(backend, plan->effects, plan->count);
|
backend_apply_effect(backend, plan->effects, plan->count);
|
||||||
plan_reset(plan);
|
plan_reset(plan);
|
||||||
runtime_notify_initial_state(runtime);
|
runtime_notify_initial_state(runtime);
|
||||||
|
|
||||||
|
runtime_init_bar(runtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const layout_result_t *runtime_layout_calc(runtime_t *runtime) {
|
static const layout_result_t *runtime_layout_calc(runtime_t *runtime) {
|
||||||
|
|||||||
Reference in New Issue
Block a user