From 53bf73d8a2c13577b92bc3c17e4bd22aa06c3e44 Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Sun, 23 Feb 2025 21:38:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=BB=98=E8=AE=A4=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=88=B0/etc/maomao/config.conf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- meson.build | 4 +++- parse_config.h | 17 +++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/meson.build b/meson.build index 1691617e..d0dbc3dc 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 ee296505..38edd13c 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(); }