This commit is contained in:
Emilia Miki 2026-06-24 15:37:30 +03:00 committed by GitHub
commit 7dcecb4bb0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 3 deletions

View file

@ -160,6 +160,7 @@ typedef struct {
typedef struct {
int32_t id;
char *name;
char *layout_name;
char *monitor_name;
char *monitor_make;
@ -2183,6 +2184,7 @@ bool parse_option(Config *config, char *key, char *value) {
// 设置默认值
rule->id = 0;
rule->name = NULL;
rule->layout_name = NULL;
rule->monitor_name = NULL;
rule->monitor_make = NULL;
@ -2211,6 +2213,8 @@ bool parse_option(Config *config, char *key, char *value) {
if (strcmp(key, "id") == 0) {
rule->id = CLAMP_INT(atoi(val), 0, LENGTH(tags));
} else if (strcmp(key, "name") == 0) {
rule->name = strdup(val);
} else if (strcmp(key, "layout_name") == 0) {
rule->layout_name = strdup(val);
} else if (strcmp(key, "monitor_name") == 0) {
@ -3300,6 +3304,8 @@ void free_config(void) {
// 释放 tag_rules
if (config.tag_rules) {
for (int32_t i = 0; i < config.tag_rules_count; i++) {
if (config.tag_rules[i].name)
free((void *)config.tag_rules[i].name);
if (config.tag_rules[i].layout_name)
free((void *)config.tag_rules[i].layout_name);
if (config.tag_rules[i].monitor_name)
@ -4302,3 +4308,13 @@ int32_t reload_config(const Arg *arg) {
printstatus(IPC_WATCH_ARRANGGE);
return 1;
}
static const char *get_tag_name(int tag_index) {
for (int i = 0; i < config.tag_rules_count; i++) {
if (config.tag_rules[i].id == tag_index && config.tag_rules[i].name)
return config.tag_rules[i].name;
}
if (tag_index >= 1 && tag_index <= (int)LENGTH(tags))
return tags[tag_index - 1];
return NULL;
}

View file

@ -100,9 +100,9 @@ static void handle_ext_commit(struct wl_listener *listener, void *data) {
}
static const char *get_name_from_tag(uint32_t tag) {
static const char *names[] = {"overview", "1", "2", "3", "4",
"5", "6", "7", "8", "9"};
return (tag < sizeof(names) / sizeof(names[0])) ? names[tag] : NULL;
if (tag == 0)
return "overview";
return get_tag_name((int)tag);
}
void destroy_workspace(struct workspace *workspace) {

View file

@ -99,6 +99,7 @@ static cJSON *build_tags_json(Monitor *m) {
}
cJSON *tag_obj = cJSON_CreateObject();
cJSON_AddNumberToObject(tag_obj, "index", tag);
cJSON_AddStringToObject(tag_obj, "name", get_tag_name(tag));
cJSON_AddBoolToObject(tag_obj, "is_active", is_active);
cJSON_AddBoolToObject(tag_obj, "is_urgent", is_urgent);
cJSON_AddStringToObject(tag_obj, "layout",