Skip to content

Win32: Better DPI changes handling#235

Merged
prokopyl merged 3 commits intoRustAudio:masterfrom
prokopyl:dpi-fixes
May 3, 2026
Merged

Win32: Better DPI changes handling#235
prokopyl merged 3 commits intoRustAudio:masterfrom
prokopyl:dpi-fixes

Conversation

@prokopyl
Copy link
Copy Markdown
Member

@prokopyl prokopyl commented May 2, 2026

This PR improves the Win32 DPI changes handling in several ways:

  • Separate storage of current_size and current_scale_factor, allowing us to track which one changed;
  • Store the above information in Cells instead of RefCell;
  • Adjust WM_DPICHANGED event handler to properly use the RECT given with the event;
    • This fixes the window positioning itself weirdly when moving it between display.
  • Properly trigger a Resize event if the above results in changing the size;
    • It turns out the WM_DPICHANGED often happens after the WM_SIZE event when changing the DPI of the window, leaving the event handler "behind" until the window was resized again.
  • Fix how the scaling factor was read and initialized on initial window creation.
    • This fixes the initial frame being only partially covering the window on a non-96dpi display.

This is a leaner version of #178, leaving the more "refactor-y" parts of it for later.
Note that there are still some DPI-related issues even after this PR, but they require some larger refactoring and usage of DPI-aware Win32 functions (e.g. AdjustWindowRectExForDpi, SetThreadDpiAwarenessContext, etc.), so we'll do these after the v0.1 release.

@prokopyl prokopyl requested a review from micahrj May 2, 2026 10:20
@prokopyl prokopyl force-pushed the dpi-fixes branch 2 times, most recently from b0bb0d2 to f9af5e4 Compare May 3, 2026 07:51
@prokopyl prokopyl removed the request for review from micahrj May 3, 2026 15:33
@prokopyl prokopyl merged commit fa2c51c into RustAudio:master May 3, 2026
3 checks passed
@prokopyl prokopyl deleted the dpi-fixes branch May 3, 2026 15:36
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.

Windows: Panic "already borrowed" when reentering wnd_proc due to mouse move or timer

1 participant