fix lots of issues/bad code

This commit is contained in:
speedie 2023-04-21 09:49:38 +02:00
parent b79f5c39c1
commit eca13f2896
11 changed files with 66 additions and 20 deletions

View file

@ -337,6 +337,7 @@ clearins(const Arg *arg)
if (hidemode) strcpy(modetext, "");
calcoffsets();
drawmenu();
}
@ -511,3 +512,23 @@ setprofile(const Arg *arg)
// this just runs an external shell script to set the profile
exit(system("command -v spmenu_profile > /dev/null && spmenu_profile --spmenu-set-profile > /dev/null"));
}
void
spawn(const Arg *arg)
{
struct sigaction sa;
if (fork() == 0) {
if (dpy)
close(ConnectionNumber(dpy));
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sa.sa_handler = SIG_DFL;
sigaction(SIGCHLD, &sa, NULL);
setsid();
execvp(((char **)arg->v)[1], ((char **)arg->v)+1);
fprintf(stderr, "spmenu: failed to execute command '%s'", ((char **)arg->v)[0]);
}
}

View file

@ -38,3 +38,4 @@ static void setimggaps(const Arg *arg);
static void setlines(const Arg *arg);
static void setcolumns(const Arg *arg);
static void setprofile(const Arg *arg);
static void spawn(const Arg *arg);

View file

@ -144,6 +144,6 @@ resizeclient(void)
// no window/invalid window or menu height we had before is the same as the current window height
if (!win || omh == mh) return;
XMoveResizeWindow(dpy, win, x, y, mw - 2 * sp - 2 * borderwidth, mh);
XMoveResizeWindow(dpy, win, x, y, mw - 2 * sp - borderwidth, mh);
drw_resize(drw, mw - 2 * sp - borderwidth * 2, mh);
}

View file

@ -21,3 +21,7 @@
#define ALTR Mod3Mask
#define SUPER Mod4Mask
#define SUPERR Mod5Mask
// for running stuff
#define shell "/bin/sh"
#define cmd( cmd ) {.v = (const char*[]){ shell, "-c", cmd, NULL } },

View file

@ -191,12 +191,8 @@ drawitem(int x, int y, int w)
if (!hidematchcount) numberWidth = pango_numbers ? TEXTWM(numbers) : TEXTW(numbers);
if (!hidecaps) capsWidth = pango_caps ? TEXTWM(capstext) : TEXTW(capstext);
// mode indicator is always going to be at the right
if (hidemode) {
numberWidth += 2 * sp + borderwidth;
} else {
modeWidth += 2 * sp + borderwidth;
}
if (!strcmp(capstext, ""))
capsWidth = 0;
#if USEIMAGE
int ox = 0; // original x position
@ -237,9 +233,18 @@ drawitem(int x, int y, int w)
x = drawlarrow(x, y, w);
for (item = curr; item != next; item = item->right) // draw items
x = drawitemtext(item, x, y, MIN(pango_item ? TEXTWM(item->text) : TEXTW(item->text), mw - x - rarrowWidth - numberWidth - modeWidth - capsWidth - menumarginh));
x = drawitemtext(item, x, y, MIN(pango_item ? TEXTWM(item->text) : TEXTW(item->text),
mw - x -
rarrowWidth -
numberWidth -
modeWidth -
capsWidth -
menumarginh -
2 * sp -
2 * borderwidth
));
w = rarrowWidth + numberWidth + modeWidth + menumarginh;
w = rarrowWidth + numberWidth + modeWidth + capsWidth + menumarginh + 2 * sp + 2 * borderwidth;
x = drawrarrow(mw - w, y, w);
}
@ -437,6 +442,8 @@ drawmenu(void)
x += menumarginh;
y += menumarginv;
calcoffsets();
// why have an empty line?
if ((hideprompt && hideinput && hidemode && hidematchcount
#if USEIMAGE

View file

@ -25,6 +25,7 @@ setimagesize(int width, int height)
return;
}
calcoffsets();
drawmenu();
}
@ -429,9 +430,9 @@ resizetoimageheight(int imageheight)
return;
}
//XResizeWindow(dpy, win, mw - 2 * sp - 2 * borderwidth, mh);
XMoveResizeWindow(dpy, win, x, y, mw - 2 * sp - 2 * borderwidth, mh);
drw_resize(drw, mw - 2 * sp - 2 * borderwidth, mh);
//XResizeWindow(dpy, win, mw - 2 * sp - borderwidth, mh);
XMoveResizeWindow(dpy, win, x, y, mw - 2 * sp - borderwidth, mh);
drw_resize(drw, mw - 2 * sp - borderwidth, mh);
if (olines != lines) {
struct item *item;
@ -444,6 +445,7 @@ resizetoimageheight(int imageheight)
jumptoindex(i);
}
calcoffsets();
drawmenu();
}
#endif

