From 48e3db316bc5809ce2a46fc5a1c2c41791b812d4 Mon Sep 17 00:00:00 2001 From: speedie Date: Fri, 14 Jul 2023 01:16:35 +0200 Subject: [PATCH] Make sure number of lines/menu height cannot exceed monitor height --- libs/x11/init.c | 2 ++ spmenu.c | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/libs/x11/init.c b/libs/x11/init.c index 5cdc932..2de9da2 100644 --- a/libs/x11/init.c +++ b/libs/x11/init.c @@ -64,6 +64,8 @@ void setupdisplay_x11(void) { mo.output_height = wa.height; } + get_mh(); + if (menuposition == 2) { // centered sp.mw = MIN(MAX(max_textw() + sp.promptw, minwidth), mo.output_width); x = (mo.output_width - sp.mw) / 2 + xpos; diff --git a/spmenu.c b/spmenu.c index ff4d2db..7c9abfc 100644 --- a/spmenu.c +++ b/spmenu.c @@ -501,12 +501,24 @@ void get_width(void) { } void get_mh(void) { + int epad; + sp.mh = (lines + 1) * sp.bh; sp.mh += 2 * menumarginv; if ((hideprompt && hideinput && hidemode && hidematchcount && hidecaps) && lines) { sp.mh -= sp.bh; } + + epad = 2 * menupaddingv; + + if (mo.output_height && !xpos && !ypos) { + sp.mh = MIN(sp.mh, mo.output_height - epad); + + if (sp.mh == mo.output_height - epad) { + lines = ((mo.output_height - epad) / sp.bh) - 1; + } + } } void set_mode(void) {