sites

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit a12a226e9286319f819f657dbe0a8cd04cd353a0
parent 2c7c5d85c957b4955b858c6fb55800d91d555187
Author: nzl <uruabi@gmail.com>
Date:   Sat, 24 Feb 2018 14:02:35 +0800

[dmenu] scroll patch: curpos adjustment fix

Diffstat:
Mtools.suckless.org/dmenu/patches/dmenu-scroll-20180224-8895128.diff | 36++++++++++++++++++++----------------
1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/tools.suckless.org/dmenu/patches/dmenu-scroll-20180224-8895128.diff b/tools.suckless.org/dmenu/patches/dmenu-scroll-20180224-8895128.diff @@ -1,19 +1,19 @@ -From f424638a4a81ae24ec68eed2f1376b19354cac55 Mon Sep 17 00:00:00 2001 +From 32ae6bfb5f3a840443c52c9a53c27b126c3b59d0 Mon Sep 17 00:00:00 2001 From: nzl <uruabi@gmail.com> -Date: Sat, 24 Feb 2018 00:31:00 +0800 +Date: Sat, 24 Feb 2018 13:47:59 +0800 Subject: [PATCH] Implement text scrolling a new function drw_text_align is added, it is different from drw_text in that it doesn't append '...' for long text, and it allows drawing text right justified. --- - dmenu.c | 24 ++++++--- + dmenu.c | 28 ++++++++--- drw.c | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ drw.h | 2 + - 3 files changed, 188 insertions(+), 7 deletions(-) + 3 files changed, 191 insertions(+), 8 deletions(-) diff --git a/dmenu.c b/dmenu.c -index a246111..bc5e732 100644 +index a246111..d51b404 100644 --- a/dmenu.c +++ b/dmenu.c @@ -128,9 +128,11 @@ drawitem(struct item *item, int x, int y, int w) @@ -24,32 +24,36 @@ index a246111..bc5e732 100644 + static int curpos, oldcurlen; struct item *item; int x = 0, y = 0, w; -+ int curlen; ++ int curlen, rcurlen; + char ch; drw_setscheme(drw, scheme[SchemeNorm]); drw_rect(drw, 0, 0, mw, mh, 1, 1); -@@ -142,13 +144,21 @@ drawmenu(void) +@@ -141,14 +143,24 @@ drawmenu(void) + } /* draw input field */ w = (lines > 0 || !matches) ? mw - x : inputw; - drw_setscheme(drw, scheme[SchemeNorm]); +- drw_setscheme(drw, scheme[SchemeNorm]); - drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0); + w -= lrpad / 2; + x += lrpad / 2; - -- drw_font_getexts(drw->fonts, text, cursor, &curpos, NULL); -- if ((curpos += lrpad / 2 - 1) < w) { -- drw_setscheme(drw, scheme[SchemeNorm]); -- drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0); -- } ++ + ch = text[cursor]; + text[cursor] = '\0'; + curlen = drw_fontset_getwidth(drw, text); + text[cursor] = ch; ++ rcurlen = drw_fontset_getwidth(drw, text + cursor); + curpos += curlen - oldcurlen; -+ curpos = curpos - 1 >= w ? w : (curpos < 0 ? 0 : curpos); ++ curpos = MIN(w, MAX(0, curpos)); ++ curpos = MAX(curpos, w - rcurlen); ++ curpos = MIN(curpos, curlen); + oldcurlen = curlen; -+ + +- drw_font_getexts(drw->fonts, text, cursor, &curpos, NULL); +- if ((curpos += lrpad / 2 - 1) < w) { +- drw_setscheme(drw, scheme[SchemeNorm]); +- drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0); +- } + 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);