diff --git a/libs/draw.c b/libs/draw.c index 98694e3..3817320 100644 --- a/libs/draw.c +++ b/libs/draw.c @@ -299,7 +299,7 @@ drawinput(int x, int y, int w) curpos = TEXTW(text) - TEXTW(&text[cursor]); } - if ((curpos += lrpad / 2 - 1) < w && !hidecaret && !hideprompt) { + if ((curpos += lrpad / 2 - 1) < w && !hidecaret && !hideprompt && cursorstate) { drw_setscheme(drw, scheme[SchemeCaret]); drw_rect(drw, x + curpos, 2 + (bh - fh) / 2 + y, 2, fh - 4, 1, 0); } @@ -445,7 +445,7 @@ drawmenu(void) calcoffsets(); // why have an empty line? - if ((hideprompt && hideinput && hidemode && hidematchcount + if ((hideprompt && hideinput && hidemode && hidematchcount && hidecaps #if USEIMAGE ) && (!image || hideimage)) { #else diff --git a/libs/event.c b/libs/event.c index 9bfa063..7e12320 100644 --- a/libs/event.c +++ b/libs/event.c @@ -21,11 +21,7 @@ eventloop(void) noimg = 0; #endif break; - case MotionNotify: - motionevent(&ev.xbutton); - #if USEIMAGE - noimg = 0; - #endif + case MotionNotify: // currently does nothing break; case Expose: if (ev.xexpose.count == 0) diff --git a/libs/img.c b/libs/img.c index 9fd1e9d..2fd6983 100644 --- a/libs/img.c +++ b/libs/img.c @@ -91,19 +91,20 @@ drawimage(void) rotateimage(); flipimage(); - int leftmargin = imagegaps; - int wtr = 0; - int wta = 0; - int xta = 0; + int leftmargin = imagegaps; // gaps between image and menu + int wtr = 0; // remove from w + int wta = 0; // add to w + int xta = 0; // add to x - if (hideprompt && hideinput && hidemode && hidematchcount) { + if (hideprompt && hideinput && hidemode && hidematchcount && hidecaps) { wtr = bh; } else { - wta = bh + menumarginv; + wta = bh; } // margin xta += menumarginh; + wta += menumarginv; if (mh != bh + height + imagegaps * 2 - wtr) { // menu height cannot be smaller than image height resizetoimageheight(height); diff --git a/libs/mouse.c b/libs/mouse.c index 6937f4f..3bfcc59 100644 --- a/libs/mouse.c +++ b/libs/mouse.c @@ -1,63 +1,3 @@ -unsigned int -textw_clamp(const char *str, unsigned int n) -{ - unsigned int w; - w = drw_fontset_getwidth_clamp(drw, str, n, True) + lrpad; - - return MIN(w, n); -} - -void -motionevent(XButtonEvent *ev) -{ - struct item *item; - int xy, ev_xy; - - if (ev->window != win || matches == 0) - return; - - #if USEIMAGE - if (image) return; - #endif - - int itemCount = 0; - - // walk through all items - for (item = items; item && item->text; item++) { - itemCount++; - } - - // to prevent slowdown, arbritary limit of 50 items - if (itemCount > 50) { - return; - } - - 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 - 2 * sp - 2 * borderwidth - numberWidth - modeWidth - capsWidth); - if (ev_xy >= xy && ev_xy < (xy + wh)) { - sel = item; - drawmenu(); - break; - } - xy += wh; - } -} - void buttonpress(XEvent *e) { @@ -86,26 +26,21 @@ buttonpress(XEvent *e) if (!hidemode) modeWidth = pango_mode ? TEXTWM(modetext) : TEXTW(modetext); if (!hidecaps) capsWidth = pango_caps ? TEXTWM(capstext) : TEXTW(capstext); - if (!strcmp(capstext, "")) - capsWidth = 0; + if (!strcmp(capstext, "")) capsWidth = 0; // no caps lock width for no chars + if (ev->window != win) return; // if incorrect or wrong window, return - // if incorrect or wrong window, return - if (ev->window != win) - return; + click = clickwindow; // clicking anywhere, we use this and override it if we clicked on something specific - // clicking anywhere, we use this as a base for a click - click = clickwindow; - - // check if we clicked on the prompt or the input - if (ev->x < x + promptw + powerlineprompt ? plw : 0) { + // check click position and override the value of click + if (ev->x < x + promptw + powerlineprompt ? plw : 0) { // prompt click = clickprompt; - } else if ((ev->x > mw - capsWidth - 2 * sp - 2 * borderwidth - menumarginh) && !hidecaps && capsWidth) { + } else if ((ev->x > mw - capsWidth - 2 * sp - 2 * borderwidth - menumarginh) && !hidecaps && capsWidth) { // caps lock indicator click = clickcaps; - } else if (ev->x > mw - modeWidth - capsWidth - 2 * sp - 2 * borderwidth - menumarginh) { + } else if (ev->x > mw - modeWidth - capsWidth - 2 * sp - 2 * borderwidth - menumarginh) { // mode indicator click = clickmode; - } else if (ev->x > mw - modeWidth - numberWidth - capsWidth - 2 * sp - 2 * borderwidth - menumarginh) { + } else if (ev->x > mw - modeWidth - numberWidth - capsWidth - 2 * sp - 2 * borderwidth - menumarginh) { // match count click = clicknumber; - } else { // actually we clicked on the input + } else { // input w = (lines > 0 || !matches) ? mw - x : inputw; if ((lines <= 0 && ev->x >= 0 && ev->x <= x + w + promptw + @@ -129,6 +64,7 @@ buttonpress(XEvent *e) y += h; + // clickselitem, called function doesn't matter if (ev->y >= y && ev->y <= (y + h) && ev->x >= x && ev->x <= (x + w / columns)) { for (i = 0; i < LENGTH(buttons); i++) { if (buttons[i].click == clickselitem && buttons[i].button == ev->button && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state)) { @@ -140,8 +76,8 @@ buttonpress(XEvent *e) } } } - } else if (matches) { - // left-click on left arrow + } else if (matches) { // a single line, meaning it could be arrows too, so we check that here + // left arrow x += inputw; w = larrowWidth; if (prev && curr->left) { @@ -166,7 +102,7 @@ buttonpress(XEvent *e) } } - // left-click on right arrow + // right arrow w = rarrowWidth; x = mw - w; if (next && ev->x >= x && ev->x <= x + w) { @@ -174,7 +110,7 @@ buttonpress(XEvent *e) } } - // go through mouse button array + // go through mouse button array and run function for (i = 0; i < LENGTH(buttons); i++) if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state)) diff --git a/libs/mouse.h b/libs/mouse.h index a2f811b..25894c3 100644 --- a/libs/mouse.h +++ b/libs/mouse.h @@ -20,6 +20,4 @@ enum { clickmode, }; -static unsigned int textw_clamp(const char *str, unsigned int n); -static void motionevent(XButtonEvent *ev); static void buttonpress(XEvent *e); diff --git a/spmenu.c b/spmenu.c index 597e899..5ec4f07 100644 --- a/spmenu.c +++ b/spmenu.c @@ -132,6 +132,7 @@ static int plw = 0; static int lrpad; // sum of left and right padding static int vp; // vertical padding for bar static int sp; // side padding for bar +static int cursorstate = 0; // cursor state static size_t cursor; static struct item *items = NULL, *backup_items; static struct item *matches, *matchend;