mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-05-05 06:47:12 -04:00
feat: add -c arg for config file
This commit is contained in:
parent
8e4d3b7aac
commit
75b91d64be
2 changed files with 37 additions and 30 deletions
|
|
@ -2943,7 +2943,7 @@ void set_default_key_bindings(Config *config) {
|
||||||
config->key_bindings_count += default_key_bindings_count;
|
config->key_bindings_count += default_key_bindings_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_config(void) {
|
void parse_config(const char *cli_config_file) {
|
||||||
|
|
||||||
char filename[1024];
|
char filename[1024];
|
||||||
|
|
||||||
|
|
@ -2989,30 +2989,34 @@ void parse_config(void) {
|
||||||
|
|
||||||
create_config_keymap();
|
create_config_keymap();
|
||||||
|
|
||||||
// 获取 MANGOCONFIG 环境变量
|
if (cli_config_path != NULL) {
|
||||||
const char *mangoconfig = getenv("MANGOCONFIG");
|
snprintf(filename, sizeof(filename), "%s", cli_config_path);
|
||||||
|
|
||||||
// 如果 MANGOCONFIG 环境变量不存在或为空,则使用 HOME 环境变量
|
|
||||||
if (!mangoconfig || mangoconfig[0] == '\0') {
|
|
||||||
// 获取当前用户家目录
|
|
||||||
const char *homedir = getenv("HOME");
|
|
||||||
if (!homedir) {
|
|
||||||
// 如果获取失败,则无法继续
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 构建日志文件路径
|
|
||||||
snprintf(filename, sizeof(filename), "%s/.config/mango/config.conf",
|
|
||||||
homedir);
|
|
||||||
|
|
||||||
// 检查文件是否存在
|
|
||||||
if (access(filename, F_OK) != 0) {
|
|
||||||
// 如果文件不存在,则使用 /etc/mango/config.conf
|
|
||||||
snprintf(filename, sizeof(filename), "%s/mango/config.conf",
|
|
||||||
SYSCONFDIR);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// 使用 MANGOCONFIG 环境变量作为配置文件夹路径
|
// 获取 MANGOCONFIG 环境变量
|
||||||
snprintf(filename, sizeof(filename), "%s/config.conf", mangoconfig);
|
const char *mangoconfig = getenv("MANGOCONFIG");
|
||||||
|
|
||||||
|
// 如果 MANGOCONFIG 环境变量不存在或为空,则使用 HOME 环境变量
|
||||||
|
if (!mangoconfig || mangoconfig[0] == '\0') {
|
||||||
|
// 获取当前用户家目录
|
||||||
|
const char *homedir = getenv("HOME");
|
||||||
|
if (!homedir) {
|
||||||
|
// 如果获取失败,则无法继续
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 构建日志文件路径
|
||||||
|
snprintf(filename, sizeof(filename), "%s/.config/mango/config.conf",
|
||||||
|
homedir);
|
||||||
|
|
||||||
|
// 检查文件是否存在
|
||||||
|
if (access(filename, F_OK) != 0) {
|
||||||
|
// 如果文件不存在,则使用 /etc/mango/config.conf
|
||||||
|
snprintf(filename, sizeof(filename), "%s/mango/config.conf",
|
||||||
|
SYSCONFDIR);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 使用 MANGOCONFIG 环境变量作为配置文件夹路径
|
||||||
|
snprintf(filename, sizeof(filename), "%s/config.conf", mangoconfig);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
set_value_default();
|
set_value_default();
|
||||||
|
|
|
||||||
15
src/mango.c
15
src/mango.c
|
|
@ -628,7 +628,7 @@ static void setgaps(int oh, int ov, int ih, int iv);
|
||||||
static void setmon(Client *c, Monitor *m, unsigned int newtags, bool focus);
|
static void setmon(Client *c, Monitor *m, unsigned int newtags, bool focus);
|
||||||
static void setpsel(struct wl_listener *listener, void *data);
|
static void setpsel(struct wl_listener *listener, void *data);
|
||||||
static void setsel(struct wl_listener *listener, void *data);
|
static void setsel(struct wl_listener *listener, void *data);
|
||||||
static void setup(void);
|
static void setup(const char *config_file);
|
||||||
static void startdrag(struct wl_listener *listener, void *data);
|
static void startdrag(struct wl_listener *listener, void *data);
|
||||||
|
|
||||||
static void unlocksession(struct wl_listener *listener, void *data);
|
static void unlocksession(struct wl_listener *listener, void *data);
|
||||||
|
|
@ -4852,11 +4852,11 @@ void create_output(struct wlr_backend *backend, void *data) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup(void) {
|
void setup(const char *config_file) {
|
||||||
|
|
||||||
setenv("XCURSOR_SIZE", "24", 1);
|
setenv("XCURSOR_SIZE", "24", 1);
|
||||||
setenv("XDG_CURRENT_DESKTOP", "mango", 1);
|
setenv("XDG_CURRENT_DESKTOP", "mango", 1);
|
||||||
parse_config();
|
parse_config(config_file);
|
||||||
init_baked_points();
|
init_baked_points();
|
||||||
|
|
||||||
int drm_fd, i, sig[] = {SIGCHLD, SIGINT, SIGTERM, SIGPIPE};
|
int drm_fd, i, sig[] = {SIGCHLD, SIGINT, SIGTERM, SIGPIPE};
|
||||||
|
|
@ -5858,11 +5858,14 @@ static void setgeometrynotify(struct wl_listener *listener, void *data) {
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
char *startup_cmd = NULL;
|
char *startup_cmd = NULL;
|
||||||
|
char *config_file = NULL;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "s:hdv")) != -1) {
|
while ((c = getopt(argc, argv, "s:c:hdv")) != -1) {
|
||||||
if (c == 's')
|
if (c == 's')
|
||||||
startup_cmd = optarg;
|
startup_cmd = optarg;
|
||||||
|
else if (c == 'c')
|
||||||
|
config_file = optarg;
|
||||||
else if (c == 'd')
|
else if (c == 'd')
|
||||||
log_level = WLR_DEBUG;
|
log_level = WLR_DEBUG;
|
||||||
else if (c == 'v')
|
else if (c == 'v')
|
||||||
|
|
@ -5878,11 +5881,11 @@ int main(int argc, char *argv[]) {
|
||||||
*/
|
*/
|
||||||
if (!getenv("XDG_RUNTIME_DIR"))
|
if (!getenv("XDG_RUNTIME_DIR"))
|
||||||
die("XDG_RUNTIME_DIR must be set");
|
die("XDG_RUNTIME_DIR must be set");
|
||||||
setup();
|
setup(config_file);
|
||||||
run(startup_cmd);
|
run(startup_cmd);
|
||||||
cleanup();
|
cleanup();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
||||||
usage:
|
usage:
|
||||||
die("Usage: %s [-v] [-d] [-s startup command]", argv[0]);
|
die("Usage: %s [-v] [-d] [-c config_file] [-s startup command]", argv[0]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue