From 7cb4f832374299d5f6c990d5c9b2f4f1cf8b037e Mon Sep 17 00:00:00 2001 From: Sam Hanes Date: Tue, 23 Sep 2025 10:35:23 -0700 Subject: [PATCH] Use ImGui's native DPI scaling. Fixes #868 --- src/ngscopeclient/VulkanWindow.cpp | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/src/ngscopeclient/VulkanWindow.cpp b/src/ngscopeclient/VulkanWindow.cpp index 79cd220c4..461ef695f 100644 --- a/src/ngscopeclient/VulkanWindow.cpp +++ b/src/ngscopeclient/VulkanWindow.cpp @@ -83,6 +83,8 @@ VulkanWindow::VulkanWindow(const string& title, shared_ptr queue) io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; + io.ConfigDpiScaleFonts = true; + io.ConfigDpiScaleViewports = true; //Don't serialize UI config for now //TODO: serialize to scopesession or something? https://github.com/ocornut/imgui/issues/4294 @@ -182,18 +184,6 @@ VulkanWindow::VulkanWindow(const string& title, shared_ptr queue) ImGui_ImplVulkan_Init(&info); } - //Apply DPI scaling now that glfw initialized - //This appears to be cached by glfw at init time and is not updated for dynamic scaling changes at least on X11 - //TODO: can we fix this by moving to SDL? - float scale = GetContentScale(); - LogTrace("Using ImGui style scale factor: %.2f\n", scale); - - //Per comment in imgui_impl_glfw "Apple platforms use FramebufferScale" - //On everything else use FontScaleMain -#ifndef __APPLE__ - ImGui::GetStyle().FontScaleMain = scale; -#endif - //Hook a couple of backend functions with mutexing ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); ImGui_ImplVulkan_CreateWindow = platform_io.Renderer_CreateWindow; @@ -442,16 +432,6 @@ bool VulkanWindow::UpdateFramebuffer() return true; } -float VulkanWindow::GetContentScale() -{ - float xscale; - float yscale; - glfwGetWindowContentScale(m_window, &xscale, &yscale); - - // Hope this works well should a screen have unequal X- and Y- DPIs... - return (xscale + yscale) / 2; -} - void VulkanWindow::Render() { if(m_softwareResizeRequested)