summaryrefslogtreecommitdiff
path: root/src/parser.c
diff options
context:
space:
mode:
authorAbhinav <abhinav.prsai@gmail.com>2025-06-24 01:07:50 +0100
committerAbhinav <abhinav.prsai@gmail.com>2025-06-24 01:07:50 +0100
commitde5be2ff9d3e8d0c0f3c725a9fb9ea7046c12862 (patch)
treef6dc8812e49366ddcdca67a04921b4938e2e1823 /src/parser.c
parentcc234a66f020256ca2cd2a0a189fda00195bb8f0 (diff)
add open_in_workspace
user can now open specific windows in specific workspaces
Diffstat (limited to 'src/parser.c')
-rw-r--r--src/parser.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/parser.c b/src/parser.c
index b230fa6..eb0b1a8 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -484,6 +484,43 @@ found:
else if (!strcmp(key, "new_win_master")) {
cfg->new_win_master = !strcmp(rest, "true") ? True : False;
}
+ else if (!strcmp(key, "open_in_workspace")) {
+ char *mid = strchr(rest, ':');
+ if (!mid) {
+ fprintf(stderr, "sxwmrc:%d: open_in_workspace missing workspace number\n", lineno);
+ continue;
+ }
+ *mid = '\0';
+ char *class_name = strip(rest);
+ char *ws_str = strip(mid + 1);
+
+ class_name = strip_quotes(class_name);
+
+ int ws = atoi(ws_str);
+ if (ws < 1 || ws > NUM_WORKSPACES) {
+ fprintf(stderr, "sxwmrc:%d: invalid workspace number %d\n", lineno, ws);
+ continue;
+ }
+
+ /* find free slot in open_in_workspace */
+ int slot = -1;
+ for (int i = 0; i < 256; i++) {
+ if (!cfg->open_in_workspace[i]) {
+ slot = i;
+ break;
+ }
+ }
+
+ if (slot >= 0) {
+ cfg->open_in_workspace[slot] = malloc(2 * sizeof(char *));
+ if (cfg->open_in_workspace[slot]) {
+ cfg->open_in_workspace[slot][0] = strdup(class_name); /* class name */
+ char ws_buf[16];
+ snprintf(ws_buf, sizeof(ws_buf), "%d", ws - 1); /* 0-indexed workspace */
+ cfg->open_in_workspace[slot][1] = strdup(ws_buf); /* workspace number */
+ }
+ }
+ }
else {
fprintf(stderr, "sxwmrc:%d: unknown option '%s'\n", lineno, key);
}