When the number of items is less than the number of lines on vertical
windows, it is more beautiful to have a reduced window height.
---
 dmenu.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/dmenu.c b/dmenu.c
index 65f25ce..86dbe16 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -132,6 +132,7 @@ drawmenu(void)
        unsigned int curpos;
        struct item *item;
        int x = 0, y = 0, w;
+       unsigned int item_count = 0;
 
        drw_setscheme(drw, scheme[SchemeNorm]);
        drw_rect(drw, 0, 0, mw, mh, 1, 1);
@@ -154,7 +155,15 @@ drawmenu(void)
        if (lines > 0) {
                /* draw vertical list */
                for (item = curr; item != next; item = item->right)
+               {
                        drawitem(item, x, y += bh, mw - x);
+                       item_count++;
+               }
+               if (item_count <= lines)
+               {
+                       mh = (item_count + 1) * bh;
+                       XResizeWindow(dpy, win, mw, mh);
+               }
        } else if (matches) {
                /* draw horizontal list */
                x += inputw;
-- 
2.29.2


Reply via email to