From 2d4b2fb00f92756b0c1b12cba6bdb1a938435761 Mon Sep 17 00:00:00 2001 From: speedie Date: Sun, 26 Feb 2023 05:44:48 +0100 Subject: [PATCH] add some arguments for the mode feature --- docs/example.Xresources | 3 +++ libs/mode.c | 4 ++-- options.h | 5 +++++ spmenu.c | 28 ++++++++++++++++++++++++++-- xresources.h | 3 +++ 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/docs/example.Xresources b/docs/example.Xresources index d079188..68e11c8 100644 --- a/docs/example.Xresources +++ b/docs/example.Xresources @@ -64,3 +64,6 @@ spmenu.imagesize: 86 spmenu.imagegaps: 0 spmenu.imageposition: 0 spmenu.generatecache: 0 +spmenu.mode: 1 +spmenu.normtext: Normal +spmenu.instext: Insert diff --git a/libs/mode.c b/libs/mode.c index e4c5146..e631fed 100644 --- a/libs/mode.c +++ b/libs/mode.c @@ -5,9 +5,9 @@ switchmode(const Arg *arg) allowkeys = !selkeys; if (!selkeys) { - strcpy(modetext, "Normal"); + strcpy(modetext, normtext); } else { - strcpy(modetext, "Insert"); + strcpy(modetext, instext); } if (hidemode) strcpy(modetext, ""); diff --git a/options.h b/options.h index d94073a..453ebfb 100644 --- a/options.h +++ b/options.h @@ -21,6 +21,11 @@ static int imagegaps = 0; /* Image gaps */ static int imageposition = 0; /* Image position (0: Top, 1: Bottom, 2: Center, 3: Top center) */ static int generatecache = 0; /* Generate image cache by default */ +/* Mode options */ +static int mode = 1; /* Mode to start speedwm in (0: Normal mode, 1: Insert mode) */ +static char normtext[] = "Normal"; /* Text to display for normal mode */ +static char instext[] = "Insert"; /* Text to display for insert mode */ + /* Color support */ static int colorsupport = 1; /* Support 256 colors? Otherwise the default 16 colors will be used. */ diff --git a/spmenu.c b/spmenu.c index 364c411..2922fb3 100644 --- a/spmenu.c +++ b/spmenu.c @@ -1761,9 +1761,13 @@ usage(void) "spmenu -y Offset spmenu y position by \n" "spmenu -n Preselect in the list of items\n" "spmenu -z Width of the spmenu window\n" + "spmenu -nmt Set normal mode text to \n" + "spmenu -imt Set insert mode text to \n" "spmenu -bw Width of the border. 0 will disable the border\n" "spmenu -s Use case-sensitive matching\n" "spmenu -i Use case-insensitive matching\n" + "spmenu -nm Start spmenu in normal mode\n" + "spmenu -im Start spmenu in insert mode\n" "spmenu -t Position spmenu at the top of the screen\n" "spmenu -b Position spmenu at the bottom of the screen\n" "spmenu -c Position spmenu at the center of the screen\n" @@ -1785,7 +1789,7 @@ usage(void) "spmenu -it Position the image at the top\n" "spmenu -ib Position the image at the bottom\n" "spmenu -ic Position the image in the center\n" - "spmenu -itc Position the image in the top center\n" + "spmenu -itc Position the image in the top center\n" "spmenu -wm Spawn spmenu as a window manager controlled client/window. Useful for testing\n" "spmenu -v Print spmenu version to stdout\n" "\n", stdout); @@ -1886,6 +1890,10 @@ main(int argc, char *argv[]) menuposition = 0; } else if (!strcmp(argv[i], "-t")) { /* appears at the top of the screen */ menuposition = 1; + } else if (!strcmp(argv[i], "-nm")) { /* normal mode */ + mode = 0; + } else if (!strcmp(argv[i], "-im")) { /* insert mode */ + mode = 1; } else if (!strcmp(argv[i], "-c")) { /* appears at the center of the screen */ centered = 1; } else if (!strcmp(argv[i], "-f")) { /* grabs keyboard before reading stdin */ @@ -1969,8 +1977,12 @@ main(int argc, char *argv[]) dmw = atoi(argv[++i]); else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */ prompt = argv[++i]; - else if (!strcmp(argv[i], "-fn")) { /* font or font set */ + else if (!strcmp(argv[i], "-fn")) /* font or font set */ strcpy(font, argv[++i]); /* font[0] = argv[++i]; */ + else if (!strcmp(argv[i], "-nmt")) /* normal mode text */ + strcpy(normtext, argv[++i]); + else if (!strcmp(argv[i], "-imt")) { /* insert mode text */ + strcpy(instext, argv[++i]); /* dmenu compatibility options */ } else if (!strcmp(argv[i], "-nb")) { /* normal background color */ @@ -2071,6 +2083,18 @@ main(int argc, char *argv[]) else usage(); + if (mode) { + selkeys = 1; + allowkeys = !selkeys; + + strcpy(modetext, instext); + } else { + selkeys = 0; + allowkeys = !selkeys; + + strcpy(modetext, normtext); + } + if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) fputs("warning: no locale support\n", stderr); if (!(dpy = XOpenDisplay(NULL))) diff --git a/xresources.h b/xresources.h index 2a0988d..df07aae 100644 --- a/xresources.h +++ b/xresources.h @@ -102,6 +102,8 @@ ResourcePref resources[] = { { "class", STRING, &class }, { "leftarrow", STRING, &leftarrow }, { "rightarrow", STRING, &rightarrow }, + { "normtext", STRING, &normtext }, + { "instext", STRING, &instext }, { "bordercentered", INTEGER, &bordercentered }, { "borderwidth", INTEGER, &borderwidth }, { "lines", INTEGER, &lines }, @@ -117,4 +119,5 @@ ResourcePref resources[] = { { "imagegaps", INTEGER, &imagegaps }, { "imageposition", INTEGER, &imageposition }, { "generatecache", INTEGER, &generatecache }, + { "mode", INTEGER, &mode }, };