From 9030579b18a5be4c132e23ea4f599043e4164340 Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Sun, 23 Feb 2025 21:37:59 +0800 Subject: [PATCH] feat: install default config.conf to /etc/maomao/config.conf --- README.md | 5 ++++- meson.build | 4 +++- parse_config.h | 17 +++++++++++------ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 829a15d..b95f62c 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,8 @@ mkdir -p ~/.config/maomao/ # config -you can use `MAOMAOCONFIG` env to set the config folder path +you can use `MAOMAOCONFIG` env to set the config-folder-path and the autostart-folder-patch +like `MAOMAOCONFIG=/home/xxx/maomao` - the only default keybinds is ctrl+alt+[F1-F12] to change tty @@ -94,6 +95,8 @@ you can use `MAOMAOCONFIG` env to set the config folder path - the default autostart path is `~/.config/maomao/autostart.sh` +- the fallback config path is in /etc/maomao/config.conf + # my dotfile [maomao-config](https://github.com/DreamMaoMao/dotfile/tree/main/maomao) diff --git a/meson.build b/meson.build index 1691617..d0dbc3d 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project('maomao', ['c', 'cpp'], - version : '0.1.1' + version : '0.1.5' ) subdir('protocols') @@ -71,3 +71,5 @@ executable('maomao', prefix = get_option('prefix') desktop_install_dir = join_paths(prefix, 'share/wayland-sessions') install_data('maomao.desktop', install_dir : desktop_install_dir) +install_data('config.conf', install_dir : '/etc/maomao') + diff --git a/parse_config.h b/parse_config.h index ee29650..38edd13 100644 --- a/parse_config.h +++ b/parse_config.h @@ -990,9 +990,9 @@ void parse_config(void) { config.axis_bindings = NULL; config.axis_bindings_count = 0; -// 获取 MAOMAOCONFIG 环境变量 -const char *maomaoconfig = getenv("MAOMAOCONFIG"); - + // 获取 MAOMAOCONFIG 环境变量 + const char *maomaoconfig = getenv("MAOMAOCONFIG"); + // 如果 MAOMAOCONFIG 环境变量不存在或为空,则使用 HOME 环境变量 if (!maomaoconfig || maomaoconfig[0] == '\0') { // 获取当前用户家目录 @@ -1003,14 +1003,19 @@ const char *maomaoconfig = getenv("MAOMAOCONFIG"); } // 构建日志文件路径 snprintf(filename, sizeof(filename), "%s/.config/maomao/config.conf", homedir); + + // 检查文件是否存在 + if (access(filename, F_OK) != 0) { + // 如果文件不存在,则使用 /etc/maomao/config.conf + snprintf(filename, sizeof(filename), "/etc/maomao/config.conf"); + } } else { // 使用 MAOMAOCONFIG 环境变量作为配置文件夹路径 snprintf(filename, sizeof(filename), "%s/config.conf", maomaoconfig); } - set_value_default(); - parse_config_file(&config, filename); - +set_value_default(); +parse_config_file(&config, filename); override_config(); }