fix: miss apply some config

This commit is contained in:
DreamMaoMao 2025-09-29 20:57:22 +08:00
parent 56a060a840
commit 4708c10b89
2 changed files with 55 additions and 3 deletions

View file

@ -33,6 +33,11 @@ typedef struct {
Arg arg; Arg arg;
} KeyBinding; } KeyBinding;
typedef struct {
char *type;
char *value;
} ConfigEnv;
typedef struct { typedef struct {
const char *id; const char *id;
const char *title; const char *title;
@ -278,6 +283,9 @@ typedef struct {
GestureBinding *gesture_bindings; GestureBinding *gesture_bindings;
int gesture_bindings_count; int gesture_bindings_count;
ConfigEnv **env;
int env_count;
char **exec; char **exec;
int exec_count; int exec_count;
@ -861,6 +869,12 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value,
return func; 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() { void run_exec() {
Arg arg; Arg arg;
@ -1611,7 +1625,23 @@ void parse_config_line(Config *config, const char *line) {
} }
trim_whitespace(env_type); trim_whitespace(env_type);
trim_whitespace(env_value); 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) { } else if (strncmp(key, "exec", 9) == 0) {
char **new_exec = char **new_exec =
@ -2205,6 +2235,22 @@ void free_config(void) {
config.layer_rules_count = 0; 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 // 释放 exec
if (config.exec) { if (config.exec) {
for (i = 0; i < config.exec_count; i++) { for (i = 0; i < config.exec_count; i++) {
@ -2572,6 +2618,8 @@ void parse_config(void) {
config.switch_bindings_count = 0; config.switch_bindings_count = 0;
config.gesture_bindings = NULL; config.gesture_bindings = NULL;
config.gesture_bindings_count = 0; config.gesture_bindings_count = 0;
config.env = NULL;
config.env_count = 0;
config.exec = NULL; config.exec = NULL;
config.exec_count = 0; config.exec_count = 0;
config.exec_once = NULL; config.exec_once = NULL;
@ -2770,6 +2818,7 @@ void reload_config(const Arg *arg) {
init_baked_points(); init_baked_points();
handlecursoractivity(); handlecursoractivity();
reset_keyboard_layout(); reset_keyboard_layout();
set_env();
run_exec(); run_exec();
reapply_border(); reapply_border();

View file

@ -4114,6 +4114,9 @@ void exchange_two_client(Client *c1, Client *c2) {
void // 17 void // 17
run(char *startup_cmd) { run(char *startup_cmd) {
set_env();
char autostart_temp_path[1024]; char autostart_temp_path[1024];
/* Add a Unix socket to the Wayland display. */ /* Add a Unix socket to the Wayland display. */
const char *socket = wl_display_add_socket_auto(dpy); const char *socket = wl_display_add_socket_auto(dpy);
@ -4585,6 +4588,8 @@ void setup(void) {
setenv("XCURSOR_SIZE", "24", 1); setenv("XCURSOR_SIZE", "24", 1);
setenv("XDG_CURRENT_DESKTOP", "mango", 1); setenv("XDG_CURRENT_DESKTOP", "mango", 1);
parse_config();
init_baked_points();
int drm_fd, i, sig[] = {SIGCHLD, SIGINT, SIGTERM, SIGPIPE}; int drm_fd, i, sig[] = {SIGCHLD, SIGINT, SIGTERM, SIGPIPE};
struct sigaction sa = {.sa_flags = SA_RESTART, .sa_handler = handlesig}; 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"); "failed to setup XWayland X server, continuing without it\n");
} }
#endif #endif
parse_config();
init_baked_points();
} }
void startdrag(struct wl_listener *listener, void *data) { void startdrag(struct wl_listener *listener, void *data) {