Skip to content

Use DwmGetWindowAttribute for Shell#getLocation to avoid shadow margins #2426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ShahzaibIbrahim
Copy link
Contributor

GetWindowRect returns the bounding rectangle of the entire window including invisible shadows and glass margins. This leads to Shell#getLocation reporting coordinates that do not match the actual visible frame location. For example, when positioning a dialog close to the left edge of a monitor, the reported X coordinate can be shifted by ~9 pixels compared to the visible window frame. The same discrepancy appears when opening dialogs under a maximized parent shell.

This patch changes Shell#getLocation to use:

DwmGetWindowAttribute(hwnd, DWMWA_EXTENDED_FRAME_BOUNDS, ...)

This API returns the extended frame bounds rectangle in screen space, which corresponds to the true visible window frame and excludes the transparent shadow margins. This produces values that align with what the user sees on screen and avoids subtle layout issues in multi-monitor or mixed-DPI setups.

If DWM is not available (e.g., on older Windows versions or when composition is disabled), the implementation falls back to GetWindowRect, preserving backward compatibility.

Benefits:

  • Correct window coordinates near monitor edges.
  • No more shadow-margin offset (~9px) in reported locations.
  • Consistent behavior across normal, minimized, and maximized shells.

Steps to Reproduce

  • Run the runtime workspace with monitor specific scaling turned on.
  • Move the window to secondary monitor on the right (could be of any zoom)
  • Resize the window to smaller size
  • Open the "Open Type" window using Ctrl + Shift + T
  • Move the Open Type window towards very left of the screen.
  • Close Open Type window
  • Maximize the size of main window.
  • Open the Open Type dialog again
  • You will see the dialog appearing on the left monitor instead of where it was last closed (on the right monitor)

Expected result

The sub-shell or dialog should open where it was last closed. There should be no shadow margins that leads to change of coordinates and resulting in window opening in the other monitor.

GetWindowRect includes invisible shadow borders on Windows 10/11,
causing
Shell#getLocation to return coordinates offset by ~9px from the visible
frame. Replaced with DwmGetWindowAttribute(DWMWA_EXTENDED_FRAME_BOUNDS)
to
report the true window bounds in screen space, with GetWindowRect as a
fallback if DWM is unavailable.
Copy link
Contributor

Test Results

   546 files  ±0     546 suites  ±0   29m 55s ⏱️ +59s
 4 425 tests ±0   4 408 ✅ ±0   17 💤 ±0  0 ❌ ±0 
16 746 runs  ±0  16 619 ✅ ±0  127 💤 ±0  0 ❌ ±0 

Results for commit 8a135d1. ± Comparison against base commit a641cdb.

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.

Improve Shell#getLocation OS calls
1 participant