From e7447f8aaa25932ab2977a2647a91bee63034038 Mon Sep 17 00:00:00 2001 From: Zedhugh Chen Date: Mon, 8 Dec 2025 03:25:09 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=98=E5=88=B6=E5=B8=83=E5=B1=80=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/default_config.h | 6 ++++++ src/monitor.c | 23 +++++++++++++++++++++++ src/types.h | 3 ++- src/wm.c | 2 ++ src/wm.h | 2 ++ 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/default_config.h b/src/default_config.h index 0533e5e..efbc072 100644 --- a/src/default_config.h +++ b/src/default_config.h @@ -4,6 +4,7 @@ #include #include "action.h" +#include "types.h" static const char *const font_family = "monospace"; static const int font_size = 10; @@ -32,3 +33,8 @@ static const keyboard_t key_list[] = { {modifier_alt, XK_q, quit, {.b = false}}, {modifier_alt, XK_r, quit, {.b = true}}, }; + +static const layout_t layout_list[] = { + {.symbol = "[M]", .arrange = nullptr}, + {.symbol = "><=", .arrange = nullptr}, +}; diff --git a/src/monitor.c b/src/monitor.c index 3767804..1311357 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -27,6 +27,10 @@ uint32_t monitor_initialize_tag(monitor_t *monitor, const char **tags, tag->mask = 1u << i; tag->index = tag_index_start_at + tag_count; + if (wm.layout_count > 0 && wm.layout_list) { + tag->layout = &wm.layout_list[0]; + } + if (prev_tag) { prev_tag->next = tag; } else { @@ -174,6 +178,24 @@ static void monitor_draw_tags(monitor_t *monitor) { monitor->tag_extent.end = x; } +static void monitor_draw_layout_symbol(monitor_t *monitor) { + const layout_t *layout = monitor->selected_tag->layout; + if (layout && layout->symbol) { + color_t *color = &wm.color_set.tag_color; + int width = 0; + text_get_size(layout->symbol, &width, nullptr); + area_t area = { + .x = monitor->tag_extent.end, + .y = monitor->geometry.y, + .width = width + 2 * wm.padding.tag_x, + .height = wm.bar_height, + }; + monitor->layout_symbol_extent.start = area.x; + monitor->layout_symbol_extent.end = area.x + area.width; + draw_text(monitor->bar_cr, layout->symbol, color, area, true); + } +} + void monitor_draw_bar(monitor_t *monitor) { cairo_t *cr = monitor->bar_cr; uint16_t height = wm.bar_height; @@ -186,4 +208,5 @@ void monitor_draw_bar(monitor_t *monitor) { draw_background(cr, &wm.color_set.bar_bg, bar_area); monitor_draw_tags(monitor); + monitor_draw_layout_symbol(monitor); } diff --git a/src/types.h b/src/types.h index 122abfc..0242ebb 100644 --- a/src/types.h +++ b/src/types.h @@ -58,6 +58,7 @@ struct monitor_t { cairo_t *bar_cr; extent_in_bar_t tag_extent; + extent_in_bar_t layout_symbol_extent; xcb_window_t bar_window; }; @@ -68,7 +69,7 @@ struct tag_t { extent_in_bar_t bar_extent; tag_t *next; char *name; - layout_t *layout; + const layout_t *layout; task_in_tag_t *task_list; }; diff --git a/src/wm.c b/src/wm.c index 7e2acf8..fc99184 100644 --- a/src/wm.c +++ b/src/wm.c @@ -273,6 +273,8 @@ void wm_clean(void) { static void wm_setup(void) { wm.padding.tag_x = tag_x_padding; + wm.layout_list = layout_list; + wm.layout_count = (uint16_t)countof(layout_list); wm_init_color_set(); diff --git a/src/wm.h b/src/wm.h index 0fb22ad..6ec5c37 100644 --- a/src/wm.h +++ b/src/wm.h @@ -9,6 +9,7 @@ typedef struct wm_t { padding_t padding; uint16_t bar_height; + uint16_t layout_count; bool need_restart; GMainLoop *loop; @@ -18,6 +19,7 @@ typedef struct wm_t { client_t *client_focused; monitor_t *monitor_list; monitor_t *current_monitor; + const layout_t *layout_list; xcb_connection_t *xcb_conn; xcb_screen_t *screen;