[hackers] [dmenu] Print highlighted input text only on single match || Quentin Rameau

From: <git_AT_suckless.org>
Date: Tue, 26 Jul 2016 22:52:16 +0200 (CEST)

commit a4053bc4e403ae57343f43b7e363a0911bba5a3a
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Tue Jul 26 12:48:23 2016 +0200
Commit: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
CommitDate: Tue Jul 26 18:29:42 2016 +0200

    Print highlighted input text only on single match
    
    When the input text fully matches a single item, do not draw the item
    and highlight the input text to show that it matches an item in
    opposition to regular input text not matching anything.

diff --git a/dmenu.c b/dmenu.c
index 8e84fbd..b191486 100644
--- a/dmenu.c
+++ b/dmenu.c
_AT_@ -130,7 +130,7 @@ drawmenu(void)
 {
         unsigned int curpos;
         struct item *item;
- int x = 0, y = 0, w;
+ int x = 0, y = 0, w, inputscheme;
 
         drw_setscheme(drw, scheme[SchemeNorm]);
         drw_rect(drw, 0, 0, mw, mh, 1, 1);
_AT_@ -138,18 +138,27 @@ drawmenu(void)
         if (prompt && *prompt) {
                 drw_setscheme(drw, scheme[SchemeSel]);
                 x = drw_text(drw, x, 0, promptw, bh, lrpad / 2, prompt, 0);
+ x += 2;
         }
         /* draw input field */
         w = (lines > 0 || !matches) ? mw - x : inputw;
- drw_setscheme(drw, scheme[SchemeNorm]);
+ if (matches && !strcmp(text, curr->text))
+ inputscheme = SchemeSel;
+ else
+ inputscheme = SchemeNorm;
+ drw_setscheme(drw, scheme[inputscheme]);
+
         drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0);
 
         drw_font_getexts(drw->fonts, text, cursor, &curpos, NULL);
         if ((curpos += lrpad / 2 - 1) < w) {
- drw_setscheme(drw, scheme[SchemeNorm]);
+ drw_setscheme(drw, scheme[inputscheme]);
                 drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
         }
 
+ if (inputscheme == SchemeSel)
+ goto drawmap;
+
         if (lines > 0) {
                 /* draw vertical list */
                 for (item = curr; item != next; item = item->right)
_AT_@ -171,6 +180,7 @@ drawmenu(void)
                         drw_text(drw, mw - w, 0, w, bh, lrpad / 2, ">", 0);
                 }
         }
+drawmap:
         drw_map(drw, win, 0, 0, mw, mh);
 }
 
Received on Tue Jul 26 2016 - 22:52:16 CEST

This archive was generated by hypermail 2.3.0 : Tue Jul 26 2016 - 23:00:15 CEST