remove centered in favor of menuposition == 2

This commit is contained in:
speedie 2023-03-16 17:22:14 +01:00
parent 1153d416ab
commit d163a7262b
4 changed files with 21 additions and 17 deletions

View file

@ -4,6 +4,9 @@ readargs(int argc, char *argv[])
int i = 0; int i = 0;
int j = 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) // 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++) { for (j = 1; j < argc; j++) {
if (!strcmp(argv[j], "-xrdb")) { if (!strcmp(argv[j], "-xrdb")) {
@ -22,11 +25,12 @@ readargs(int argc, char *argv[])
XrmInitialize(); XrmInitialize();
if (loadconfig) { if (loadconfig) {
int cxrdb = system("[ -e $HOME/.config/spmenu/spmenurc ] && xrdb -override $HOME/.config/spmenu/spmenurc"); cxrdb = system("[ -e $HOME/.config/spmenu/spmenurc ] && xrdb -override $HOME/.config/spmenu/spmenurc");
int hxrdb = system("[ -e $HOME/.spmenurc ] && xrdb -override $HOME/.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 // no arguments
@ -48,12 +52,12 @@ readargs(int argc, char *argv[])
menuposition = 0; menuposition = 0;
} else if (!strcmp(argv[i], "-t")) { // appears at the top of the screen } else if (!strcmp(argv[i], "-t")) { // appears at the top of the screen
menuposition = 1; 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 } else if (!strcmp(argv[i], "-nm")) { // normal mode
mode = 0; mode = 0;
} else if (!strcmp(argv[i], "-im")) { // insert mode } else if (!strcmp(argv[i], "-im")) { // insert mode
mode = 1; 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 } else if (!strcmp(argv[i], "-f")) { // grabs keyboard before reading stdin
fast = 1; fast = 1;
} else if (!strcmp(argv[i], "-rw")) { // relative width } else if (!strcmp(argv[i], "-rw")) { // relative width

View file

@ -14,7 +14,7 @@ drawhighlights(struct item *item, int x, int y, int w)
? SchemeSelHighlight ? SchemeSelHighlight
: SchemeNormHighlight]); : SchemeNormHighlight]);
for (i = 0, highlight = itemtext; *highlight && text[i];) { 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; c = *highlight;
*highlight = '\0'; *highlight = '\0';
indent = TEXTW(itemtext) - lrpad; indent = TEXTW(itemtext) - lrpad;

View file

@ -12,11 +12,10 @@ static int mon = -1; /* Monitor to run spmenu on */
/* Window options */ /* Window options */
static int alpha = 1; /* Enable alpha */ 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 menupaddingv = 0; /* Vertical padding of bar (in pixels) */
static int menupaddingh = 0; /* Horizontal padding of bar (in pixels) */ static int menupaddingh = 0; /* Horizontal padding of bar (in pixels) */
static int minwidth = 500; /* Minimum width */ 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? */ static int managed = 0; /* Let your window manager manage spmenu? */
/* Image options */ /* Image options */

View file

@ -638,8 +638,8 @@ readstdin(void)
// spmenu:test // spmenu:test
if (!strncmp("test", items[i].ex, strlen("test"))) { if (!strncmp("test", items[i].ex, strlen("test"))) {
system("command -v spmenu_test > /dev/null && spmenu_test"); int i = system("command -v spmenu_test > /dev/null && spmenu_test");
exit(0); if (i||!i) exit(0);
} }
} }
} }
@ -698,7 +698,8 @@ setup(void)
#endif #endif
mh = (lines + 1) * bh; // lines + 1 * bh is the menu height 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 // get accurate width
if (accuratewidth) { if (accuratewidth) {
@ -744,10 +745,10 @@ setup(void)
break; break;
// calculate x/y position // 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); x = info[i].x_org + ((info[i].width - mw) / 2);
y = info[i].y_org + ((info[i].height - mh) / 2); y = info[i].y_org + ((info[i].height - mh) / 2);
mw = MIN(MAX(max_textw() + promptw, minwidth), info[i].width);
} else { } else {
x = info[i].x_org + dmx; x = info[i].x_org + dmx;
y = info[i].y_org + (menuposition ? 0 : info[i].height - mh - dmy); 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", die("could not get embedding window attributes: 0x%lx",
parentwin); parentwin);
if (centered) { if (menuposition == 2) {
mw = MIN(MAX(max_textw() + promptw, minwidth), wa.width); mw = MIN(MAX(max_textw() + promptw, minwidth), wa.width);
x = (wa.width - mw) / 2; x = (wa.width - mw) / 2;
y = (wa.height - mh) / 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); if (!accuratewidth) inputw = MIN(inputw, mw/3);
match(); match();
/* create menu window */ // create menu window
create_window(x + sp, y + vp - (menuposition ? 0 : borderwidth * 2), mw - 2 * sp - borderwidth * 2, mh); create_window(x + sp, y + vp - (menuposition == 2 ? 0 : borderwidth * 2), mw - 2 * sp - borderwidth * 2, mh);
set_window(); set_window();
set_prop(); set_prop();