Skip to content

feat(grabandmove): snap windows to screen edges and corners while dragging - #50245

Open
James Martin (jjamesmartiin) wants to merge 1 commit into
microsoft:mainfrom
jjamesmartiin:feat/win-click-edge-snap
Open

feat(grabandmove): snap windows to screen edges and corners while dragging#50245
James Martin (jjamesmartiin) wants to merge 1 commit into
microsoft:mainfrom
jjamesmartiin:feat/win-click-edge-snap

Conversation

@jjamesmartiin

@jjamesmartiin James Martin (jjamesmartiin) commented Aug 29, 2026

Copy link
Copy Markdown

Summary of the Pull Request

Adds release-to-edge window snapping to the GrabAndMove utility. When dragging windows using the modifier key (Alt/Win + Left Click), dragging near the left or right work-area edge previews and snaps the window to that screen half using direct window positioning. Dragging to a screen corner previews and snaps the window to that quarter, and dragging to the top work-area edge previews and maximizes the window.

PR Checklist

Detailed Description of the Pull Request / Additional comments

Technical Implementation Details:

  1. Edge Snapping Logic (src/modules/GrabAndMove/GrabAndMove/main.cpp):
    • Added ComputeSnapTarget() to calculate work-area boundaries (GetWorkAreaForPoint) and determine if the cursor is within SNAP_EDGE_THRESHOLD (24px) of an edge or corner. Corners are checked first so quadrants take priority over the half-screen/maximize edge zones.
    • When armed, the existing DWM overlay window (RepositionOverlay) expands to preview the half-screen, quarter-screen, or full-screen target region with zeroed margins.
    • On mouse release, if armed:
      • Half / Corner: Positions the dragged window directly via SetWindowPos() so its visible frame (DWM extended frame bounds) matches the previewed half/quarter region, accounting for the invisible resize borders.
      • Top Edge: Calls ShowWindow(g_dragTarget, SW_MAXIMIZE).
  2. Settings UI Integration:
    • Added SnapToEdges (snapToEdges bool property, default true) to GrabAndMoveProperties.cs.
    • Added ViewModel binding in GrabAndMoveViewModel.cs and UI toggle switch in GrabAndMovePage.xaml.
    • Updated Resources.resw (en-us).

Validation Steps Performed

  1. Standalone GrabAndMove Execution:
    • Executed PowerToys.GrabAndMove.exe with explorer PID runner parameter.
  2. Window Movement & Snapping:
    • Held Alt + left-click drag on target windows (e.g. Notepad, Edge, Command Prompt).
    • Dragged cursor to left work-area edge -> Gold preview overlay rendered on left half of monitor -> Released mouse -> Window snapped to left half.
    • Dragged cursor to right work-area edge -> Overlay rendered on right half -> Released mouse -> Window snapped to right half.
    • Dragged cursor to top work-area edge -> Overlay rendered on entire work area -> Released mouse -> Window maximized.
    • Dragged cursor to each screen corner -> Overlay rendered on that quarter -> Released mouse -> Window snapped to that quarter.
  3. Settings UI Validation:
    • Toggled "Snap windows to screen edges while dragging" off -> Dragging to edges showed standard window outline without triggering snap.
    • Toggled on -> Edge snap functionality restored.
  4. Regression Check:
    • Confirmed Alt + Right-Click window resize operations function normally without interference.

Video Demonstration

power-toys-grab-and-move-snapping-demo-10mb.mp4

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@github-actions github-actions Bot added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something Product-Grab And Move labels Aug 29, 2026
@github-actions

github-actions Bot commented Aug 29, 2026

Copy link
Copy Markdown

✅ PR intake

All automated intake checks now pass. Thanks for the updates!

Automated PR intake; PowerToys maintainers make final decisions.

@jjamesmartiin

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@microsoft-github-policy-service microsoft-github-policy-service Bot added Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams Needs-Team-Response An issue author responded so the team needs to follow up and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Aug 29, 2026
@jjamesmartiin

James Martin (jjamesmartiin) commented Aug 29, 2026

Copy link
Copy Markdown
Author

📷 Visual Evidence & UI Summary

As requested by the PR intake bot check, here is the visual breakdown for the UI additions in GrabAndMovePage.xaml:

1. Settings UI Integration (GrabAndMovePage.xaml & Resources.resw)

  • Toggle Switch: Added Snap windows to screen edges while dragging (SnapToEdges, default true).
  • Header: Snap windows to screen edges while dragging
  • Description: Release a dragged window near the left or right edge to snap it to that half, or near the top edge to maximize it
image

2. Edge Snapping Overlay Behavior

  • Left / Right Edge: Dragging within 16px of the left or right work-area edge displays the DWM target overlay across that half of the screen; releasing sends synthetic Win + Left / Win + Right to trigger native Aero Snap.
  • Top Edge: Dragging near the top work-area edge displays a full work-area overlay; releasing calls ShowWindow(..., SW_MAXIMIZE).

1/4 Snap

image

1/2 Snap

image

Full-screen

image

@github-actions github-actions Bot added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Aug 30, 2026
@jjamesmartiin
James Martin (jjamesmartiin) force-pushed the feat/win-click-edge-snap branch 2 times, most recently from 699a952 to d835ec5 Compare August 30, 2026 01:46
@jjamesmartiin

James Martin (jjamesmartiin) commented Aug 30, 2026

Copy link
Copy Markdown
Author

Hi! I've put together a short (~30 second) screen recording that walks through the snapping behavior end-to-end: the new Settings toggle, snapping to a half at the left/right edge, snapping to a quarter at the corners, and maximizing at the top edge. Please let me know if there's anything else you'd like me to include or if you have any feedback on the behavior or the settings wording — happy to make changes. Thanks for taking a look!

power-toys-grab-and-move-snapping-demo-10mb.mp4

@microsoft-github-policy-service microsoft-github-policy-service Bot removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Aug 30, 2026
@jjamesmartiin James Martin (jjamesmartiin) changed the title feat(grabandmove): snap windows to screen edges while dragging feat(grabandmove): snap windows to screen edges and corners while dragging Aug 30, 2026
…gging

Add release-to-edge-snap to GrabAndMove:
- Arm edge-snap when dragging near the left/right/top work-area edge or a
  screen corner
- Reuse the existing overlay to preview the target half/quarter/maximize region
- On release: position the window directly into the half/quarter region
  (accounting for DWM frame bounds), or maximize at the top edge
- Add snapToEdges setting (default on) with Settings UI toggle + localization
@jjamesmartiin

Copy link
Copy Markdown
Author

Quick note: I ran clang-format against main.cpp (per the repo's .clang-format) to make sure the new edge/corner snapping code matches the style guide. Purely formatting — no behavior changes — and Debug + Release builds are both clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs-Team-Response An issue author responded so the team needs to follow up Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams Product-Grab And Move Ready for review

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Easy Window Dragging & Resizing

2 participants