Recalculate monitor based DPI scale if Window moved; Set DPI awareness of UI on Windows. (#206)

This commit is contained in:
Max Risuhin 2019-02-11 22:27:42 +02:00 committed by Liam Galvin
parent 77348c2188
commit 7caa46e443
2 changed files with 36 additions and 0 deletions

View File

@ -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()
}

View File

@ -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)
}