diff options
Diffstat (limited to 'src/parser.c')
| -rw-r--r-- | src/parser.c | 126 |
1 files changed, 122 insertions, 4 deletions
diff --git a/src/parser.c b/src/parser.c index 3fc2856..79cf29b 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1,6 +1,6 @@ #define _POSIX_C_SOURCE 200809L #include <ctype.h> -#include <limits.h> +#include <linux/limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -9,6 +9,7 @@ #include <wordexp.h> #endif #include <X11/keysym.h> +#include <X11/XF86keysym.h> #include <X11/Xlib.h> #include "parser.h" #include "defs.h" @@ -36,6 +37,7 @@ static const struct { {"toggle_floating", toggle_floating}, {"global_floating", toggle_floating_global}, {"fullscreen", toggle_fullscreen}, + {"centre_window", centre_window}, {NULL, NULL}}; static void remap_and_dedupe_binds(Config *cfg) @@ -367,17 +369,58 @@ found: int n; if (sscanf(act, "move %d", &n) == 1 && n >= 1 && n <= NUM_WORKSPACES) { - b->type = TYPE_CWKSP; + b->type = TYPE_WS_CHANGE; b->action.ws = n - 1; } else if (sscanf(act, "swap %d", &n) == 1 && n >= 1 && n <= NUM_WORKSPACES) { - b->type = TYPE_MWKSP; + b->type = TYPE_WS_MOVE; b->action.ws = n - 1; } else { fprintf(stderr, "sxwmrc:%d: invalid workspace action '%s'\n", lineno, act); } } + else if (!strcmp(key, "scratchpad")) { + char *mid = strchr(rest, ':'); + if (!mid) { + fprintf(stderr, "sxwmrc:%d: scratchpad missing action\n", lineno); + continue; + } + *mid = '\0'; + char *combo = strip(rest); + char *act = strip(mid + 1); + + KeySym ks; + unsigned mods = parse_combo(combo, cfg, &ks); + if (ks == NoSymbol) { + fprintf(stderr, "sxwmrc:%d: bad key in '%s'\n", lineno, combo); + continue; + } + + Binding *b = alloc_bind(cfg, mods, ks); + if (!b) { + fputs("sxwm: too many binds\n", stderr); + goto cleanup_file; + } + + int padnum = -1; + + if (sscanf(act, "create %d", &padnum) == 1 && padnum >= 1 && padnum <= MAX_SCRATCHPADS) { + b->type = TYPE_SP_CREATE; + b->action.sp = padnum - 1; + } + else if (sscanf(act, "toggle %d", &padnum) == 1 && padnum >= 1 && padnum <= MAX_SCRATCHPADS) { + b->type = TYPE_SP_TOGGLE; + b->action.sp = padnum - 1; + } + else if (sscanf(act, "remove %d", &padnum) == 1 && padnum >= 1 && padnum <= MAX_SCRATCHPADS) { + b->type = TYPE_SP_REMOVE; + b->action.sp = padnum - 1; + } + else { + fprintf(stderr, "sxwmrc:%d: invalid scratchpad action '%s'\n", lineno, act); + } + } else if (!strcmp(key, "exec")) { if (torun >= 256) { fprintf(stderr, "sxwmrc:%d: too many exec commands\n", lineno); @@ -404,6 +447,81 @@ found: } torun++; } + else if (!strcmp(key, "can_swallow")) { + char *token = strtok(rest, ","); + int i = 0; + while (token && i < 256) { + char *item = strip_quotes(strip(token)); + if (*item) { + cfg->can_swallow[i] = malloc(2 * sizeof(char *)); + if (!cfg->can_swallow[i]) { + fprintf(stderr, "sxwmrc:%d: malloc failed\n", lineno); + break; + } + cfg->can_swallow[i][0] = strdup(item); + cfg->can_swallow[i][1] = NULL; + i++; + } + token = strtok(NULL, ","); + } + } + else if (!strcmp(key, "can_be_swallowed")) { + char *token = strtok(rest, ","); + int i = 0; + while (token && i < 256) { + char *item = strip_quotes(strip(token)); + if (*item) { + cfg->can_be_swallowed[i] = malloc(2 * sizeof(char *)); + if (!cfg->can_be_swallowed[i]) { + break; + } + cfg->can_be_swallowed[i][0] = strdup(item); + cfg->can_be_swallowed[i][1] = NULL; + i++; + } + token = strtok(NULL, ","); + } + } + else if (!strcmp(key, "new_win_master")) { + cfg->new_win_master = !strcmp(rest, "true") ? True : False; + } + else if (!strcmp(key, "open_in_workspace")) { + char *mid = strchr(rest, ':'); + if (!mid) { + fprintf(stderr, "sxwmrc:%d: open_in_workspace missing workspace number\n", lineno); + continue; + } + *mid = '\0'; + char *class_name = strip(rest); + char *ws_str = strip(mid + 1); + + class_name = strip_quotes(class_name); + + int ws = atoi(ws_str); + if (ws < 1 || ws > NUM_WORKSPACES) { + fprintf(stderr, "sxwmrc:%d: invalid workspace number %d\n", lineno, ws); + continue; + } + + /* find free slot in open_in_workspace */ + int slot = -1; + for (int i = 0; i < 256; i++) { + if (!cfg->open_in_workspace[i]) { + slot = i; + break; + } + } + + if (slot >= 0) { + cfg->open_in_workspace[slot] = malloc(2 * sizeof(char *)); + if (cfg->open_in_workspace[slot]) { + cfg->open_in_workspace[slot][0] = strdup(class_name); /* class name */ + char ws_buf[16]; + snprintf(ws_buf, sizeof(ws_buf), "%d", ws - 1); /* 0-indexed workspace */ + cfg->open_in_workspace[slot][1] = strdup(ws_buf); /* workspace number */ + } + } + } else { fprintf(stderr, "sxwmrc:%d: unknown option '%s'\n", lineno, key); } @@ -574,4 +692,4 @@ const char **build_argv(const char *cmd) free(tmp); return argv; #endif -}
\ No newline at end of file +} |
