From 94760fc2f8d1318f1d79f5cddd4046237c4f3215 Mon Sep 17 00:00:00 2001 From: Zedhugh Chen Date: Thu, 13 Nov 2025 23:46:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E6=AF=8F=E4=B8=AA?= =?UTF-8?q?=E5=B1=8F=E5=B9=95=E7=9A=84=20tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/default_config.h | 3 +++ src/monitor.c | 24 ++++++++++++++++++++++++ src/monitor.h | 1 + src/wm.c | 8 ++++++++ 4 files changed, 36 insertions(+) create mode 100644 src/default_config.h diff --git a/src/default_config.h b/src/default_config.h new file mode 100644 index 0000000..42b9018 --- /dev/null +++ b/src/default_config.h @@ -0,0 +1,3 @@ +static const char *const tags[] = { + "1", "2", "3", "4", "5", "6", "7", "8", "9", nullptr, +}; diff --git a/src/monitor.c b/src/monitor.c index 3ac0a1c..366b641 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -1,3 +1,27 @@ #include "monitor.h" +#include +#include "types.h" +#include "utils.h" + +void monitor_initialize_tag(monitor_t *monitor, const char **tags) { + int i = 0; + const char *tag_name = nullptr; + tag_t *prev_tag = nullptr; + for (tag_name = tags[i]; tag_name; tag_name = tags[++i]) { + tag_t *tag = p_new(tag_t, 1); + tag->name = strdup(tag_name); + tag->mask = 1u << i; + + if (prev_tag) { + prev_tag->next = tag; + } else { + monitor->tag_list = tag; + } + + prev_tag = tag; + } + + monitor->selected_tag = monitor->tag_list; +} diff --git a/src/monitor.h b/src/monitor.h index e43f315..cf1aa98 100644 --- a/src/monitor.h +++ b/src/monitor.h @@ -4,4 +4,5 @@ #include "types.h" +void monitor_initialize_tag(monitor_t *monitor, const char **tags); void monitor_select_tag(monitor_t *monitor, uint32_t tag_mask); diff --git a/src/wm.c b/src/wm.c index bde8776..d531adf 100644 --- a/src/wm.c +++ b/src/wm.c @@ -18,6 +18,8 @@ #include "backtrace.h" #include "buffer.h" +#include "default_config.h" +#include "monitor.h" #include "types.h" #include "utils.h" @@ -255,6 +257,9 @@ static void debug_show_monitor_list(void) { printf("x: %4d, y: %4d, width: %4u, height: %4u -> monitor[%s]\n", m->geometry.x, m->geometry.y, m->geometry.width, m->geometry.height, m->name); + for (const tag_t *tag = m->tag_list; tag; tag = tag->next) { + printf("tag[\"%s\"]: 0b%09b\n", tag->name, tag->mask); + } } } @@ -267,6 +272,9 @@ int main(int argc, char *argv[]) { wm_check_xcb_extensions(); wm_detect_monitor(); + for (monitor_t *m = wm.monitor_list; m; m = m->next) { + monitor_initialize_tag(m, (const char **)tags); + } debug_show_monitor_list();