fix lots of issues/bad code
This commit is contained in:
parent
b79f5c39c1
commit
eca13f2896
21
libs/arg.c
21
libs/arg.c
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 } },
|
||||
|
|
23
libs/draw.c
23
libs/draw.c
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -52,6 +52,7 @@ keypress(XEvent *e)
|
|||
allowkeys = !allowkeys;
|
||||
}
|
||||
|
||||
calcoffsets();
|
||||
drawmenu();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,8 +81,6 @@ fuzzymatch(void)
|
|||
calcoffsets();
|
||||
}
|
||||
}
|
||||
|
||||
calcoffsets();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
16
libs/mouse.c
16
libs/mouse.c
|
@ -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;
|
||||
|
|
1
mouse.h
1
mouse.h
|
@ -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} },
|
||||
};
|
||||
|
|
7
spmenu.c
7
spmenu.c
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue