summaryrefslogtreecommitdiff
path: root/dmenu.c
diff options
context:
space:
mode:
authortsxv478 <vt0451@yandex.ru>2022-09-21 02:22:44 +0300
committertsxv478 <vt0451@yandex.ru>2022-09-21 02:22:44 +0300
commit47769a59eb9efed2699d3c66ea847c3f52296a9b (patch)
treeb26b62aca38dcb0abc8c4abe86c38c63a0eb7adb /dmenu.c
parentf8a5d245468cc6e04903fe96e3efcbd85aea13d9 (diff)
scroll patch
Diffstat (limited to 'dmenu.c')
-rw-r--r--dmenu.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/dmenu.c b/dmenu.c
index fe12f1f..512a489 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -155,9 +155,10 @@ drawitem(struct item *item, int x, int y, int w)
static void
drawmenu(void)
{
- unsigned int curpos;
+ static int curpos, oldcurlen;
struct item *item;
int x = 0, y = 0, w;
+ int curlen, rcurlen;
drw_setscheme(drw, scheme[SchemeNorm]);
drw_rect(drw, 0, 0, mw, mh, 1, 1);
@@ -168,14 +169,21 @@ drawmenu(void)
}
/* draw input field */
w = (lines > 0 || !matches) ? mw - x : inputw;
- drw_setscheme(drw, scheme[SchemeNorm]);
- drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0);
+ w -= lrpad / 2;
+ x += lrpad / 2;
- curpos = TEXTW(text) - TEXTW(&text[cursor]);
- if ((curpos += lrpad / 2 - 1) < w) {
- drw_setscheme(drw, scheme[SchemeNorm]);
- drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
- }
+ rcurlen = drw_fontset_getwidth(drw, text + cursor);
+ curlen = drw_fontset_getwidth(drw, text) - rcurlen;
+ curpos += curlen - oldcurlen;
+ curpos = MIN(w, MAX(0, curpos));
+ curpos = MAX(curpos, w - rcurlen);
+ curpos = MIN(curpos, curlen);
+ oldcurlen = curlen;
+
+ drw_setscheme(drw, scheme[SchemeNorm]);
+ drw_text_align(drw, x, 0, curpos, bh, text, cursor, AlignR);
+ drw_text_align(drw, x + curpos, 0, w - curpos, bh, text + cursor, strlen(text) - cursor, AlignL);
+ drw_rect(drw, x + curpos - 1, 2, 2, bh - 4, 1, 0);
if (lines > 0) {
/* draw vertical list */