Skip to content

Fix windowed mode maximizing and ImGui mouse offset on scaled displays - #228

Merged
BenjaFriend merged 2 commits into
mainfrom
fix/window-scale-imgui
Oct 28, 2026
Merged

BenjaFriend merged 2 commits into
mainfrom
fix/window-scale-imgui

Conversation

@BenjaFriend

@BenjaFriend BenjaFriend commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Problem

On a 2560x1440 display at 1.25 fractional scaling (GLFW running natively on Wayland):

  • Window boots maximized. The configured 1920x1080 window covers almost all of the 2048x1152 logical work area, so GNOME's auto-maximize maximizes it on first map (window became 1981x1083 with GLFW_MAXIMIZED set).
  • ImGui input offset. io.DisplaySize was the framebuffer size (2400x1350) while mouse positions are in window coordinates (1920x1080), so clicks landed 1.25x closer to the top-left than the cursor.

Changes

  • DesktopWindow::FitToWorkArea shrinks the window (keeping aspect ratio) if it would cover more than 75% of the monitor work area. On Wayland the work area is converted using the window's content scale, since the monitor scale is rounded up to an integer. This runs before the first present, so the compositor never maximizes it.
  • FlingWindow gains GetWindowWidth() / GetWindowHeight() (screen coordinates, the units mouse positions use). The old GetWidth() / GetHeight() are renamed to GetFramebufferWidth() / GetFramebufferHeight() (pixels) so the two sizes can't be confused.
  • ImGui uses the window size plus DisplayFramebufferScale; ImGuiSubpass sets the viewport and scissor rects in framebuffer pixels (scissors are clamped and empty clips skipped).
  • Fix VulkanApp::CreateGameWindow assigning m_Height twice instead of setting m_Width.
  • Log window and framebuffer size at creation.

Testing

  • All 96 CTest tests pass; comment-style check passes.
  • Sandbox --unattended --frames 120 and --null-render both exit 0.
  • Verified at startup: window 1536x864, framebuffer 1920x1080, not maximized.
  • ImGui mouse alignment still needs a manual check on a scaled display.

🤖 Generated with Claude Code

BenjaFriend and others added 2 commits October 28, 2026 07:35
On a display with fractional scaling (e.g. Wayland at 1.25x), a 1920x1080
window covers most of the work area, so GNOME auto-maximizes it. The window
now shrinks to fit within 75% of the work area before its first frame.

ImGui was given the framebuffer size while mouse positions are in window
coordinates, so clicks landed short of the cursor. ImGui now uses the window
size plus DisplayFramebufferScale, and the ImGui pass scales its viewport and
scissor rects to framebuffer pixels.

Also fix CreateGameWindow never setting the width correctly for invalid sizes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…bufferHeight.

The window now has two sizes, framebuffer pixels and screen coordinates, so
name the pixel one explicitly next to GetWindowWidth/GetWindowHeight.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@BenjaFriend
BenjaFriend merged commit 8a3775d into main Oct 28, 2026
11 checks passed
@BenjaFriend
BenjaFriend deleted the fix/window-scale-imgui branch October 28, 2026 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant