调整配置结构并添加 client 规则配置
This commit is contained in:
@@ -15,7 +15,7 @@ project(${APP_NAME}
|
|||||||
LANGUAGES C
|
LANGUAGES C
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(${APP_NAME} main.c utils.c config.c)
|
add_executable(${APP_NAME} main.c utils.c)
|
||||||
|
|
||||||
# use C17
|
# use C17
|
||||||
set_property(TARGET ${APP_NAME} PROPERTY C_STANDARD 17)
|
set_property(TARGET ${APP_NAME} PROPERTY C_STANDARD 17)
|
||||||
@@ -51,6 +51,7 @@ target_include_directories(${APP_NAME} SYSTEM
|
|||||||
)
|
)
|
||||||
target_include_directories(${APP_NAME}
|
target_include_directories(${APP_NAME}
|
||||||
PRIVATE "${SOURCE_DIR}/include"
|
PRIVATE "${SOURCE_DIR}/include"
|
||||||
|
PRIVATE "${SOURCE_DIR}"
|
||||||
PRIVATE ${CMAKE_BINARY_DIR}
|
PRIVATE ${CMAKE_BINARY_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
23
src/config.c
23
src/config.c
@@ -1,23 +0,0 @@
|
|||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
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,
|
|
||||||
};
|
|
||||||
60
src/config.h
Normal file
60
src/config.h
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#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},
|
||||||
|
};
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
/* 壁纸列表,支持通配符和 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[];
|
|
||||||
@@ -56,3 +56,20 @@ typedef struct wallpaper_config_t {
|
|||||||
uint32_t count;
|
uint32_t count;
|
||||||
char **path_list;
|
char **path_list;
|
||||||
} wallpaper_config_t;
|
} 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;
|
||||||
|
|||||||
15
src/main.c
15
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 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);
|
||||||
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 free_wallpaper_config(wallpaper_config_t *wallpaper_config);
|
||||||
static void init_xcb_event_loop(void);
|
static void init_xcb_event_loop(void);
|
||||||
static gboolean handle_xcb_event(GIOChannel *channel, GIOCondition condition,
|
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) {
|
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();
|
GStrvBuilder *builder = g_strv_builder_new();
|
||||||
const char *const *tags = NULL;
|
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];
|
const char *const *const *config = monitor_tags[i];
|
||||||
|
|
||||||
uint32_t monitor_count_in_tags_config = 0;
|
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) {
|
void init_wallpaper(void) {
|
||||||
wallpaper_config = parse_wallpaper_config(wallpager_list);
|
wallpaper_config = parse_wallpaper_config();
|
||||||
if (!wallpaper_config) return;
|
if (!wallpaper_config) return;
|
||||||
|
|
||||||
update_wallpaper(wallpaper_config);
|
update_wallpaper(wallpaper_config);
|
||||||
@@ -171,13 +168,13 @@ void set_wallpaper_by_index(uint32_t index) {
|
|||||||
free(screen_size);
|
free(screen_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
wallpaper_config_t *parse_wallpaper_config(const char **wallpapers) {
|
wallpaper_config_t *parse_wallpaper_config(void) {
|
||||||
if (!wallpapers) return NULL;
|
if (!LENGTH(wallpapers)) return NULL;
|
||||||
|
|
||||||
wallpaper_config_t *wc = ecalloc(1, sizeof(wallpaper_config_t));
|
wallpaper_config_t *wc = ecalloc(1, sizeof(wallpaper_config_t));
|
||||||
|
|
||||||
GStrvBuilder *builder = g_strv_builder_new();
|
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;
|
wordexp_t p;
|
||||||
if (wordexp(wallpapers[i], &p, 0)) continue;
|
if (wordexp(wallpapers[i], &p, 0)) continue;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user