diff --git a/src/config/parse_config.h b/src/config/parse_config.h index 4e811d5..45143cc 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -33,6 +33,11 @@ typedef struct { Arg arg; } KeyBinding; +typedef struct { + char *type; + char *value; +} ConfigEnv; + typedef struct { const char *id; const char *title; @@ -278,6 +283,9 @@ typedef struct { GestureBinding *gesture_bindings; int gesture_bindings_count; + ConfigEnv **env; + int env_count; + char **exec; int exec_count; @@ -861,6 +869,12 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value, return func; } +void set_env() { + for (int i = 0; i < config.env_count; i++) { + setenv(config.env[i]->type, config.env[i]->value, 1); + } +} + void run_exec() { Arg arg; @@ -1611,7 +1625,23 @@ void parse_config_line(Config *config, const char *line) { } trim_whitespace(env_type); trim_whitespace(env_value); - setenv(env_type, env_value, 1); + + ConfigEnv *env = calloc(1, sizeof(ConfigEnv)); + env->type = strdup(env_type); + env->value = strdup(env_value); + + config->env = + realloc(config->env, (config->env_count + 1) * sizeof(ConfigEnv)); + if (!config->env) { + free(env->type); + free(env->value); + free(env); + fprintf(stderr, "Error: Failed to allocate memory for env\n"); + return; + } + + config->env[config->env_count] = env; + config->env_count++; } else if (strncmp(key, "exec", 9) == 0) { char **new_exec = @@ -2205,6 +2235,22 @@ void free_config(void) { config.layer_rules_count = 0; } + // 释放 env + if (config.env) { + for (int i = 0; i < config.env_count; i++) { + if (config.env[i]->type) { + free((void *)config.env[i]->type); + } + if (config.env[i]->value) { + free((void *)config.env[i]->value); + } + free(config.env[i]); + } + free(config.env); + config.env = NULL; + config.env_count = 0; + } + // 释放 exec if (config.exec) { for (i = 0; i < config.exec_count; i++) { @@ -2572,6 +2618,8 @@ void parse_config(void) { config.switch_bindings_count = 0; config.gesture_bindings = NULL; config.gesture_bindings_count = 0; + config.env = NULL; + config.env_count = 0; config.exec = NULL; config.exec_count = 0; config.exec_once = NULL; @@ -2770,6 +2818,7 @@ void reload_config(const Arg *arg) { init_baked_points(); handlecursoractivity(); reset_keyboard_layout(); + set_env(); run_exec(); reapply_border(); diff --git a/src/mango.c b/src/mango.c index fcb8679..9d1b76f 100644 --- a/src/mango.c +++ b/src/mango.c @@ -4114,6 +4114,9 @@ void exchange_two_client(Client *c1, Client *c2) { void // 17 run(char *startup_cmd) { + + set_env(); + char autostart_temp_path[1024]; /* Add a Unix socket to the Wayland display. */ const char *socket = wl_display_add_socket_auto(dpy); @@ -4585,6 +4588,8 @@ void setup(void) { setenv("XCURSOR_SIZE", "24", 1); setenv("XDG_CURRENT_DESKTOP", "mango", 1); + parse_config(); + init_baked_points(); int drm_fd, i, sig[] = {SIGCHLD, SIGINT, SIGTERM, SIGPIPE}; struct sigaction sa = {.sa_flags = SA_RESTART, .sa_handler = handlesig}; @@ -4866,8 +4871,6 @@ void setup(void) { "failed to setup XWayland X server, continuing without it\n"); } #endif - parse_config(); - init_baked_points(); } void startdrag(struct wl_listener *listener, void *data) {