根据配置为每个屏幕初始化 tags 属性

This commit is contained in:
2025-08-13 01:25:50 +08:00
parent 43ca95d2f4
commit 72151c1458
4 changed files with 86 additions and 10 deletions

View File

@@ -15,6 +15,7 @@
#include "xcb.h"
static void init_monitors(void);
static char **get_monitor_tags(uint32_t monitor_count, uint32_t monitor_index);
static void init_wallpaper(void);
static gboolean update_wallpaper(gpointer user_data);
static void set_wallpaper_by_index(uint32_t index);
@@ -31,10 +32,18 @@ static GMainLoop *loop = NULL;
/* 调试函数,开发完成后删除 */
static void print_monitor_list_info(monitor_t *monitor_list) {
printf("========================= monitor info =========================\n");
for (monitor_t *m = monitor_list; m; m = m->next) {
printf("mon[%u]: x: %d, y: %d, width: %u, height: %u\n", m->index,
m->monitor_x, m->monitor_y, m->monitor_width, m->monitor_height);
printf("========== mon[%u]:\n", m->index);
printf("x: %d, y: %d, width: %u, height: %u\n", m->monitor_x, m->monitor_y,
m->monitor_width, m->monitor_height);
printf("mon[%u] tags: ", m->index);
for (int i = 0; m->tags[i]; i++) {
printf("%s%s", i > 0 ? ", " : "", m->tags[i]);
}
printf("\n");
}
printf("======================= monitor info end =======================\n");
}
static void print_wallpaper_config(wallpaper_config_t *config) {
if (!config) {
@@ -83,6 +92,39 @@ void init_monitors(void) {
free(mr);
mr = next_mr;
}
for (monitor_t *m = monitors; m; m = m->next) {
m->tags = get_monitor_tags(i, m->index);
}
}
char **get_monitor_tags(uint32_t monitor_count, uint32_t monitor_index) {
int config_count = 0;
while (monitor_tags[config_count]) config_count++;
GStrvBuilder *builder = g_strv_builder_new();
const char *const *tags = NULL;
/* 倒序遍历,达到后面的配置覆盖前面相同配置的效果 */
for (int i = config_count - 1; i >= 0; i--) {
const char *const *const *config = monitor_tags[i];
uint32_t monitor_count_in_tags_config = 0;
while (config[monitor_count_in_tags_config]) monitor_count_in_tags_config++;
if (monitor_count_in_tags_config != monitor_count) continue;
tags = config[monitor_index];
break;
const char *const *const tags = config[monitor_index];
for (int j = 0; tags[j]; j++) g_strv_builder_add(builder, tags[j]);
return g_strv_builder_unref_to_strv(builder);
}
if (tags == NULL) tags = default_monitor_tags;
for (int i = 0; tags[i]; i++) g_strv_builder_add(builder, tags[i]);
return g_strv_builder_unref_to_strv(builder);
}
void init_wallpaper(void) {
@@ -199,9 +241,10 @@ void cleanup(void) {
free(c);
c = tc;
}
monitor_t *tm = m->next;
monitor_t *next_monitor = m->next;
g_strfreev(m->tags);
free(m);
m = tm;
m = next_monitor;
}
monitors = NULL;
}