diff options
| -rw-r--r-- | README.md | 7 | ||||
| -rw-r--r-- | src/parser.c | 33 | ||||
| -rw-r--r-- | src/sxwm.c | 31 |
3 files changed, 47 insertions, 24 deletions
@@ -227,6 +227,13 @@ slackpkg install gcc make libX11 libXinerama</code></pre> </details> <details> +<summary>OpenBSD</summary> +<pre><code>doas pkg_add gmake</code></pre> +You will also need the X sets (<code>xbase</code>, <code>xfonts</code>, <code>xserv</code> and <code>xshare</code>) installed. +When you make the code, use <code>gmake</code> instead of <code>make</code> (which will be BSD make). Use the following command to build: <code>gmake CFLAGS="-I/usr/X11R6/include -Wall -Wextra -O3 -Isrc" LDFLAGS="-L/usr/X11R6/lib -lX11 -lXinerama -lXcursor"</code> +</details> + +<details> <summary>FreeBSD</summary> <pre><code># If you use doas or su instead of sudo, modify the following commands accordingly. sudo pkg update diff --git a/src/parser.c b/src/parser.c index eb6ba21..c2c6e23 100644 --- a/src/parser.c +++ b/src/parser.c @@ -158,6 +158,9 @@ int parser(Config *cfg) } found: + if (0) { + } // label followed by declaration is a C23 extension + FILE *f = fopen(path, "r"); if (!f) { fprintf(stderr, "sxwmrc: cannot open %s\n", path); @@ -168,8 +171,8 @@ found: int lineno = 0; int should_floatn = 0; - for (int i = 0; i < 256; i++) { - cfg->should_float[i] = NULL; + for (int j = 0; j < 256; j++) { + cfg->should_float[j] = calloc(256, sizeof(char *)); // allocate array of 256 strings } while (fgets(line, sizeof line, f)) { @@ -237,10 +240,20 @@ found: char *win = strip(rest); - cfg->should_float[should_floatn] = malloc(256 * sizeof(char *)); - + // remove comments + char *nocom = malloc(strlen(win) + 1); + char *comment = strchr(win, '#'); + if (comment) { + strncpy(nocom, win, comment - win); + nocom[comment - win] = '\0'; + } else { + strcpy(nocom, win); + } + + char *final = strip(nocom); + char *comma_ptr, *space_ptr; - char *comma = strtok_r(win, ",", &comma_ptr); + char *comma = strtok_r(final, ",", &comma_ptr); while (comma) { if (should_floatn < 256) { @@ -265,7 +278,6 @@ found: } should_floatn++; - cfg->should_float[should_floatn] = malloc(256 * sizeof(char *)); } else { fprintf(stderr, "sxwmrc:%d: too many should_float entries\n", lineno); @@ -357,15 +369,6 @@ 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; @@ -614,20 +614,33 @@ void hdl_keypress(XEvent *xev) switch (b->type) { case TYPE_CMD: spawn(b->action.cmd); + + next_should_float = False; 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) { + Bool all_matching = True; + for (int k = 0; k < 256; k++) { + if (!user_config.should_float[j] || !b->action.cmd) + continue; + + if (!user_config.should_float[j][k] || !b->action.cmd[k]) { + all_matching = (!user_config.should_float[j][k] && !b->action.cmd[k]); + break; + } + // confirm these two entries match + if (strcmp(user_config.should_float[j][k], b->action.cmd[k]) != 0) { + all_matching = False; + printf("%s != %s\n", user_config.should_float[j][k], b->action.cmd[k]); + break; + } + } + if (all_matching) { + next_should_float = True; break; } } + + end: break; case TYPE_FUNC: if (b->action.fn) |
