根据配置为每个屏幕初始化 tags 属性
This commit is contained in:
33
src/config.c
33
src/config.c
@@ -3,7 +3,36 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
/* 壁纸列表,支持通配符和 shell 环境变量拼接,最后以 NULL 结尾 */
|
|
||||||
const char *wallpager_list[] = {NULL};
|
const char *wallpager_list[] = {NULL};
|
||||||
/* 壁纸切换间隔(单位:秒),0 表示不切换 */
|
|
||||||
const uint32_t wallpaper_interval = 0;
|
const uint32_t wallpaper_interval = 0;
|
||||||
|
|
||||||
|
const char *const *const *const monitor_tags[] = {
|
||||||
|
(const char *const *const[]){
|
||||||
|
(const char *const[]){
|
||||||
|
"1 ",
|
||||||
|
"2 ",
|
||||||
|
"3 ",
|
||||||
|
"4 ",
|
||||||
|
"5 ",
|
||||||
|
"6 ",
|
||||||
|
NULL,
|
||||||
|
},
|
||||||
|
NULL,
|
||||||
|
},
|
||||||
|
(const char *const *const[]){
|
||||||
|
(const char *const[]){"1 ", "2 ", "3 ", NULL},
|
||||||
|
(const char *const[]){
|
||||||
|
"1 ",
|
||||||
|
"2 ",
|
||||||
|
"3 ",
|
||||||
|
"4 ",
|
||||||
|
"5 ",
|
||||||
|
NULL,
|
||||||
|
},
|
||||||
|
NULL,
|
||||||
|
},
|
||||||
|
NULL,
|
||||||
|
};
|
||||||
|
const char *const default_monitor_tags[] = {
|
||||||
|
"1", "2", "3", "4", "5", "6", "7", "8", "9", NULL,
|
||||||
|
};
|
||||||
|
|||||||
@@ -2,5 +2,27 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/* 壁纸列表,支持通配符和 shell 环境变量拼接,最后以 NULL 结尾 */
|
||||||
extern const char *wallpager_list[];
|
extern const char *wallpager_list[];
|
||||||
|
/* 壁纸切换间隔(单位:秒),0 表示不切换 */
|
||||||
extern const uint32_t wallpaper_interval;
|
extern const uint32_t wallpaper_interval;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 屏幕 tags 设置
|
||||||
|
* @description 每个屏幕的 tags 配置为字符串数组,以 NULL 结束,如
|
||||||
|
* {"1", "2", "3", "4", "5", "6", NULL}
|
||||||
|
*
|
||||||
|
* 每一项配置里面的数组个数表示对应的屏幕个数,并最后以 NULL 结束,
|
||||||
|
*
|
||||||
|
* 如一个屏幕应该配置为 {{"1", "2", "3", "4", NULL}, NULL},
|
||||||
|
* 两个屏幕应该配置为 {{"1", "2", "3", NULL}, {"1", "2", NULL}, NULL},以此类推
|
||||||
|
*/
|
||||||
|
extern const char *const *const *const monitor_tags[];
|
||||||
|
/**
|
||||||
|
* @brief 默认屏幕 tags 设置
|
||||||
|
* @description 若屏幕个数与 monitor_tags 中设置的所有配置项都不符,
|
||||||
|
* 则所有屏幕的 tags 都使用这个默认配置
|
||||||
|
*
|
||||||
|
* 格式为字符串数组,以 NULL 标志结束,如 {"1", "2", "3", NULL}
|
||||||
|
*/
|
||||||
|
extern const char *const default_monitor_tags[];
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ typedef struct layout_t {
|
|||||||
void (*arrange)(monitor_t *monitor);
|
void (*arrange)(monitor_t *monitor);
|
||||||
} layout_t;
|
} layout_t;
|
||||||
|
|
||||||
#define TAG_SYMBOL_LENGTH 32
|
|
||||||
|
|
||||||
/* 避免引入 xcb 头文件 */
|
/* 避免引入 xcb 头文件 */
|
||||||
typedef uint32_t xcb_window_t;
|
typedef uint32_t xcb_window_t;
|
||||||
|
|
||||||
@@ -22,8 +20,7 @@ struct monitor_t {
|
|||||||
uint32_t monitor_width, monitor_height, window_width, window_height;
|
uint32_t monitor_width, monitor_height, window_width, window_height;
|
||||||
|
|
||||||
uint32_t selected_tag;
|
uint32_t selected_tag;
|
||||||
uint32_t tag_count;
|
char **tags;
|
||||||
char (*tags)[TAG_SYMBOL_LENGTH];
|
|
||||||
|
|
||||||
/* 为了避免引入 cairo 相关头文件,这里用 void *
|
/* 为了避免引入 cairo 相关头文件,这里用 void *
|
||||||
* 指针代替实际的指针类型,使用时强转为相应指针类型使用即可 */
|
* 指针代替实际的指针类型,使用时强转为相应指针类型使用即可 */
|
||||||
|
|||||||
51
src/main.c
51
src/main.c
@@ -15,6 +15,7 @@
|
|||||||
#include "xcb.h"
|
#include "xcb.h"
|
||||||
|
|
||||||
static void init_monitors(void);
|
static void init_monitors(void);
|
||||||
|
static char **get_monitor_tags(uint32_t monitor_count, uint32_t monitor_index);
|
||||||
static void init_wallpaper(void);
|
static void init_wallpaper(void);
|
||||||
static gboolean update_wallpaper(gpointer user_data);
|
static gboolean update_wallpaper(gpointer user_data);
|
||||||
static void set_wallpaper_by_index(uint32_t index);
|
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) {
|
static void print_monitor_list_info(monitor_t *monitor_list) {
|
||||||
|
printf("========================= monitor info =========================\n");
|
||||||
for (monitor_t *m = monitor_list; m; m = m->next) {
|
for (monitor_t *m = monitor_list; m; m = m->next) {
|
||||||
printf("mon[%u]: x: %d, y: %d, width: %u, height: %u\n", m->index,
|
printf("========== mon[%u]:\n", m->index);
|
||||||
m->monitor_x, m->monitor_y, m->monitor_width, m->monitor_height);
|
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) {
|
static void print_wallpaper_config(wallpaper_config_t *config) {
|
||||||
if (!config) {
|
if (!config) {
|
||||||
@@ -83,6 +92,39 @@ void init_monitors(void) {
|
|||||||
free(mr);
|
free(mr);
|
||||||
mr = next_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) {
|
void init_wallpaper(void) {
|
||||||
@@ -199,9 +241,10 @@ void cleanup(void) {
|
|||||||
free(c);
|
free(c);
|
||||||
c = tc;
|
c = tc;
|
||||||
}
|
}
|
||||||
monitor_t *tm = m->next;
|
monitor_t *next_monitor = m->next;
|
||||||
|
g_strfreev(m->tags);
|
||||||
free(m);
|
free(m);
|
||||||
m = tm;
|
m = next_monitor;
|
||||||
}
|
}
|
||||||
monitors = NULL;
|
monitors = NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user