diff options
Diffstat (limited to 'src/parser.c')
| -rw-r--r-- | src/parser.c | 88 |
1 files changed, 46 insertions, 42 deletions
diff --git a/src/parser.c b/src/parser.c index cfd7c00..e9b4d16 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1,12 +1,13 @@ #define _POSIX_C_SOURCE 200809L -#include <X11/Xlib.h> #include <ctype.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> -#include <unistd.h> #include <string.h> +#include <unistd.h> +#include <wordexp.h> #include <X11/keysym.h> +#include <X11/Xlib.h> #include "parser.h" #include "defs.h" @@ -25,6 +26,8 @@ static const struct { {"reload_config", reload_config}, {"master_increase", resize_master_add}, {"master_decrease", resize_master_sub}, + {"stack_increase", resize_stack_add}, + {"stack_decrease", resize_stack_sub}, {"toggle_floating", toggle_floating}, {"global_floating", toggle_floating_global}, {"fullscreen", toggle_fullscreen}, @@ -132,7 +135,7 @@ int parser(Config *cfg) return -1; } - // Determine config file path + /* determine config file path */ const char *xdg_config_home = getenv("XDG_CONFIG_HOME"); if (xdg_config_home) { snprintf(path, sizeof path, "%s/sxwmrc", xdg_config_home); @@ -156,7 +159,7 @@ int parser(Config *cfg) goto found; } - // Nothing found + /* Nothing found */ fprintf(stderr, "sxwmrc: no configuration file found\n"); return -1; @@ -173,7 +176,7 @@ found: int should_floatn = 0; int torun = 0; - // Initialize should_float matrix + /* Initialize should_float matrix */ for (int j = 0; j < 256; j++) { cfg->should_float[j] = calloc(256, sizeof(char *)); if (!cfg->should_float[j]) { @@ -202,7 +205,7 @@ found: if (!strcmp(key, "mod_key")) { unsigned m = parse_mods(rest, cfg); - if (m & (Mod1Mask | Mod4Mask)) { + if (m & (Mod1Mask | Mod4Mask | ShiftMask | ControlMask)) { cfg->modkey = m; } else { @@ -232,6 +235,14 @@ found: cfg->new_win_focus = False; } } + else if (!strcmp(key, "warp_cursor")) { + if (!strcmp(rest, "true")) { + cfg->warp_cursor = True; + } + else { + cfg->warp_cursor = False; + } + } else if (!strcmp(key, "master_width")) { float mf = (float)atoi(rest) / 100.0f; for (int i = 0; i < MAX_MONITORS; i++) { @@ -244,6 +255,9 @@ found: else if (!strcmp(key, "resize_master_amount")) { cfg->resize_master_amt = atoi(rest); } + else if (!strcmp(key, "resize_stack_amount")) { + cfg->resize_stack_amt = atoi(rest); + } else if (!strcmp(key, "snap_distance")) { cfg->snap_distance = atoi(rest); } @@ -266,15 +280,16 @@ found: /* store each comma separated value in a seperate row */ while (comma && should_floatn < 256) { comma = strip(comma); - if (*comma == '"') + if (*comma == '"') { comma++; + } char *end = comma + strlen(comma) - 1; - if (*end == '"') + if (*end == '"') { *end = '\0'; + } /* store each programs name in its own row at index 0 */ cfg->should_float[should_floatn][0] = strdup(comma); - printf("DEBUG: should_float[%d][0] = '%s'\n", should_floatn, cfg->should_float[should_floatn][0]); should_floatn++; comma = strtok_r(NULL, ",", &comma_ptr); } @@ -305,7 +320,12 @@ found: if (*act == '"' && !strcmp(key, "bind")) { b->type = TYPE_CMD; b->action.cmd = build_argv(strip_quotes(act)); + if (!b->action.cmd) { + fprintf(stderr, "sxwmrc:%d: failed to parse command: %s\n", lineno, act); + b->type = -1; + } } + else { b->type = TYPE_FUNC; Bool found = False; @@ -445,39 +465,23 @@ KeySym parse_keysym(const char *key) const char **build_argv(const char *cmd) { - char *dup = strdup(cmd); - char *saveptr = NULL; - const char **argv = malloc(MAX_ARGS * sizeof(*argv)); - int i = 0; - - char *tok = strtok_r(dup, " \t", &saveptr); - while (tok && i < MAX_ARGS - 1) { - if (*tok == '"') { - char *end = tok + strlen(tok) - 1; - if (*end == '"') { - *end = '\0'; - argv[i++] = strdup(tok + 1); - } - else { - char *quoted = strdup(tok + 1); - while ((tok = strtok_r(NULL, " \t", &saveptr)) && *tok != '"') { - quoted = realloc(quoted, strlen(quoted) + strlen(tok) + 2); - strcat(quoted, " "); - strcat(quoted, tok); - } - if (tok && *tok == '"') { - quoted = realloc(quoted, strlen(quoted) + strlen(tok)); - strcat(quoted, tok); - } - argv[i++] = quoted; - } - } - else { - argv[i++] = strdup(tok); - } - tok = strtok_r(NULL, " \t", &saveptr); + wordexp_t p; + if (wordexp(cmd, &p, 0) != 0 || p.we_wordc == 0) { + fprintf(stderr, "sxwm: wordexp failed for cmd: '%s'\n", cmd); + return NULL; + } + + const char **argv = malloc((p.we_wordc + 1) * sizeof(char *)); + if (!argv) { + wordfree(&p); + return NULL; } - argv[i] = NULL; - free(dup); + + for (size_t i = 0; i < p.we_wordc; i++) { + argv[i] = strdup(p.we_wordv[i]); + } + argv[p.we_wordc] = NULL; + + wordfree(&p); return argv; } |
