From d163a7262bbad60f0fd34405706fc1fdc8f89620 Mon Sep 17 00:00:00 2001 From: speedie Date: Thu, 16 Mar 2023 17:22:14 +0100 Subject: [PATCH] remove centered in favor of menuposition == 2 --- libs/argv.c | 14 +++++++++----- libs/draw.c | 2 +- options.h | 3 +-- spmenu.c | 19 ++++++++++--------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/libs/argv.c b/libs/argv.c index 6370090..1007743 100644 --- a/libs/argv.c +++ b/libs/argv.c @@ -4,6 +4,9 @@ readargs(int argc, char *argv[]) int i = 0; int j = 0; + int cxrdb = 0; + int hxrdb = 0; + // check if we should load the xrdb/config, because it needs to be loaded before arguments are checked (internal -> xresources -> arguments) for (j = 1; j < argc; j++) { if (!strcmp(argv[j], "-xrdb")) { @@ -22,11 +25,12 @@ readargs(int argc, char *argv[]) XrmInitialize(); if (loadconfig) { - int cxrdb = system("[ -e $HOME/.config/spmenu/spmenurc ] && xrdb -override $HOME/.config/spmenu/spmenurc"); - int hxrdb = system("[ -e $HOME/.spmenurc ] && xrdb -override $HOME/.spmenurc"); + cxrdb = system("[ -e $HOME/.config/spmenu/spmenurc ] && xrdb -override $HOME/.config/spmenu/spmenurc"); + hxrdb = system("[ -e $HOME/.spmenurc ] && xrdb -override $HOME/.spmenurc"); } - load_xresources(); + // avoid an annoying warning gcc will spit out when you don't care about the result + if (!cxrdb || !hxrdb || cxrdb || hxrdb || xresources) load_xresources(); } // no arguments @@ -48,12 +52,12 @@ readargs(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], "-c")) { // appears at the center of the screen + menuposition = 2; } 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 fast = 1; } else if (!strcmp(argv[i], "-rw")) { // relative width diff --git a/libs/draw.c b/libs/draw.c index a8640ee..ca53151 100644 --- a/libs/draw.c +++ b/libs/draw.c @@ -14,7 +14,7 @@ drawhighlights(struct item *item, int x, int y, int w) ? SchemeSelHighlight : SchemeNormHighlight]); for (i = 0, highlight = itemtext; *highlight && text[i];) { - if ((fuzzy && !fstrncmp(&(*highlight), &text[i], 1) || (!fuzzy && *highlight == text[i]))) { + if (((fuzzy && !fstrncmp(&(*highlight), &text[i], 1)) || (!fuzzy && *highlight == text[i]))) { c = *highlight; *highlight = '\0'; indent = TEXTW(itemtext) - lrpad; diff --git a/options.h b/options.h index 3ce7000..4919b02 100644 --- a/options.h +++ b/options.h @@ -12,11 +12,10 @@ static int mon = -1; /* Monitor to run spmenu on */ /* Window options */ static int alpha = 1; /* Enable alpha */ -static int menuposition = 1; /* Position of the menu */ +static int menuposition = 1; /* Position of the menu (0: Bottom, 1: Top, 2: Center */ static int menupaddingv = 0; /* Vertical padding of bar (in pixels) */ static int menupaddingh = 0; /* Horizontal padding of bar (in pixels) */ static int minwidth = 500; /* Minimum width */ -static int centered = 0; /* Whether or not to center spmenu by default */ static int managed = 0; /* Let your window manager manage spmenu? */ /* Image options */ diff --git a/spmenu.c b/spmenu.c index d84f786..448e15a 100644 --- a/spmenu.c +++ b/spmenu.c @@ -638,8 +638,8 @@ readstdin(void) // spmenu:test if (!strncmp("test", items[i].ex, strlen("test"))) { - system("command -v spmenu_test > /dev/null && spmenu_test"); - exit(0); + int i = system("command -v spmenu_test > /dev/null && spmenu_test"); + if (i||!i) exit(0); } } } @@ -698,7 +698,8 @@ setup(void) #endif mh = (lines + 1) * bh; // lines + 1 * bh is the menu height - promptw = (prompt && *prompt) ? TEXTWM(prompt) - lrpad / 4 : 0; // prompt width + + if (menuposition == 2) promptw = (prompt && *prompt) ? TEXTWM(prompt) - lrpad / 4 : 0; // prompt width // get accurate width if (accuratewidth) { @@ -744,10 +745,10 @@ setup(void) break; // calculate x/y position - if (centered) { + if (menuposition == 2) { + mw = MIN(MAX(max_textw() + promptw, minwidth), info[i].width); x = info[i].x_org + ((info[i].width - mw) / 2); y = info[i].y_org + ((info[i].height - mh) / 2); - mw = MIN(MAX(max_textw() + promptw, minwidth), info[i].width); } else { x = info[i].x_org + dmx; y = info[i].y_org + (menuposition ? 0 : info[i].height - mh - dmy); @@ -762,7 +763,7 @@ setup(void) die("could not get embedding window attributes: 0x%lx", parentwin); - if (centered) { + if (menuposition == 2) { mw = MIN(MAX(max_textw() + promptw, minwidth), wa.width); x = (wa.width - mw) / 2; y = (wa.height - mh) / 2; @@ -773,13 +774,13 @@ setup(void) } } - /* might be faster in some instances, most of the time unnecessary */ + // might be faster in some instances, most of the time unnecessary if (!accuratewidth) inputw = MIN(inputw, mw/3); match(); - /* create menu window */ - create_window(x + sp, y + vp - (menuposition ? 0 : borderwidth * 2), mw - 2 * sp - borderwidth * 2, mh); + // create menu window + create_window(x + sp, y + vp - (menuposition == 2 ? 0 : borderwidth * 2), mw - 2 * sp - borderwidth * 2, mh); set_window(); set_prop();