Sdl Dpi awareness on Windows / multiple monitors
pthom opened this issue · comments
An issue raised by Bernard Harmel:
I just discovered your repo https://github.com/pthom/rpn_calculator and the helloimgui sdk https://github.com/pthom/hello_imgui. Great job, thank you ! I compiled the calculator under windows and everything was ok !
After that I use helloimgui with sdl instead of glfw (-DHELLOIMGUI_WITH_SDL=ON) and with this setting i have an issue, the gui of the calculator is clipped and I can't see the whole ui even if i maximize it. I have a resolution of 3840x2160 (4K) perhaps it is the source of my problem.
I found the origin of my problem. It is related to my 4K resolution and mainly to the value of System>Display>Scale & Layout setting. With 4K res, the recommended scale value is 150% and causes my issues. If I set it to 100% the ui is fine.
How is it possible to solve this issue because I need to set the window scale setting to 150%, without this every thing is too small and this is the recommended value :-)
calling SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE); seems to fix the issue.
Any ideas why ?
Hi,
I cannot reproduce the issue on my side.
You told me that calling SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE); seems to fix the issue.
Can you confirm whether modifying hello_imgui/src/hello_imgui/internal/backend_impls/backend_window_helper/win32_dpi_awareness.cpp like this (removing two return) does solve the issue for you?
// Helper function to enable DPI awareness without setting up a manifest
void ImGui_ImplWin32_EnableDpiAwareness()
{
// Make sure monitors will be updated with latest correct scaling
// if (ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData())
// bd->WantUpdateMonitors = true;
if (_IsWindows10OrGreater())
{
static HINSTANCE user32_dll = ::LoadLibraryA("user32.dll"); // Reference counted per-process
if (PFN_SetThreadDpiAwarenessContext SetThreadDpiAwarenessContextFn =
(PFN_SetThreadDpiAwarenessContext)::GetProcAddress(user32_dll,
"SetThreadDpiAwarenessContext"))
{
SetThreadDpiAwarenessContextFn(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
return; // REMOVE THIS RETURN
}
}
if (_IsWindows8Point1OrGreater())
{
static HINSTANCE shcore_dll = ::LoadLibraryA("shcore.dll"); // Reference counted per-process
if (PFN_SetProcessDpiAwareness SetProcessDpiAwarenessFn =
(PFN_SetProcessDpiAwareness)::GetProcAddress(shcore_dll, "SetProcessDpiAwareness"))
{
SetProcessDpiAwarenessFn(PROCESS_PER_MONITOR_DPI_AWARE);
return; // REMOVE THIS RETURN ??
}
}
#if _WIN32_WINNT >= 0x0600
::SetProcessDPIAware();
#endif
}