初始化每个屏幕的 tag

This commit is contained in:
2025-11-13 23:46:44 +08:00
parent db284bf6b7
commit 94760fc2f8
4 changed files with 36 additions and 0 deletions

3
src/default_config.h Normal file
View File

@@ -0,0 +1,3 @@
static const char *const tags[] = {
"1", "2", "3", "4", "5", "6", "7", "8", "9", nullptr,
};

View File

@@ -1,3 +1,27 @@
#include "monitor.h"
#include <string.h>
#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;
}

View File

@@ -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);

View File

@@ -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();