Repository navigation
Rescale the UI when the screen DPI changes while the app runs (#1162, #1163) - #1183
Merged
Merged
Conversation
…1163) Platform.setSystemScreenDpi() sets the DPI detected by the backend and, when SCREEN_DPI changes, reloads the fonts and images cached for the old DPI and lays the windows out again (what the SDL backend did inline). A value outside the supported range (isSupportedScreenDpi(), now shared with the SCREEN_DPI setter) is logged once. Windows scale their client size limits from the DPI they were set for before they are resized. X11 (#1162): the app selects PropertyChangeMask on the root window of screen 0 and reads Xft.dpi from RESOURCE_MANAGER again when it changes (XResourceManagerString() keeps the value from when the display was opened). The change is applied in the outermost pumpEvents(), not while getClipboardText() waits. Windows in normal state are resized by the DPI ratio and kept in the work area. Win32 (#1163): the process is per-monitor DPI aware (v2) where available, else system DPI aware as before. WM_GETDPISCALEDSIZE answers the size for the new DPI: the client size setWindowState() is setting, else the current one scaled from the SCREEN_DPI it was made for to the new one, with the frame for the new DPI; WM_DPICHANGED applies the rectangle Windows suggests. Frames are computed for the window's DPI (AdjustWindowRectExForDpi). The first window takes the DPI of the monitor it is created on. SCREEN_DPI stays global: with windows on monitors of different scales, the last change wins. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 24, 2026
buggins
marked this pull request as ready for review
November 24, 2026 17:37
This was referenced Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1162, fixes #1163.
When the desktop scale changes while the app runs, the UI is now rescaled instead of keeping its startup size (X11) or being stretched as a bitmap (Win32).
Common
Platform.setSystemScreenDpi(dpi): sets the DPI detected by the backend. WhenSCREEN_DPIchanges, it reloads the fonts and images cached for the old DPI and lays the windows out again. The SDL backend did this inline and now uses it.isSupportedScreenDpi()incore/types.d: the 72–500 range, shared by theSCREEN_DPIsetter,overrideScreenDPIand Win32. A rejected value is logged once.Window.scaleClientSizeLimitsToScreenDpi(): min/max client sizes are scaled from the DPI they were set for before a DPI resize, so they don't hold a window at its old size.X11 (#1162)
PropertyChangeMaskon the root window of screen 0, whereRESOURCE_MANAGERlives, selected beforeXft.dpiis first read. Each change readsXft.dpiagain from the property (XResourceManagerString()keeps the value from when the display was opened). WithoutXft.dpi: 96, as at startup.pumpEvents(), not whilegetClipboardText()waits for the selection.Win32 (#1163)
Per-monitor DPI awareness (v2) where available (
SetProcessDpiAwarenessContext), elseSetProcessDPIAwareas before.WM_GETDPISCALEDSIZE(Windows' question for the size at the new DPI), answered with the frame for the new DPI plus:setWindowState(), the client size it is setting (so a restored window doesn't grow);SCREEN_DPIit was made for (updated on every size change) to the new one.That means: with an override, nothing changes; after a system scale change, every window is resized; a dialog created on another monitor and moved over its parent keeps its size. Minimized and maximized windows are left to Windows.
WM_DPICHANGEDapplies the rectangle Windows suggests, as Microsoft documents.Frames are computed for the window's DPI (
AdjustWindowRectExForDpi, falling back toAdjustWindowRectEx) when restoring sizes and for min/max sizes.setWindowState()reads the reached rectangle back (normal state only).The first window takes the DPI of the monitor it is created on (
GetDpiForWindow), with its client size scaled (not for fullscreen windows). Later windows don't change the global DPI on creation.Limitations
SCREEN_DPIstays global: with windows on monitors of different scales, the last change wins. Follow-ups: per-window DPI (#1184), Win32 window icon sizes per monitor (#1185), smaller points from the last review (#1187). Found during the review: #1186 (an older Win32 bug with multisampling and OpenGL disabled).Testing
dub test: Linux with LDC 1.36 and DMD 2.107.1, Windows, and-c console; no leak lines. D-Scanner: clean. Builds: default, x11, Win32.setSystemScreenDpi()reloads and lays out only on an actual change, and not under an override; checked that it fails with a broken version.:99, example1 x11 config,Xft.dpichanged withxrdb):WM_DELETE_WINDOW, one exited without its exit log). They weren't reproducible afterwards (50+ runs). The window-map iteration that could modify the map during the loop was fixed since; no proof it was the cause.Xft.dpi: 600logs the warning and keeps the DPI._NET_WM_*atoms; on bare Xvfb they had to be created first (X11: the app dies with BadAtom on an X server without a window manager #1181).WM_GETDPISCALEDSIZEandWM_DPICHANGEDto its own window, as Windows does: 120 → 144 → 120 rescales the UI sharply and resizes the window. WithoverrideScreenDPIthe client size follows the content's scale. No leaks inui.log.GetDpiForWindowon a secondary monitor (single-monitor machine here), and desktop environments beyond plainXft.dpichanges.🤖 Generated with Claude Code