summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/defs.h1
-rw-r--r--src/parser.c66
-rw-r--r--src/sxwm.c53
3 files changed, 78 insertions, 42 deletions
diff --git a/src/defs.h b/src/defs.h
index db71409..3b8d7fc 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -92,6 +92,7 @@ typedef struct {
Bool new_win_focus;
Binding binds[256];
char **should_float[256];
+ char *torun[256];
} Config;
typedef struct {
diff --git a/src/parser.c b/src/parser.c
index baa15a0..cfd7c00 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -171,6 +171,7 @@ found:
char line[512];
int lineno = 0;
int should_floatn = 0;
+ int torun = 0;
// Initialize should_float matrix
for (int j = 0; j < 256; j++) {
@@ -365,55 +366,36 @@ found:
char *final = strip(win);
char *comma_ptr;
- printf("DEBUG: exec command: '%s'\n", final);
- char *comma = strtok_r(final, ",", &comma_ptr);
- while (comma) {
- comma = strip(comma);
- if (*comma == '"') {
- comma++;
- }
- char *end = comma + strlen(comma) - 1;
- if (*end == '"') {
- *end = '\0';
- }
+ char *cmd = strip(final);
+ if (*cmd == '"') {
+ cmd++;
+ } else {
+ fprintf(stderr, "sxwmrc:%d: exec not enclosed in quotes", lineno);
+ }
- char *cmd = strdup(comma);
-
- // we have to fork and exec, because system() is blocking
- pid_t pid = fork();
- if (pid == 0) {
- char *argv[64];
- char *argv_ptr;
- int i = 0;
- char *arg = strtok_r(cmd, " ", &argv_ptr);
- while (arg && i < 63) {
- argv[i++] = arg;
- arg = strtok_r(NULL, " ", &argv_ptr);
- }
- argv[i] = NULL;
- execvp(argv[0], argv);
- perror("execvp");
- _exit(127);
- }
- else if (pid > 0) {
- // parent: don’t wait, just continue (background)
- }
- else {
- perror("fork");
- }
-
- printf("DEBUG: exec command: '%s'\n", comma);
-
- comma = strtok_r(NULL, ",", &comma_ptr);
- }
- }
+ char *end = cmd + strlen(cmd) - 1;
+ if (*end == '"') {
+ *end = '\0';
+ } else {
+ fprintf(stderr, "sxwmrc:%d: exec not enclosed in quotes", lineno);
+ }
+
+ printf("DEBUG: exec command '%s'\n", cmd);
+ cfg->torun[torun] = strdup(cmd);
+
+ if (torun > 254) {
+ fprintf(stderr, "sxwmrc:%d: too many execs", lineno);
+ } else {
+ torun++;
+ }
+ }
else {
fprintf(stderr, "sxwmrc:%d: unknown option '%s'\n", lineno, key);
}
}
-
+
fclose(f);
remap_and_dedupe_binds(cfg);
return 0;
diff --git a/src/sxwm.c b/src/sxwm.c
index c1eeb25..6b98c6b 100644
--- a/src/sxwm.c
+++ b/src/sxwm.c
@@ -1144,6 +1144,33 @@ void reload_config(void)
fprintf(stderr, "sxrc: error parsing config file\n");
init_defaults();
}
+
+ for (int i = 0; i < 256; i++) {
+ if (user_config.torun[i]) {
+ printf("[DEBUG] executing %s\n", user_config.torun[i]);
+ pid_t pid = fork();
+ if (pid == 0) {
+ char *argv[256];
+ int j = 0;
+ char *arg = strtok(user_config.torun[i], " ");
+ while (arg && j < 256) {
+ argv[j++] = arg;
+ arg = strtok(NULL, " ");
+ }
+ argv[j] = NULL;
+ execvp(argv[0], argv);
+ perror("execvp");
+ _exit(127);
+ }
+ else if (pid > 0) {
+ // parent: don’t wait, just continue (background)
+ }
+ else {
+ perror("fork");
+ }
+ }
+ }
+
grab_keys();
XUngrabButton(dpy, AnyButton, AnyModifier, root);
XGrabButton(dpy, Button1, user_config.modkey, root, True, ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
@@ -1251,6 +1278,32 @@ void setup(void)
fprintf(stderr, "sxrc: error parsing config file\n");
init_defaults();
}
+
+ for (int i = 0; i < 256; i++) {
+ if (user_config.torun[i]) {
+ printf("[DEBUG] executing %s\n", user_config.torun[i]);
+ pid_t pid = fork();
+ if (pid == 0) {
+ char *argv[256];
+ int j = 0;
+ char *arg = strtok(user_config.torun[i], " ");
+ while (arg && j < 256) {
+ argv[j++] = arg;
+ arg = strtok(NULL, " ");
+ }
+ argv[j] = NULL;
+ execvp(argv[0], argv);
+ perror("execvp");
+ _exit(127);
+ }
+ else if (pid > 0) {
+ // parent: don’t wait, just continue (background)
+ }
+ else {
+ perror("fork");
+ }
+ }
+ }
grab_keys();
c_normal = XcursorLibraryLoadCursor(dpy, "left_ptr");