commit 4aecb462e5fccf9b2faceb0c4d21bc0f64ee82e2
parent 87343a5fc63c320e6fdffd01f6c84b9e9cf46f8b
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Tue, 13 Oct 2026 23:11:59 +0530
parent 87343a5fc63c320e6fdffd01f6c84b9e9cf46f8b
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Tue, 13 Oct 2026 23:11:59 +0530
Keep requested list height within the screen
3 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/README b/README @@ -27,7 +27,7 @@ Useful flags: -e utf8|ansi|oem stdin/stdout/prompt encoding; default utf8 -x px -y px -w px position and width -c center window --l lines visible list lines +-l lines visible list lines (capped to screen height) -m select multiple entries; Ctrl+Enter adds one -V enable vi support; Ctrl+Alt+V toggles vi mode -d use normal Windows edit shortcuts instead of emacs-ish keys
diff --git a/test_stream.c b/test_stream.c @@ -17,6 +17,9 @@ static LRESULT CALLBACK TestWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) int main(int argc, char **argv) { + assert(fit_lines(INT_MAX, 300) == 12); + assert(fit_lines(0, 300) == 5); + assert(fit_lines(7, 35) == 1); assert(has_match("aC", "ABC")); assert(!has_match("Ab", "abc")); /* Preserve fzy's ASCII query casing. */ assert(has_match("\xc3\xa9", "caf\xc3\xa9"));
diff --git a/wmenu.c b/wmenu.c @@ -766,6 +766,15 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) return DefWindowProcW(hwnd, msg, wp, lp); } +static int fit_lines(int requested, int screen_height) +{ + int row_height = S(22); + int fit = row_height > 0 && screen_height > S(28) ? (screen_height - S(28)) / row_height : 1; + if (fit < 1) fit = 1; + if (requested < 1) requested = 5; + return requested < fit ? requested : fit; +} + static void usage(void) { puts("usage: wmenu [-chimbdVv] [-e utf8|ansi|oem] [-p prompt] [-x px] [-y px] [-w px] [-l lines] [-fn name] [-fs pt] [-fw weight] < items"); @@ -845,7 +854,8 @@ int main(int argc, char **argv) InitCommonControlsEx(&icc); make_font(); if (!win_w) win_w = GetSystemMetrics(SM_CXSCREEN); - win_h = has_items ? S(28) + (lines > 0 ? lines : 5) * S(22) : S(28); + lines = fit_lines(lines, GetSystemMetrics(SM_CYSCREEN)); + win_h = has_items ? S(28) + lines * S(22) : S(28); if (center_window) { win_x = (GetSystemMetrics(SM_CXSCREEN) - win_w) / 2; win_y = (GetSystemMetrics(SM_CYSCREEN) - win_h) / 2;
: nply/wmenu