绘制 layout 标志

This commit is contained in:
2025-08-26 03:29:15 +08:00
parent 9b77469ed2
commit 2c49c9f179
4 changed files with 17 additions and 3 deletions

View File

@@ -120,4 +120,5 @@ const uint32_t dpi_fallback = 96;
const uint32_t bar_y_padding = 1; const uint32_t bar_y_padding = 1;
const uint32_t tag_x_padding = 10; const uint32_t tag_x_padding = 10;
const uint32_t layout_symbol_x_padding = 10;
const uint32_t border_width = 1; const uint32_t border_width = 1;

View File

@@ -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, uint32_t get_font_height(const char *font_family, const uint32_t font_size,
const uint32_t dpi); const uint32_t dpi);
void draw_bar(monitor_t *monitor, bool is_current_monitor, 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); void clean_pango_context(void);

View File

@@ -83,6 +83,7 @@ static uint32_t font_size = default_font_size;
static uint32_t dpi = dpi_fallback; static uint32_t dpi = dpi_fallback;
static uint32_t bar_y_pad = bar_y_padding; static uint32_t bar_y_pad = bar_y_padding;
static uint32_t tag_x_pad = tag_x_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 bar_height = 0;
static uint32_t border_px = border_width; 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.font_size", &font_size);
get_xresource_uint32("zswm.bar_y_padding", &bar_y_pad); get_xresource_uint32("zswm.bar_y_padding", &bar_y_pad);
get_xresource_uint32("zswm.tag_x_padding", &tag_x_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); get_xresource_uint32("zswm.border_width", &border_px);
logger("dpi: %u, font family: %s, font size: %u\n", dpi, font_family, 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) { 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(); flush_xcb_connection();
} }

View File

@@ -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, 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; cairo_t *cr = monitor->cr;
int32_t x = 0; int32_t x = 0;
uint32_t width = 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); draw_text(cr, text, color, x, 0, width, height, true);
x += width; 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) { void clean_pango_context(void) {