Skip to content

GLFW: DPI scaling seems to be applied twice on style on Wayland #9422

Description

@Cyphall

Version/Branch of Dear ImGui:

Version 1.92.8, Branch: docking

Back-ends:

imgui_impl_glfw.cpp + custom render backend

Compiler, OS:

Linux Fedora 44

Full config/build information:

Using GLFW X11 backend:

Dear ImGui 1.92.8 (19280)
--------------------------------

sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=201703
define: IMGUI_DISABLE_OBSOLETE_FUNCTIONS
define: __linux__
define: __GNUC__=4
define: __clang_version__=22.1.6 (Fedora 22.1.6-1.fc44)
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
IM_ASSERT: runs expression: OK. expand size: OK
--------------------------------

io.BackendPlatformName: imgui_impl_glfw (3400)
io.BackendRendererName: ImGuiVulkanBackend
io.ConfigFlags: 0x00000080
 DockingEnable
io.ConfigDpiScaleFonts
io.ConfigDpiScaleViewports
io.ConfigViewportsNoDecoration
io.ConfigViewportsNoDefaultParent
io.ConfigNavCaptureKeyboard
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x0000181E
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasVtxOffset
 RendererHasTextures
--------------------------------

io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,256
io.Fonts->FontLoaderName: FreeType (2.14.3; 2.14.3)
io.DisplaySize: 3840.00,2006.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------

style.WindowPadding: 16.00,16.00
style.WindowBorderSize: 2.00
style.FramePadding: 10.00,8.00
style.FrameRounding: 4.00
style.FrameBorderSize: 2.00
style.ItemSpacing: 16.00,8.00
style.ItemInnerSpacing: 8.00,8.00

Using GLFW Wayland backend:

Dear ImGui 1.92.8 (19280)
--------------------------------

sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=201703
define: IMGUI_DISABLE_OBSOLETE_FUNCTIONS
define: __linux__
define: __GNUC__=4
define: __clang_version__=22.1.6 (Fedora 22.1.6-1.fc44)
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
IM_ASSERT: runs expression: OK. expand size: OK
--------------------------------

io.BackendPlatformName: imgui_impl_glfw (3400)
io.BackendRendererName: ImGuiVulkanBackend
io.ConfigFlags: 0x00000080
 DockingEnable
io.ConfigDpiScaleFonts
io.ConfigDpiScaleViewports
io.ConfigViewportsNoDecoration
io.ConfigViewportsNoDefaultParent
io.ConfigNavCaptureKeyboard
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x0000101E
 HasMouseCursors
 HasSetMousePos
 HasMouseHoveredViewport
 RendererHasVtxOffset
 RendererHasTextures
--------------------------------

io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,256
io.Fonts->FontLoaderName: FreeType (2.14.3; 2.14.3)
io.DisplaySize: 1829.00,955.00
io.DisplayFramebufferScale: 2.10,2.10
--------------------------------

style.WindowPadding: 16.00,16.00
style.WindowBorderSize: 2.00
style.FramePadding: 10.00,8.00
style.FrameRounding: 4.00
style.FrameBorderSize: 2.00
style.ItemSpacing: 16.00,8.00
style.ItemInnerSpacing: 8.00,8.00

Details:

When running with GLFW's Wayland backend, DPI scaling is applied twice on styles (fonts seem to be unaffected).

My app does this to handle DPI:

ImGuiIO& io = ImGui::GetIO();
io.ConfigDpiScaleFonts = true;
io.ConfigDpiScaleViewports = true;

float pixelScale;
glfwGetWindowContentScale(window, &pixelScale, nullptr);

ImGuiStyle& style = ImGui::GetStyle();
style.ScaleAllSizes(pixelScale);
style.FontSizeBase = 14;

(full source code here)

Also, looking at the build infos, io.DisplaySize and io.DisplayFramebufferScale are different between X11 and Wayland.

Screenshots/Video:

Using GLFW X11 backend:
Image

Using GLFW Wayland backend:
Image

Minimal, Complete and Verifiable Example code:

Put one of those lines as the first line of the main() function in example_glfw_opengl3 to compare backend behaviors:

glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_X11);
// or
glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_WAYLAND);

The symptoms are slightly different here, Wayland shows a blurry render instead of double-scaled styles, as if the scaling was done by the compositor rather than the app itself.

The difference comes from the source of the DPI scale passed to ImGui::ScaleAllSizes:

  • The example gets it from ImGui_ImplGlfw_GetContentScaleForMonitor, which always returns 1 on Wayland for some reason (X11 correctly reports 2.1).
  • My app gets it from glfwGetWindowContentScale, which correctly reports 2.1 on both X11 and Wayland.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions