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