summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAbhinav Prasai <72694427+uint23@users.noreply.github.com>2025-06-04 19:51:19 +0100
committerGitHub <noreply@github.com>2025-06-04 19:51:19 +0100
commit0582858f8693aa7455c4df5a7ff6440a5c31963d (patch)
tree204f90bb37ff749edd2eab394a92de0f08767cab /src
parent485e2b676a0a2380274de2d1b5ad6c6cdc16ce7e (diff)
parent7f79463c7b1881bdf1e7a76ebfd8d2a2e46213f4 (diff)
Merge pull request #58 from werdl/main
add exec config file keyword
Diffstat (limited to 'src')
-rw-r--r--src/defs.h1
-rw-r--r--src/parser.c40
-rw-r--r--src/sxwm.c26
3 files changed, 65 insertions, 2 deletions
diff --git a/src/defs.h b/src/defs.h
index 0075c21..53c7c6a 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -95,6 +95,7 @@ typedef struct {
Bool warp_cursor;
Binding binds[256];
char **should_float[256];
+ char *torun[256];
} Config;
typedef struct {
diff --git a/src/parser.c b/src/parser.c
index 3803f10..e9b4d16 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -163,7 +163,8 @@ int parser(Config *cfg)
fprintf(stderr, "sxwmrc: no configuration file found\n");
return -1;
-found:;
+found:
+ printf("sxwmrc: using configuration file %s\n", path);
FILE *f = fopen(path, "r");
if (!f) {
fprintf(stderr, "sxwmrc: cannot open %s\n", path);
@@ -173,6 +174,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++) {
@@ -375,11 +377,45 @@ found:;
fprintf(stderr, "sxwmrc:%d: invalid workspace action '%s'\n", lineno, act);
}
}
+ else if (!strcmp(key, "exec")) {
+ char *comment = strchr(rest, '#');
+ size_t len = comment ? (size_t)(comment - rest) : strlen(rest);
+ char win[len + 1];
+ strncpy(win, rest, len);
+ win[len] = '\0';
+
+ char *final = strip(win);
+ char *comma_ptr;
+
+ char *cmd = strip(final);
+ if (*cmd == '"') {
+ cmd++;
+ } else {
+ fprintf(stderr, "sxwmrc:%d: exec not enclosed in quotes", lineno);
+ }
+
+
+ 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 ac9e62e..bc6f922 100644
--- a/src/sxwm.c
+++ b/src/sxwm.c
@@ -1335,6 +1335,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");