From e78c84712571cffc66831807368650b5cc738516 Mon Sep 17 00:00:00 2001 From: Zedhugh Chen Date: Wed, 13 Aug 2025 21:26:40 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=85=8D=E7=BD=AE=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E5=B9=B6=E6=B7=BB=E5=8A=A0=20client=20=E8=A7=84?= =?UTF-8?q?=E5=88=99=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CMakeLists.txt | 3 ++- src/config.c | 23 ----------------- src/config.h | 60 ++++++++++++++++++++++++++++++++++++++++++++ src/include/config.h | 28 --------------------- src/include/types.h | 17 +++++++++++++ src/main.c | 15 +++++------ 6 files changed, 85 insertions(+), 61 deletions(-) delete mode 100644 src/config.c create mode 100644 src/config.h delete mode 100644 src/include/config.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8869308..8806281 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,7 +15,7 @@ project(${APP_NAME} LANGUAGES C ) -add_executable(${APP_NAME} main.c utils.c config.c) +add_executable(${APP_NAME} main.c utils.c) # use C17 set_property(TARGET ${APP_NAME} PROPERTY C_STANDARD 17) @@ -51,6 +51,7 @@ target_include_directories(${APP_NAME} SYSTEM ) target_include_directories(${APP_NAME} PRIVATE "${SOURCE_DIR}/include" + PRIVATE "${SOURCE_DIR}" PRIVATE ${CMAKE_BINARY_DIR} ) diff --git a/src/config.c b/src/config.c deleted file mode 100644 index f81866e..0000000 --- a/src/config.c +++ /dev/null @@ -1,23 +0,0 @@ -#include "config.h" - -#include -#include - -const char *wallpager_list[] = {NULL}; -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, -}; diff --git a/src/config.h b/src/config.h new file mode 100644 index 0000000..aba3167 --- /dev/null +++ b/src/config.h @@ -0,0 +1,60 @@ +#pragma once + +#include +#include + +#include "types.h" + +/* 壁纸列表,支持通配符和 shell 环境变量拼接,最后以 NULL 结尾 */ +const char *wallpapers[] = {}; +/* 壁纸切换间隔(单位:秒),0 表示不切换 */ +const uint32_t wallpaper_interval = 0; + +/** + * @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},以此类推 + */ +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, + }, +}; +/** + * @brief 默认屏幕 tags 设置 + * @description 若屏幕个数与 monitor_tags 中设置的所有配置项都不符, + * 则所有屏幕的 tags 都使用这个默认配置 + * + * 格式为字符串数组,以 NULL 标志结束,如 {"1", "2", "3", NULL} + */ +const char *const default_monitor_tags[] = { + "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL, +}; + +/* 新建窗口规则,以 NULL 结束 */ +const rule_t rules[] = { + /* client 固定规则 */ + {.class = "firefox", .maximize = true}, + {.class = "Google-chrome", .maximize = true}, + {.class = "mpv", .fullscreen = true}, + {.class = "Emacs", .switch_to_tag = true, .maximize = true}, + + /* client 默认 tag 规则 */ + {.class = "firefox", .monitor_index = 0, .tags = 1 << 1}, + {.class = "Google-chrome", .monitor_index = 0, .tags = 1 << 1}, + {.class = "mpv", .monitor_amount = 1, .monitor_index = 0, .tags = 1 << 3}, + {.class = "mpv", .monitor_amount = 2, .monitor_index = 1, .tags = 1 << 2}, + {.class = "Emacs", .monitor_amount = 1, .monitor_index = 0, .tags = 1 << 2}, + {.class = "Emacs", .monitor_amount = 2, .monitor_index = 0, .tags = 1 << 1}, +}; diff --git a/src/include/config.h b/src/include/config.h deleted file mode 100644 index 0505e08..0000000 --- a/src/include/config.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include - -/* 壁纸列表,支持通配符和 shell 环境变量拼接,最后以 NULL 结尾 */ -extern const char *wallpager_list[]; -/* 壁纸切换间隔(单位:秒),0 表示不切换 */ -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[]; diff --git a/src/include/types.h b/src/include/types.h index 7242598..75007da 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -56,3 +56,20 @@ typedef struct wallpaper_config_t { uint32_t count; char **path_list; } wallpaper_config_t; + +typedef struct rule_t { + const char *class; + const char *instance; + const char *title; + + /* 规则适用的屏幕总数,若设置为 0 ,则此条规则适用于任意屏幕数 */ + const uint32_t monitor_amount; + + uint32_t tags; + uint32_t monitor_index; + + bool switch_to_tag; + bool fullscreen; + bool maximize; + bool floating; +} rule_t; diff --git a/src/main.c b/src/main.c index e001615..b2b4f66 100644 --- a/src/main.c +++ b/src/main.c @@ -19,7 +19,7 @@ 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); -static wallpaper_config_t *parse_wallpaper_config(const char **wallpapers); +static wallpaper_config_t *parse_wallpaper_config(void); static void free_wallpaper_config(wallpaper_config_t *wallpaper_config); static void init_xcb_event_loop(void); static gboolean handle_xcb_event(GIOChannel *channel, GIOCondition condition, @@ -98,14 +98,11 @@ void init_monitors(void) { } 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--) { + for (int i = LENGTH(monitor_tags) - 1; i >= 0; i--) { const char *const *const *config = monitor_tags[i]; uint32_t monitor_count_in_tags_config = 0; @@ -128,7 +125,7 @@ char **get_monitor_tags(uint32_t monitor_count, uint32_t monitor_index) { } void init_wallpaper(void) { - wallpaper_config = parse_wallpaper_config(wallpager_list); + wallpaper_config = parse_wallpaper_config(); if (!wallpaper_config) return; update_wallpaper(wallpaper_config); @@ -171,13 +168,13 @@ void set_wallpaper_by_index(uint32_t index) { free(screen_size); } -wallpaper_config_t *parse_wallpaper_config(const char **wallpapers) { - if (!wallpapers) return NULL; +wallpaper_config_t *parse_wallpaper_config(void) { + if (!LENGTH(wallpapers)) return NULL; wallpaper_config_t *wc = ecalloc(1, sizeof(wallpaper_config_t)); GStrvBuilder *builder = g_strv_builder_new(); - for (int i = 0; wallpapers && wallpapers[i]; i++) { + for (int i = 0; i < LENGTH(wallpapers); i++) { wordexp_t p; if (wordexp(wallpapers[i], &p, 0)) continue;