From a77d543af2e6ccf5b53fe92761f7ac67c53dddb8 Mon Sep 17 00:00:00 2001 From: werdl Date: Mon, 19 May 2025 06:55:25 +0100 Subject: multiple should_float entries preliminary work --- src/defs.h | 2 +- src/parser.c | 30 ++++++++++++++++++++++++------ src/sxwm.c | 11 +++++++++-- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/defs.h b/src/defs.h index 6861262..d90ab61 100644 --- a/src/defs.h +++ b/src/defs.h @@ -87,7 +87,7 @@ typedef struct { int snap_distance; int bindsn; Binding binds[256]; - char *should_float[256]; + char **should_float[256]; } Config; typedef struct { diff --git a/src/parser.c b/src/parser.c index 1ceb7e0..e5f7944 100644 --- a/src/parser.c +++ b/src/parser.c @@ -228,7 +228,7 @@ found: cfg->snap_distance = atoi(rest); } else if (!strcmp(key, "should_float")) { - // should_float: + // should_float: binary --arg,binary2 parameter --arg,binary3 if (should_floatn >= 256) { fprintf(stderr, "sxwmrc:%d: too many should_float entries\n", lineno); @@ -237,13 +237,31 @@ found: char *win = strip(rest); - cfg->should_float[should_floatn] = malloc(strlen(win) + 1); - if (!cfg->should_float[should_floatn]) { - fprintf(stderr, "sxwmrc:%d: out of memory\n", lineno); - break; + int count = 0; + for (char *p = win; *p; p++) { + if (*p == ',') { + count++; + } + } + + cfg->should_float[should_floatn] = malloc((count + 2) * sizeof(char *)); + + // split by commas + char *comma = strtok(win, ","); + + int i = 0; + + while (comma) { + if (should_floatn < 256) { + cfg->should_float[should_floatn][i] = strdup(comma); + i++; + } else { + fprintf(stderr, "sxwmrc:%d: too many should_float entries\n", lineno); + break; + } + comma = strtok(NULL, ","); } - strcpy(cfg->should_float[should_floatn], win); should_floatn++; } else if (!strcmp(key, "call") || !strcmp(key, "bind")) { diff --git a/src/sxwm.c b/src/sxwm.c index a2dfdcd..878e9e2 100644 --- a/src/sxwm.c +++ b/src/sxwm.c @@ -591,8 +591,15 @@ void hdl_keypress(XEvent *xev) switch (b->type) { case TYPE_CMD: spawn(b->action.cmd); - for (int j = 0; j < 256; j++) { - if (user_config.should_float[j] && !strcmp(user_config.should_float[j], b->action.cmd[0])) { + for (int j = 0; j < 256; j++) { + Bool valid = False; + for (int k = 0; user_config.should_float[j] && user_config.should_float[j][k] && b->action.cmd[k]; k++) { + if (!strcmp(b->action.cmd[k], user_config.should_float[j][k])) { + valid = True; + break; + } + } + if (valid) { next_should_float = True; break; } -- cgit v1.2.3 From 176380fd65d0233ea6a5608bfb24d437deccbb0b Mon Sep 17 00:00:00 2001 From: werdl Date: Mon, 19 May 2025 19:08:30 +0100 Subject: add multiple should_float options --- README.md | 2 +- src/parser.c | 53 ++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 60811a1..bd00cd1 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ The file uses a `key : value` format. Lines starting with `#` are ignored. | `resize_master_amount` | Integer | `1` | Percent to increase/decrease master width. | | `snap_distance` | Integer | `5` | Distance (px) before a floating window snaps to edge. | | `motion_throttle` | Integer | `60` | Target FPS for mouse drag actions. | -| `should_float` | String | `st` | Always-float rule (can list multiple). | +| `should_float` | String | `"st"` | Always-float rule. Multiple entries should be comma-seperated. Optionally, entries can be enclosed in quotes.| --- diff --git a/src/parser.c b/src/parser.c index e5f7944..6ee0d6e 100644 --- a/src/parser.c +++ b/src/parser.c @@ -236,32 +236,46 @@ found: } char *win = strip(rest); - - int count = 0; - for (char *p = win; *p; p++) { - if (*p == ',') { - count++; - } - } - cfg->should_float[should_floatn] = malloc((count + 2) * sizeof(char *)); - - // split by commas - char *comma = strtok(win, ","); + cfg->should_float[should_floatn] = malloc(256 * sizeof(char *)); - int i = 0; + char *comma_ptr, *space_ptr; + char *comma = strtok_r(win, ",", &comma_ptr); while (comma) { if (should_floatn < 256) { - cfg->should_float[should_floatn][i] = strdup(comma); - i++; + // if comma starts and ends with quotes, remove them + if (*comma == '"') { + comma++; + } + char *end = comma + strlen(comma) - 1; + if (*end == '"') { + *end = '\0'; + } + + printf("comma: %s\n", comma); + char *argv = strtok_r(comma, " ", &space_ptr); + int i = 0; + + + while (argv) { + printf("argv: %s\n", argv); + cfg->should_float[should_floatn][i] = strdup(argv); + argv = strtok_r(NULL, " ", &space_ptr); + i++; + } + + should_floatn++; + cfg->should_float[should_floatn] = malloc(256 * sizeof(char *)); + } else { fprintf(stderr, "sxwmrc:%d: too many should_float entries\n", lineno); break; } - comma = strtok(NULL, ","); + comma = strtok_r(NULL, ",", &comma_ptr); } + should_floatn++; } else if (!strcmp(key, "call") || !strcmp(key, "bind")) { @@ -345,6 +359,15 @@ found: } } + // print should_float + for (int i = 0; i < should_floatn; i++) { + fprintf(stderr, "sxwmrc: should_float[%d]: ", i); + for (int j = 0; cfg->should_float[i][j]; j++) { + fprintf(stderr, "%s ", cfg->should_float[i][j]); + } + fprintf(stderr, "\n"); + } + fclose(f); remap_and_dedupe_binds(cfg); return 0; -- cgit v1.2.3 From f0c4d01c33fd133eb0a09a970e12844d9ed17137 Mon Sep 17 00:00:00 2001 From: werdl Date: Mon, 19 May 2025 19:14:53 +0100 Subject: add sxwmrc copying to Makefile --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 2721383..adeb0e3 100644 --- a/Makefile +++ b/Makefile @@ -42,6 +42,9 @@ install: all @echo "Installing man page to $(DESTDIR)$(MAN_DIR)..." @mkdir -p $(DESTDIR)$(MAN_DIR) @install -m 644 $(MAN) $(DESTDIR)$(MAN_DIR)/ + @echo "Copying default configuration to $(DESTDIR)$(PREFIX)/share/sxwmrc..." + @mkdir -p "$(DESTDIR)$(PREFIX)/share" + @install -m 644 default_sxrc "$(DESTDIR)$(PREFIX)/share/sxwmrc" @echo "Installation complete." uninstall: -- cgit v1.2.3