summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/parser.c33
-rw-r--r--src/sxwm.c31
2 files changed, 40 insertions, 24 deletions
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;
diff --git a/src/sxwm.c b/src/sxwm.c
index 91c0839..3140412 100644
--- a/src/sxwm.c
+++ b/src/sxwm.c
@@ -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)