Skip to content

On Windows, stop a dragged window bouncing between mixed-DPI monitors - #20

Open
insanedps wants to merge 1 commit into
iced-rs:2026-10-02from
insanedps:fix/dpi-drag-loop
Open

insanedps wants to merge 1 commit into
iced-rs:2026-10-02from
insanedps:fix/dpi-drag-loop

Conversation

@insanedps

Copy link
Copy Markdown

Problem

On Windows with two monitors at different scale factors, dragging an iced window from one monitor to the other makes it flip back and forth between the two monitors and grow on every crossing. Releasing the mouse and grabbing it again puts it back on the monitor it came from, or part way between.

In WM_DPICHANGED, winit ignores the rect Windows suggests and builds its own "conservative" rect, then checks it against MonitorFromWindow. During a drag that still answers with the monitor being left, so the window is nudged back onto it. That move sends another WM_DPICHANGED, which rescales the size again, and the two feed each other while the drag lasts.

This is upstream rust-windowing#3040 / rust-windowing#4041; upstream fixed it in rust-windowing#4341 (merged, Windows 11 uses the suggested rect), and rust-windowing#4694 (open) does the same for live drags. The 2026-10-02 branch still has the old code.

Fix

While the window is in a live move/resize (MARKER_IN_SIZE_MOVE), use the rect suggested by WM_DPICHANGED as is. Outside a drag, the existing conservative rect and monitor nudge are unchanged. One file, 9 lines added and 5 removed.

Test

  • Manual: an iced 0.15-dev application (OpenCADStudio) on Windows 11, two monitors with different scale factors. Before: the window bounced between the monitors and grew while dragged. After: it moves to the other monitor and stays there at one logical size. That run used this change on 05b8ff17 (the rev iced 0.15-dev pinned until recently); this branch has the same change on 2026-10-02.
  • cargo check and cargo clippy on x86_64-pc-windows-msvc: clean (the first version used a late-initialised let, which clippy rejects; this one is a let … = if … else …).

While the window is in a live move, apply the rect suggested by
WM_DPICHANGED instead of the conservative rect. The conservative rect
can land back on the monitor being left, which sends another
WM_DPICHANGED and grows the window on every crossing.

Same approach as rust-windowing#4341 (merged) and rust-windowing#4694.

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

Copy link
Copy Markdown
Author

Friendly ping: a second user has hit this downstream in OpenCADStudio (HakanSeven12/OpenCADStudio#2858, after rust-windowing#2363). The window gets stuck or bounces when dragged between a high-DPI laptop panel and a 1080p external monitor on Windows. The app is waiting for this fix to land here before it moves its winit pin. Happy to rebase or change anything that would make this easier to review.

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