From c6e21e3da5daf56b8b5184bfe37b440ee7fa4d7f Mon Sep 17 00:00:00 2001 From: tildearrow Date: Thu, 20 Oct 2022 02:49:08 -0500 Subject: [PATCH] GUI: fix input scaling --- .../imgui_patched/backends/imgui_impl_sdl.cpp | 54 +++++++------------ 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/extern/imgui_patched/backends/imgui_impl_sdl.cpp b/extern/imgui_patched/backends/imgui_impl_sdl.cpp index 2424dd41..e7ae8d07 100644 --- a/extern/imgui_patched/backends/imgui_impl_sdl.cpp +++ b/extern/imgui_patched/backends/imgui_impl_sdl.cpp @@ -276,9 +276,6 @@ bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event) case SDL_MOUSEMOTION: { ImVec2 mouse_pos((float)event->motion.x, (float)event->motion.y); -#ifdef __APPLE__ - -#endif if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { int window_x, window_y; @@ -286,16 +283,14 @@ bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event) mouse_pos.x += window_x; mouse_pos.y += window_y; } -#ifdef __APPLE__ - // Fix for high DPI mac - ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); - if (!platform_io.Monitors.empty() && platform_io.Monitors[0].DpiScale > 1.0f) - { - // The Framebuffer is scaled by an integer ceiling of the actual ratio, so 2.0 not 1.685 on Mac! - mouse_pos.x *= std::ceil(platform_io.Monitors[0].DpiScale); - mouse_pos.y *= std::ceil(platform_io.Monitors[0].DpiScale); - } -#endif + // Fix for high DPI mac/idevice/wayland + ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); + if (!platform_io.Monitors.empty() && platform_io.Monitors[0].DpiScale > 1.0f) + { + // The Framebuffer is scaled by an integer ceiling of the actual ratio, so 2.0 not 1.685 on Mac! + mouse_pos.x *= std::ceil(platform_io.Monitors[0].DpiScale); + mouse_pos.y *= std::ceil(platform_io.Monitors[0].DpiScale); + } io.AddMousePosEvent(mouse_pos.x, mouse_pos.y); return true; } @@ -551,16 +546,14 @@ static void ImGui_ImplSDL2_UpdateMouseData() mouse_x -= window_x; mouse_y -= window_y; } -#ifdef __APPLE__ - // Fix for high DPI mac - ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); - if (!platform_io.Monitors.empty() && platform_io.Monitors[0].DpiScale > 1.0f) - { - // The Framebuffer is scaled by an integer ceiling of the actual ratio, so 2.0 not 1.685 on Mac! - mouse_x *= std::ceil(platform_io.Monitors[0].DpiScale); - mouse_y *= std::ceil(platform_io.Monitors[0].DpiScale); - } -#endif + // Fix for high DPI mac/idevice/wayland + ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); + if (!platform_io.Monitors.empty() && platform_io.Monitors[0].DpiScale > 1.0f) + { + // The Framebuffer is scaled by an integer ceiling of the actual ratio, so 2.0 not 1.685 on Mac! + mouse_x *= std::ceil(platform_io.Monitors[0].DpiScale); + mouse_y *= std::ceil(platform_io.Monitors[0].DpiScale); + } io.AddMousePosEvent((float)mouse_x, (float)mouse_y); } } @@ -669,13 +662,7 @@ static void ImGui_ImplSDL2_UpdateMonitors() monitor.WorkSize = ImVec2((float)r.w, (float)r.h); #endif #if SDL_HAS_PER_MONITOR_DPI -#ifdef __APPLE__ - monitor.DpiScale=getMacDPIScale(); -#else - float dpi = 0.0f; - if (!SDL_GetDisplayDPI(n, &dpi, NULL, NULL)) - monitor.DpiScale = dpi / 96.0f; -#endif + monitor.DpiScale = 1.0f; #endif platform_io.Monitors.push_back(monitor); } @@ -701,15 +688,14 @@ void ImGui_ImplSDL2_NewFrame() if (w > 0 && h > 0) io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h); -#if defined(__APPLE__) - // On Apple, The window size is reported in Low DPI, even when running in high DPI mode + // On Apple and Wayland, The window size is reported in Low DPI, even when running in high DPI mode ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); - if (!platform_io.Monitors.empty() && platform_io.Monitors[0].DpiScale > 1.0f && display_h != h) + if (!platform_io.Monitors.empty() /*&& platform_io.Monitors[0].DpiScale > 1.0f*/ && display_h != h) { io.DisplayFramebufferScale = ImVec2(1.0f, 1.0f); io.DisplaySize = ImVec2((float)display_w, (float)display_h); + platform_io.Monitors[0].DpiScale=(float)display_w/(float)w; } -#endif // Setup time step (we don't use SDL_GetTicks() because it is using millisecond resolution) static Uint64 frequency = SDL_GetPerformanceFrequency();