From 89b7ee444fb628e066d844dd704dbcf2acfc79e6 Mon Sep 17 00:00:00 2001 From: casey langen Date: Mon, 2 Jan 2023 14:07:24 -0800 Subject: [PATCH] Merge upstream PDCurses changes. --- src/3rdparty/win32_src/pdcurses/initscr.c | 13 ++++--- .../win32_src/pdcurses/wincon/pdcwin.h | 5 --- .../win32_src/pdcurses/wingui/pdcdisp.c | 5 +++ .../win32_src/pdcurses/wingui/pdckbd.c | 16 ++++----- .../win32_src/pdcurses/wingui/pdcscrn.c | 34 +++++++++++++++++++ src/musikcube/cursespp/cursespp/Window.h | 6 +--- 6 files changed, 54 insertions(+), 25 deletions(-) diff --git a/src/3rdparty/win32_src/pdcurses/initscr.c b/src/3rdparty/win32_src/pdcurses/initscr.c index 02c69c4f9..33fa97e27 100644 --- a/src/3rdparty/win32_src/pdcurses/initscr.c +++ b/src/3rdparty/win32_src/pdcurses/initscr.c @@ -156,7 +156,7 @@ WINDOW *initscr(void) if (SP && SP->alive) return NULL; - SP = calloc(1, sizeof(SCREEN)); + SP = (SCREEN *)calloc(1, sizeof(SCREEN)); assert( SP); if (!SP) return NULL; @@ -274,13 +274,13 @@ WINDOW *initscr(void) longname( ); - SP->c_buffer = malloc(_INBUFSIZ * sizeof(int)); + SP->c_buffer = (int *)malloc(_INBUFSIZ * sizeof(int)); if (!SP->c_buffer) return NULL; SP->c_pindex = 0; SP->c_gindex = 1; - SP->c_ungch = malloc(NUNGETCH * sizeof(int)); + SP->c_ungch = (int *)malloc(NUNGETCH * sizeof(int)); if (!SP->c_ungch) return NULL; SP->c_ungind = 0; @@ -334,13 +334,13 @@ SCREEN *newterm(const char *type, FILE *outfd, FILE *infd) return initscr() ? SP : NULL; } -SCREEN *set_term(SCREEN *new) +SCREEN *set_term(SCREEN *new_scr) { PDC_LOG(("set_term() - called\n")); /* We only support one screen */ - return (new == SP) ? SP : NULL; + return (new_scr == SP) ? SP : NULL; } void delscreen(SCREEN *sp) @@ -367,6 +367,9 @@ void delscreen(SCREEN *sp) optr->window_list[i]->_parent = NULL; while( optr->n_windows) delwin( optr->window_list[0]); + /* With all windows deleted, the window */ + /* list should be empty. */ + assert( !optr->window_list); PDC_free_atrtab( ); stdscr = (WINDOW *)NULL; diff --git a/src/3rdparty/win32_src/pdcurses/wincon/pdcwin.h b/src/3rdparty/win32_src/pdcurses/wincon/pdcwin.h index 64b77eed8..189f77006 100644 --- a/src/3rdparty/win32_src/pdcurses/wincon/pdcwin.h +++ b/src/3rdparty/win32_src/pdcurses/wincon/pdcwin.h @@ -1,8 +1,5 @@ /* PDCurses */ -#ifndef __PDC_WIN_H__ -#define __PDC_WIN_H__ - #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) # define _CRT_SECURE_NO_DEPRECATE 1 /* kill nonsense warnings */ #endif @@ -36,5 +33,3 @@ extern short pdc_oldf, pdc_oldb, pdc_oldu; extern bool pdc_conemu, pdc_wt, pdc_ansi; extern void PDC_blink_text(void); - -#endif \ No newline at end of file diff --git a/src/3rdparty/win32_src/pdcurses/wingui/pdcdisp.c b/src/3rdparty/win32_src/pdcurses/wingui/pdcdisp.c index 8288596a9..3fad796f1 100644 --- a/src/3rdparty/win32_src/pdcurses/wingui/pdcdisp.c +++ b/src/3rdparty/win32_src/pdcurses/wingui/pdcdisp.c @@ -283,6 +283,11 @@ static LOGFONT PDC_get_logical_font( const int font_idx) LOGFONT lf; + if ( PDC_font_size < 0) + { + PDC_font_size = scale_font_for_current_dpi( 12); /* default 12 points */ + } + memset(&lf, 0, sizeof(LOGFONT)); /* Clear out structure. */ lf.lfHeight = -PDC_font_size; #ifdef PDC_WIDE diff --git a/src/3rdparty/win32_src/pdcurses/wingui/pdckbd.c b/src/3rdparty/win32_src/pdcurses/wingui/pdckbd.c index 4aa282931..9aaf6e34e 100644 --- a/src/3rdparty/win32_src/pdcurses/wingui/pdckbd.c +++ b/src/3rdparty/win32_src/pdcurses/wingui/pdckbd.c @@ -19,19 +19,15 @@ extern int PDC_key_queue[KEY_QUEUE_SIZE]; bool PDC_check_key(void) { - MSG msg; - extern HWND PDC_hWnd; - - while( PeekMessage(&msg, PDC_hWnd, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE) ) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - - PDC_napms(1); + static int count; if( PDC_key_queue_low != PDC_key_queue_high) return TRUE; + if( count++ == 100) + { + count = 0; + PDC_napms( 1); + } return FALSE; } diff --git a/src/3rdparty/win32_src/pdcurses/wingui/pdcscrn.c b/src/3rdparty/win32_src/pdcurses/wingui/pdcscrn.c index 6b8bf3b6c..745885b2e 100644 --- a/src/3rdparty/win32_src/pdcurses/wingui/pdcscrn.c +++ b/src/3rdparty/win32_src/pdcurses/wingui/pdcscrn.c @@ -1204,6 +1204,21 @@ void PDC_set_window_resized_callback(resize_callback_fnptr callback) { resize_callback = callback; } +/* Under Wine, it appears that the code to force the window size to be +an integral number of columns and rows doesn't work. This is because +WM_SIZING messages aren't sent. This appeared to be fixed as of Wine +1.7.18, and Wine-specific code was removed at that point. The bug +recrudesced in Wine 7.0.1. + + Therefore, _in Wine only_, attempting to resize the window to be +an exact number of rows/columns results in cascading resize attempts. +So we check on initialization to see if we're in Wine; if we are, +resizes are skipped. */ + +typedef const char *(CDECL *wine_version_func)(void); + +static wine_version_func wine_version; + static void HandleSize( const WPARAM wParam, const LPARAM lParam) { static WPARAM prev_wParam = (WPARAM)-99; @@ -1254,6 +1269,8 @@ static void HandleSize( const WPARAM wParam, const LPARAM lParam) } } } + else if( wine_version) + return; add_resize_key = 1; if( wParam == SIZE_RESTORED && @@ -2235,7 +2252,24 @@ INLINE int set_up_window( void) int PDC_scr_open(void) { + const HMODULE hntdll = GetModuleHandle( _T("ntdll.dll")); + const HMODULE shcoredll = GetModuleHandle(_T("Shcore.dll")); + PDC_LOG(("PDC_scr_open() - called\n")); + + if( hntdll) + wine_version = (wine_version_func)GetProcAddress(hntdll, "wine_get_version"); + + if ( shcoredll) { + typedef HRESULT *(CDECL *set_process_dpi_awareness_t)(int); + static set_process_dpi_awareness_t set_process_dpi_awareness_func; + static int ADJUST_DPI_PER_MONITOR = 2; + set_process_dpi_awareness_func = (set_process_dpi_awareness_t)GetProcAddress(shcoredll, "SetProcessDpiAwareness"); + if ( set_process_dpi_awareness_func) { + set_process_dpi_awareness_func(ADJUST_DPI_PER_MONITOR); + } + } + COLORS = N_COLORS; /* should give this a try and see if it works! */ if (!SP || PDC_init_palette( )) return ERR; diff --git a/src/musikcube/cursespp/cursespp/Window.h b/src/musikcube/cursespp/cursespp/Window.h index 50b3fe306..014a00014 100644 --- a/src/musikcube/cursespp/cursespp/Window.h +++ b/src/musikcube/cursespp/cursespp/Window.h @@ -41,11 +41,7 @@ #include #ifdef WIN32 - #if defined(PDCURSES_WINCON) || defined(_CONSOLE) - #define IDLE_TIMEOUT_MS 1 - #else - #define IDLE_TIMEOUT_MS 0 - #endif + #define IDLE_TIMEOUT_MS 1 #define REDRAW_DEBOUNCE_MS 100 #else #define IDLE_TIMEOUT_MS 75