From 2c49c9f179193301f362dd6c7edb2736adf3ac18 Mon Sep 17 00:00:00 2001 From: Zedhugh Chen Date: Tue, 26 Aug 2025 03:29:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=98=E5=88=B6=20layout=20=E6=A0=87?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config.h | 1 + src/include/renderer.h | 3 ++- src/main.c | 5 ++++- src/renderer/text.c | 11 ++++++++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/config.h b/src/config.h index 469a127..6223b51 100644 --- a/src/config.h +++ b/src/config.h @@ -120,4 +120,5 @@ const uint32_t dpi_fallback = 96; const uint32_t bar_y_padding = 1; const uint32_t tag_x_padding = 10; +const uint32_t layout_symbol_x_padding = 10; const uint32_t border_width = 1; diff --git a/src/include/renderer.h b/src/include/renderer.h index 817602a..7afc3ea 100644 --- a/src/include/renderer.h +++ b/src/include/renderer.h @@ -13,5 +13,6 @@ uint32_t *generate_wallpaper(const wallpaper_config_t *wallpaper_config, uint32_t get_font_height(const char *font_family, const uint32_t font_size, const uint32_t dpi); void draw_bar(monitor_t *monitor, bool is_current_monitor, - color_set_t *color_set, uint32_t height, uint32_t tag_x_padding); + color_set_t *color_set, uint32_t height, uint32_t tag_x_padding, + uint32_t layout_x_padding); void clean_pango_context(void); diff --git a/src/main.c b/src/main.c index 65ae562..8e1dea0 100644 --- a/src/main.c +++ b/src/main.c @@ -83,6 +83,7 @@ static uint32_t font_size = default_font_size; static uint32_t dpi = dpi_fallback; static uint32_t bar_y_pad = bar_y_padding; static uint32_t tag_x_pad = tag_x_padding; +static uint32_t layout_symbol_x_pad = layout_symbol_x_padding; static uint32_t bar_height = 0; static uint32_t border_px = border_width; @@ -476,6 +477,7 @@ void get_xresource_config(void) { get_xresource_uint32("zswm.font_size", &font_size); get_xresource_uint32("zswm.bar_y_padding", &bar_y_pad); get_xresource_uint32("zswm.tag_x_padding", &tag_x_pad); + get_xresource_uint32("zswm.layout_symbol_x_padding", &layout_symbol_x_pad); get_xresource_uint32("zswm.border_width", &border_px); logger("dpi: %u, font family: %s, font size: %u\n", dpi, font_family, @@ -488,7 +490,8 @@ void draw_all_monitor_bars(void) { } void draw_monitor_bar(monitor_t *m) { - draw_bar(m, m == current_monitor, color_set, bar_height, tag_x_pad); + draw_bar(m, m == current_monitor, color_set, bar_height, tag_x_pad, + layout_symbol_x_pad); flush_xcb_connection(); } diff --git a/src/renderer/text.c b/src/renderer/text.c index 11d936b..2873a90 100644 --- a/src/renderer/text.c +++ b/src/renderer/text.c @@ -136,7 +136,8 @@ static void draw_rect(cairo_t *cr, int32_t x, int32_t y, uint32_t width, } void draw_bar(monitor_t *monitor, bool is_current_monitor, - color_set_t *color_set, uint32_t height, uint32_t tag_x_padding) { + color_set_t *color_set, uint32_t height, uint32_t tag_x_padding, + uint32_t layout_x_padding) { cairo_t *cr = monitor->cr; int32_t x = 0; uint32_t width = 0; @@ -166,6 +167,14 @@ void draw_bar(monitor_t *monitor, bool is_current_monitor, draw_text(cr, text, color, x, 0, width, height, true); x += width; } + /* 绘制 layout 标识 */ + { + text = monitor->layout->symbol; + width = get_text_width(text) + layout_x_padding * 2; + color = &color_set->layout_color; + draw_text(cr, text, color, x, 0, width, height, true); + x += width; + } } void clean_pango_context(void) {