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