inputw: improve correctness and startup performance, by NRK
authorHiltjo Posthuma <hiltjo@codemadness.org>
Fri, 29 Apr 2022 18:15:48 +0000 (20:15 +0200)
committerHiltjo Posthuma <hiltjo@codemadness.org>
Fri, 29 Apr 2022 18:18:02 +0000 (20:18 +0200)
Always use ~30% of the monitor width for the input in horizontal mode.

Patch adapted from NRK patches.
This also does not calculate inputw when using vertical mode anymore (because
the code is removed).

dmenu.c

diff --git a/dmenu.c b/dmenu.c
index 839f6ccd935f2755afa81afc7549ea95bc7b93aa..4e286cf05c59c643b24a0316f354aa5ad45851ce 100644 (file)
--- a/dmenu.c
+++ b/dmenu.c
@@ -610,13 +610,12 @@ static void
 setup(void)
 {
        int x, y, i, j;
-       unsigned int du, tmp;
+       unsigned int du;
        XSetWindowAttributes swa;
        XIM xim;
        Window w, dw, *dws;
        XWindowAttributes wa;
        XClassHint ch = {"dmenu", "dmenu"};
-       struct item *item;
 #ifdef XINERAMA
        XineramaScreenInfo *info;
        Window pw;
@@ -674,12 +673,7 @@ setup(void)
                mw = wa.width;
        }
        promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
-       for (item = items; item && item->text; ++item) {
-               if ((tmp = textw_clamp(item->text, mw/3)) > inputw) {
-                       if ((inputw = tmp) == mw/3)
-                               break;
-               }
-       }
+       inputw = mw / 3; /* input width: ~30% of monitor width */
        match();
 
        /* create menu window */