View file

@ -52,6 +52,7 @@ keypress(XEvent *e)
allowkeys = !allowkeys;
}
calcoffsets();
drawmenu();
}
}

View file

@ -81,8 +81,6 @@ fuzzymatch(void)
calcoffsets();
}
}
calcoffsets();
}
void

View file

@ -34,18 +34,23 @@ motionevent(XButtonEvent *ev)
int larrowWidth = 0;
int rarrowWidth = 0;
int numberWidth = 0;
int modeWidth = 0;
int capsWidth = 0;
if (!hidelarrow) larrowWidth = pango_leftarrow ? TEXTWM(leftarrow) : TEXTW(leftarrow);
if (!hiderarrow) rarrowWidth = pango_rightarrow ? TEXTWM(rightarrow) : TEXTW(rightarrow);
if (!hidematchcount) numberWidth = pango_numbers ? TEXTWM(numbers) : TEXTW(numbers);
if (!hidemode) modeWidth = pango_mode ? TEXTWM(modetext) : TEXTW(modetext);
if (!hidecaps) capsWidth = pango_caps ? TEXTWM(capstext) : TEXTW(capstext);
xy = lines > 0 ? bh : inputw + promptw + larrowWidth;
xy += menumarginv;
ev_xy = lines > 0 ? ev->y : ev->x;
for (item = curr; item && item != next; item = item->right) {
int wh = lines > 0 ? bh : textw_clamp(item->text, mw - xy - rarrowWidth - menumarginh);
int wh = lines > 0 ? bh : textw_clamp(item->text, mw - xy - rarrowWidth - menumarginh - 2 * sp - 2 * borderwidth - numberWidth - modeWidth - capsWidth);
if (ev_xy >= xy && ev_xy < (xy + wh)) {
sel = item;
calcoffsets();
drawmenu();
break;
}
@ -66,6 +71,7 @@ buttonpress(XEvent *e)
x = xpad = plw;
}
// margin
x += menumarginh;
int larrowWidth = 0;
@ -93,11 +99,11 @@ buttonpress(XEvent *e)
// check if we clicked on the prompt or the input
if (ev->x < x + promptw + powerlineprompt ? plw : 0) {
click = clickprompt;
} else if ((ev->x > mw - capsWidth - 2 * sp - 2 * borderwidth) && !hidecaps) {
} else if ((ev->x > mw - capsWidth - 2 * sp - 2 * borderwidth - menumarginh) && !hidecaps && capsWidth) {
click = clickcaps;
} else if (ev->x > mw - modeWidth - capsWidth - 2 * sp - 2 * borderwidth) {
} else if (ev->x > mw - modeWidth - capsWidth - 2 * sp - 2 * borderwidth - menumarginh) {
click = clickmode;
} else if (ev->x > mw - modeWidth - numberWidth - capsWidth - 2 * sp - 2 * borderwidth) {
} else if (ev->x > mw - modeWidth - numberWidth - capsWidth - 2 * sp - 2 * borderwidth - menumarginh) {
click = clicknumber;
} else { // actually we clicked on the input
w = (lines > 0 || !matches) ? mw - x : inputw;

View file

@ -28,5 +28,6 @@ static Mouse buttons[] = {
{ clickprompt, 0, Button1, clear, {0} },
{ clickmode, 0, Button1, switchmode, {0} },
{ clicknumber, 0, Button1, viewhist, {0} },
{ clickcaps, 0, Button1, spawn, cmd("notify-send cuck") },
{ clickselitem, 0, Button1, NULL, {0} },
};

View file

@ -293,13 +293,18 @@ calcoffsets(void)
int modeWidth = 0;
int larrowWidth = 0;
int rarrowWidth = 0;
int capsWidth = 0;
if (!hidematchcount) numberWidth = pango_numbers ? TEXTWM(numbers) : TEXTW(numbers);
if (!hidemode) modeWidth = pango_mode ? TEXTWM(modetext) : TEXTW(modetext);
if (!hidelarrow) larrowWidth = pango_leftarrow ? TEXTWM(leftarrow) : TEXTW(leftarrow);
if (!hiderarrow) rarrowWidth = pango_rightarrow ? TEXTWM(rightarrow) : TEXTW(rightarrow);
if (!hidecaps) capsWidth = pango_caps ? TEXTWM(capstext) : TEXTW(capstext);
n = mw - (promptw + inputw + larrowWidth + rarrowWidth + modeWidth + numberWidth);
if (!strcmp(capstext, ""))
capsWidth = 0;
n = mw - (promptw + inputw + larrowWidth + rarrowWidth + modeWidth + numberWidth + capsWidth + 2 * borderwidth);
}
// calculate which items will begin the next page