remove the item hovering, it's just not necessary and causes a lot of

slowness

if you find a way to speed this up significantly, please let me know
This commit is contained in:
speedie 2023-04-21 17:59:10 +02:00
parent c0611034aa
commit 52f88f6a73
6 changed files with 25 additions and 93 deletions

View file

@ -299,7 +299,7 @@ drawinput(int x, int y, int w)
curpos = TEXTW(text) - TEXTW(&text[cursor]); 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_setscheme(drw, scheme[SchemeCaret]);
drw_rect(drw, x + curpos, 2 + (bh - fh) / 2 + y, 2, fh - 4, 1, 0); drw_rect(drw, x + curpos, 2 + (bh - fh) / 2 + y, 2, fh - 4, 1, 0);
} }
@ -445,7 +445,7 @@ drawmenu(void)
calcoffsets(); calcoffsets();
// why have an empty line? // why have an empty line?
if ((hideprompt && hideinput && hidemode && hidematchcount if ((hideprompt && hideinput && hidemode && hidematchcount && hidecaps
#if USEIMAGE #if USEIMAGE
) && (!image || hideimage)) { ) && (!image || hideimage)) {
#else #else

View file

@ -21,11 +21,7 @@ eventloop(void)
noimg = 0; noimg = 0;
#endif #endif
break; break;
case MotionNotify: case MotionNotify: // currently does nothing
motionevent(&ev.xbutton);
#if USEIMAGE
noimg = 0;
#endif
break; break;
case Expose: case Expose:
if (ev.xexpose.count == 0) if (ev.xexpose.count == 0)

View file

@ -91,19 +91,20 @@ drawimage(void)
rotateimage(); rotateimage();
flipimage(); flipimage();
int leftmargin = imagegaps; int leftmargin = imagegaps; // gaps between image and menu
int wtr = 0; int wtr = 0; // remove from w
int wta = 0; int wta = 0; // add to w
int xta = 0; int xta = 0; // add to x
if (hideprompt && hideinput && hidemode && hidematchcount) { if (hideprompt && hideinput && hidemode && hidematchcount && hidecaps) {
wtr = bh; wtr = bh;
} else { } else {
wta = bh + menumarginv; wta = bh;
} }
// margin // margin
xta += menumarginh; xta += menumarginh;
wta += menumarginv;
if (mh != bh + height + imagegaps * 2 - wtr) { // menu height cannot be smaller than image height if (mh != bh + height + imagegaps * 2 - wtr) { // menu height cannot be smaller than image height
resizetoimageheight(height); resizetoimageheight(height);

View file

@ -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 void
buttonpress(XEvent *e) buttonpress(XEvent *e)
{ {
@ -86,26 +26,21 @@ buttonpress(XEvent *e)
if (!hidemode) modeWidth = pango_mode ? TEXTWM(modetext) : TEXTW(modetext); if (!hidemode) modeWidth = pango_mode ? TEXTWM(modetext) : TEXTW(modetext);
if (!hidecaps) capsWidth = pango_caps ? TEXTWM(capstext) : TEXTW(capstext); if (!hidecaps) capsWidth = pango_caps ? TEXTWM(capstext) : TEXTW(capstext);
if (!strcmp(capstext, "")) if (!strcmp(capstext, "")) capsWidth = 0; // no caps lock width for no chars
capsWidth = 0; if (ev->window != win) return; // if incorrect or wrong window, return
// if incorrect or wrong window, return click = clickwindow; // clicking anywhere, we use this and override it if we clicked on something specific
if (ev->window != win)
return;
// clicking anywhere, we use this as a base for a click // check click position and override the value of click
click = clickwindow; if (ev->x < x + promptw + powerlineprompt ? plw : 0) { // prompt
// check if we clicked on the prompt or the input
if (ev->x < x + promptw + powerlineprompt ? plw : 0) {
click = clickprompt; 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; 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; 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; click = clicknumber;
} else { // actually we clicked on the input } else { // input
w = (lines > 0 || !matches) ? mw - x : inputw; w = (lines > 0 || !matches) ? mw - x : inputw;
if ((lines <= 0 && ev->x >= 0 && ev->x <= x + w + promptw + if ((lines <= 0 && ev->x >= 0 && ev->x <= x + w + promptw +
@ -129,6 +64,7 @@ buttonpress(XEvent *e)
y += h; y += h;
// clickselitem, called function doesn't matter
if (ev->y >= y && ev->y <= (y + h) && ev->x >= x && ev->x <= (x + w / columns)) { if (ev->y >= y && ev->y <= (y + h) && ev->x >= x && ev->x <= (x + w / columns)) {
for (i = 0; i < LENGTH(buttons); i++) { for (i = 0; i < LENGTH(buttons); i++) {
if (buttons[i].click == clickselitem && buttons[i].button == ev->button && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state)) { 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) { } else if (matches) { // a single line, meaning it could be arrows too, so we check that here
// left-click on left arrow // left arrow
x += inputw; x += inputw;
w = larrowWidth; w = larrowWidth;
if (prev && curr->left) { if (prev && curr->left) {
@ -166,7 +102,7 @@ buttonpress(XEvent *e)
} }
} }
// left-click on right arrow // right arrow
w = rarrowWidth; w = rarrowWidth;
x = mw - w; x = mw - w;
if (next && ev->x >= x && ev->x <= x + 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++) for (i = 0; i < LENGTH(buttons); i++)
if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
&& CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state)) && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))

View file

@ -20,6 +20,4 @@ enum {
clickmode, clickmode,
}; };
static unsigned int textw_clamp(const char *str, unsigned int n);
static void motionevent(XButtonEvent *ev);
static void buttonpress(XEvent *e); static void buttonpress(XEvent *e);

View file

@ -132,6 +132,7 @@ static int plw = 0;
static int lrpad; // sum of left and right padding static int lrpad; // sum of left and right padding
static int vp; // vertical padding for bar static int vp; // vertical padding for bar
static int sp; // side padding for bar static int sp; // side padding for bar
static int cursorstate = 0; // cursor state
static size_t cursor; static size_t cursor;
static struct item *items = NULL, *backup_items; static struct item *items = NULL, *backup_items;
static struct item *matches, *matchend; static struct item *matches, *matchend;