Skip to content

Fix window drag bounds - #414

Merged
AllTerrainDeveloper merged 2 commits into
WordPress:trunkfrom
CookieDarb:fix/window-drag-bounds
Jul 24, 2026
Merged

Fix window drag bounds#414
AllTerrainDeveloper merged 2 commits into
WordPress:trunkfrom
CookieDarb:fix/window-drag-bounds

Conversation

@CookieDarb

Copy link
Copy Markdown
Contributor

What?

Closes #404

Allows windows to be dragged partially off-screen without losing access to them, and smoothly recovers stranded windows during browser resizes.

Why?

This allows to replicate how macOS and Windows naturally handle desktop boundaries: allowing users to push large windows partially out of the way to clear visual space.

Previously, floating windows could be dragged completely off-screen and lost. A prior attempt to fix this (PR #406) strictly trapped windows inside the viewport, which felt a bit restrictive. Additionally, making the browser window smaller would leave floating windows completely stranded outside the visible desktop area with no way to retrieve them without refresh or making the browser window large.

How?

  • Revert: Reverted the strict boundary constraints introduced in PR Fix window dragging allowing windows to disappear off right/bottom edges #406, replacing them with a grab-margin based approach.
  • src/window/constants.ts:
    • Added a 40px GRAB_MARGIN constant to ensure a minimum clickable grab area is always maintained.
  • src/window/pointer.ts:
    • Introduced clampWindowPosition() to let windows bleed off the left, right, and bottom edges, stopping only when just 40px of the title bar remains visible. The top edge strictly locks at 0.
    • Updated handleDragStart() to enforce these new boundaries during drag moves.
  • src/window-manager/index.ts:
    • Updated reflowStatefulWindows() to include standard floating windows. If a browser resize leaves a window stranded off-screen, it smoothly pulls it back into the 40px grab area.
  • tests/vitest/drag-unstate.test.ts:
    • Added dedicated unit tests for the new clamping constraints and drag bounds.

Testing Instructions

  1. Open a standard floating window.
  2. Drag the window past the left, right, and bottom edges of the desktop. Verify it stops moving once only 40px of the title bar is left visible.
  3. Drag the window to the top edge and verify it strictly stops at the top boundary.
  4. Drag a window to the bottom-right corner, then shrink your browser window so the window is stranded outside the visible desktop area.
  5. Verify the window smoothly reflows back into view, stopping at the 40px grab margin limit.

Screencast

Before

Screen.Recording.2026-07-24.at.5.23.53.PM.mov

After

Screen.Recording.2026-07-24.at.5.31.39.PM.mov

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini and Claude
Used for: Reviewing the existing implementation and suggesting the changes. Final decisions and edits were made by me.

…rgins

- Define a 40px  constant to ensure a clickable title bar area is always accessible.
- Introduce  utility to prevent windows from being dragged completely off-screen, allowing them to bleed off the left, right, and bottom edges while strictly locking the top edge.
- Update  to use  for floating window movements within the desktop view.
- Refactor  in the window manager to smoothly recover and pull stranded off-screen windows back into bounds during browser viewport resizes.
- Add robust unit test coverage in  to verify clamping constraints and pointer move bounding logic.
@CookieDarb
CookieDarb marked this pull request as ready for review July 24, 2026 12:27

@AllTerrainDeveloper AllTerrainDeveloper left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WOAH! It feels amazing. It's very clean and clever! Thank you! ❤️

@AllTerrainDeveloper
AllTerrainDeveloper merged commit b07b694 into WordPress:trunk Jul 24, 2026
6 checks passed
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.

Window can be dragged out of bounds

2 participants