Skip to content

Fix window dragging allowing windows to disappear off right/bottom edges - #406

Merged
AllTerrainDeveloper merged 3 commits into
WordPress:trunkfrom
alshakerM:fix/window-drag-bounds-disappearing
Jul 23, 2026
Merged

Fix window dragging allowing windows to disappear off right/bottom edges#406
AllTerrainDeveloper merged 3 commits into
WordPress:trunkfrom
alshakerM:fix/window-drag-bounds-disappearing

Conversation

@alshakerM

@alshakerM alshakerM commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Follow up to issue #399 and PR: #402

Problem

When dragging windows, the constraint logic only checked the window's top-left position (x, y) against the desktop boundaries, but did not account for the window's width and height. This allowed windows to be dragged almost completely off-screen to the right and bottom edges, with only a thin sliver remaining visible.

The constraint checked:

  • x <= desktop.clientWidth - EDGE_MARGIN (doesn't account for window width)
  • y <= desktop.clientHeight - EDGE_MARGIN (doesn't account for window height)

Since EDGE_MARGIN = 0, a window could be dragged to x = desktop.clientWidth, positioning its left edge at the desktop's right boundary, effectively hiding the entire window off-screen to the right. Same issue applied to the bottom edge.

Solution

Updated the drag constraint logic in src/window/pointer.ts (lines 235-236) to account for window dimensions, mirroring the resize constraint logic that was added in #399:

Before:

Screen.Recording.2026-07-23.at.20.32.49.mov

x = Math.max(EDGE_MARGIN, Math.min(x, desktop.clientWidth - EDGE_MARGIN));
y = Math.max(EDGE_MARGIN, Math.min(y, desktop.clientHeight - EDGE_MARGIN));

After:

Screen.Recording.2026-07-23.at.20.29.45.mov

x = Math.max(EDGE_MARGIN, Math.min(x, desktop.clientWidth - win.element.offsetWidth - EDGE_MARGIN));
y = Math.max(EDGE_MARGIN, Math.min(y, desktop.clientHeight - win.element.offsetHeight - EDGE_MARGIN));
This ensures:

  • The window's right edge (x + width) cannot exceed desktop.clientWidth
  • The window's bottom edge (y + height) cannot exceed desktop.clientHeight
  • Windows remain fully visible and accessible during drag operations

Context

This is a follow-up fix to #399, which addressed the same issue for resize operations. The drag handler was using an older, simpler constraint that predated the resize fix and exhibited the same problem.

The constraint now consistently prevents windows from disappearing during both drag and resize operations, while still allowing flush-edge positioning for snap gestures (since EDGE_MARGIN = 0).

alshakerM and others added 3 commits July 23, 2026 20:24
## Problem

When dragging windows, the constraint logic only checked the window's
top-left position (x, y) against the desktop boundaries, but did not
account for the window's width and height. This allowed windows to be
dragged almost completely off-screen to the right and bottom edges,
with only a thin sliver remaining visible.

The constraint checked:
- x <= desktop.clientWidth - EDGE_MARGIN  (doesn't account for window width)
- y <= desktop.clientHeight - EDGE_MARGIN (doesn't account for window height)

Since EDGE_MARGIN = 0, a window could be dragged to x = desktop.clientWidth,
positioning its left edge at the desktop's right boundary, effectively
hiding the entire window off-screen to the right. Same issue applied to
the bottom edge.

## Solution

Updated the drag constraint logic in src/window/pointer.ts (lines 235-236)
to account for window dimensions, mirroring the resize constraint logic
that was added in WordPress#399:

Before:
  x = Math.max(EDGE_MARGIN, Math.min(x, desktop.clientWidth - EDGE_MARGIN));
  y = Math.max(EDGE_MARGIN, Math.min(y, desktop.clientHeight - EDGE_MARGIN));

After:
  x = Math.max(EDGE_MARGIN, Math.min(x, desktop.clientWidth - win.element.offsetWidth - EDGE_MARGIN));
  y = Math.max(EDGE_MARGIN, Math.min(y, desktop.clientHeight - win.element.offsetHeight - EDGE_MARGIN));

This ensures:
- The window's right edge (x + width) cannot exceed desktop.clientWidth
- The window's bottom edge (y + height) cannot exceed desktop.clientHeight
- Windows remain fully visible and accessible during drag operations

## Context

This is a follow-up fix to WordPress#399, which addressed the same issue for
resize operations. The drag handler was using an older, simpler constraint
that predated the resize fix and exhibited the same problem.

The constraint now consistently prevents windows from disappearing during
both drag and resize operations, while still allowing flush-edge positioning
for snap gestures (since EDGE_MARGIN = 0).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@AllTerrainDeveloper
AllTerrainDeveloper merged commit 3222c61 into WordPress:trunk Jul 23, 2026
5 checks passed
AllTerrainDeveloper pushed a commit that referenced this pull request Jul 24, 2026
* Revert "Fix window dragging allowing windows to disappear off right/bottom edges (#406)"

This reverts commit 3222c61.

* fix(window): enforce drag boundaries and viewport reflow with grab margins

- 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.
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.

2 participants