From 7caa46e443eb4bb5510288a59bd23b083c79eb6b Mon Sep 17 00:00:00 2001 From: Max Risuhin Date: Mon, 11 Feb 2019 22:27:42 +0200 Subject: [PATCH] Recalculate monitor based DPI scale if Window moved; Set DPI awareness of UI on Windows. (#206) --- gui/gui.go | 11 +++++++++++ platform/winproc.go | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/gui/gui.go b/gui/gui.go index 1b48ded..71a1df6 100644 --- a/gui/gui.go +++ b/gui/gui.go @@ -340,6 +340,8 @@ func (gui *GUI) Render() error { gui.terminal.SetDirty() } }) + gui.window.SetPosCallback(gui.windowPosChangeCallback) + glfw.SetMonitorCallback(gui.monitorChangeCallback) gui.generateDefaultCell(false) @@ -735,3 +737,12 @@ func (gui *GUI) Screenshot(path string) { defer file.Close() png.Encode(file, img) } + +func (gui *GUI) windowPosChangeCallback(w *glfw.Window, xpos int, ypos int) { + gui.SetDPIScale() +} + +func (gui *GUI) monitorChangeCallback(monitor *glfw.Monitor, event glfw.MonitorEvent) { + gui.SetDPIScale() +} + diff --git a/platform/winproc.go b/platform/winproc.go index 188d183..d816c41 100644 --- a/platform/winproc.go +++ b/platform/winproc.go @@ -19,9 +19,11 @@ package platform // PVOID lpPreviousValue, // PSIZE_T lpReturnSize // ); +// typedef BOOL (* SetProcessDpiAwarenessContextType)(handle_t); // // InitializeProcThreadAttributeListProcType pfnInitializeProcThreadAttributeList = NULL; // UpdateProcThreadAttributeProcType pfnUpdateProcThreadAttribute = NULL; +// SetProcessDpiAwarenessContextType pfnSetProcessDpiAwarenessContext = NULL; // // #define ProcThreadAttributePseudoConsole 22 // @@ -43,6 +45,10 @@ package platform // LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList; // } STARTUPINFOEXW, *LPSTARTUPINFOEXW; // +// #ifndef DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 +// #define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((handle_t)-4) +// #endif +// // HMODULE hLibKernel32_Proc = NULL; // // DWORD initProcKernFuncs() @@ -68,6 +74,22 @@ package platform // return 0; // } // +// DWORD enableHiDpiSupport() { +// HMODULE hLibUser32_Proc = LoadLibrary( "User32.dll" ); +// if( hLibUser32_Proc == NULL ) +// { +// return -1; +// } +// +// pfnSetProcessDpiAwarenessContext = (SetProcessDpiAwarenessContextType) GetProcAddress(hLibUser32_Proc, "SetProcessDpiAwarenessContext" ); +// if( pfnInitializeProcThreadAttributeList == NULL ) +// { +// return -1; +// } +// (*pfnSetProcessDpiAwarenessContext)( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ); +// return 0; +// } +// // DWORD createGuestProcHelper( uintptr_t hpc, LPCWSTR imagePath, uintptr_t * hProcess, DWORD * dwProcessID ) // { // STARTUPINFOEXW si; @@ -152,6 +174,9 @@ var procsInitSucceeded = false func init() { ret := int(C.initProcKernFuncs()) + if ret == 0 { + ret = int(C.enableHiDpiSupport()) + } procsInitSucceeded = (ret == 0) }