From d78a87511095b1636754788fbe0a46ec43eb19a5 Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 16 May 2026 12:15:20 -0400 Subject: [PATCH] more Windows curses size tinkering --- include/extern.h | 8 ++++---- sys/windows/consoletty.c | 4 ++-- sys/windows/windsys.c | 12 ------------ win/curses/cursinit.c | 38 ++++++++++++-------------------------- win/win32/mhmain.c | 13 +++++++++++++ 5 files changed, 31 insertions(+), 44 deletions(-) diff --git a/include/extern.h b/include/extern.h index 64026008e..92a38c0ff 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2033,8 +2033,8 @@ extern int win32_cr_gettrace(int, char *, int); extern int *win32_cr_shellexecute(const char *); # endif #ifdef MSWIN_GRAPHICS -extern int get_approx_window_column_width(void); -extern int get_approx_window_rows(void); +extern int get_approx_display_width(void); +extern int get_approx_display_rows(void); #endif #endif /* WIN32 */ @@ -2185,8 +2185,8 @@ void console_g_putch(int in_ch); extern void set_output_mode(int); extern void synch_cursor(void); extern void nethack_enter_consoletty(void); -extern int get_console_width(void); -extern int get_console_height(void); +extern int get_approx_display_cols(void); +extern int get_approx_display_rows(void); extern void console_exit(void); extern int set_keyhandling_via_option(void); #ifdef ENHANCED_SYMBOLS diff --git a/sys/windows/consoletty.c b/sys/windows/consoletty.c index 2fac8b212..c44c95232 100644 --- a/sys/windows/consoletty.c +++ b/sys/windows/consoletty.c @@ -2644,13 +2644,13 @@ void nethack_enter_consoletty(void) } int -get_console_width(void) +get_approx_display_cols(void) { return console.width; } int -get_console_height(void) +get_approx_display_rows(void) { return console.height; } diff --git a/sys/windows/windsys.c b/sys/windows/windsys.c index 40c788a0d..91dc8eb40 100644 --- a/sys/windows/windsys.c +++ b/sys/windows/windsys.c @@ -1252,18 +1252,6 @@ error: } #undef win32err -#ifdef MSWIN_GRAPHICS -int -get_approx_window_column_width(void) -{ - return GetSystemMetrics(SM_CXSCREEN) / 8; -} -int -get_approx_window_rows(void) -{ - return GetSystemMetrics(SM_CYSCREEN) / 12; -} -#endif #include #define MAX_SYM_SIZE 100 diff --git a/win/curses/cursinit.c b/win/curses/cursinit.c index dd733a156..c53edd981 100644 --- a/win/curses/cursinit.c +++ b/win/curses/cursinit.c @@ -762,40 +762,26 @@ curses_init_options(void) size in the config file, we will set it to a nice big 32x110 to take advantage of some of the nice features of this windowport. */ if (iflags.wc2_term_cols == 0) { -#ifndef MSWIN_GRAPHICS - int console_width = get_console_width(); + int display_width = get_approx_display_cols(); - if (console_width != 0) - iflags.wc2_term_cols = console_width; + if (display_width > 220) + display_width = 220; + + if (display_width != 0) + iflags.wc2_term_cols = display_width; else iflags.wc2_term_cols = 110; -#else - int width = get_approx_window_column_width(); - - if (width > 220) - width = 220; - - if (width != 0) - iflags.wc2_term_cols = width; - else - iflags.wc2_term_cols = 110; -#endif } if (iflags.wc2_term_rows == 0) { -#ifndef MSWIN_GRAPHICS - int console_height = get_console_height(); + int display_height = get_approx_display_rows(); - if (console_height != 0) - iflags.wc2_term_rows = console_height; + if (display_height > 64) + display_height = 64; + + if (display_height != 0) + iflags.wc2_term_rows = display_height; else iflags.wc2_term_rows = 32; -#else - int scrows = get_approx_window_rows(); - - if (scrows > 54) - scrows = 54; - iflags.wc2_term_rows = scrows ? scrows : 32; -#endif } resize_term(iflags.wc2_term_rows, iflags.wc2_term_cols); getmaxyx(base_term, term_rows, term_cols); diff --git a/win/win32/mhmain.c b/win/win32/mhmain.c index bd3ffda5a..d543def7b 100644 --- a/win/win32/mhmain.c +++ b/win/win32/mhmain.c @@ -1361,6 +1361,19 @@ nh_compose_ascii_screenshot(void) return retval; } +int +get_approx_display_cols(void) +{ + return GetSystemMetrics(SM_CXSCREEN) / 8; +} + +int +get_approx_display_rows(void) +{ + return GetSystemMetrics(SM_CYSCREEN) / 12; +} + + #ifdef ENHANCED_SYMBOLS // returns malloc() created pointer - callee assumes the ownership static WCHAR *