Skip to content

Reintroduce screen-edge clamping for popup window#1364

Open
gabrielMalonso wants to merge 1 commit into
p0deje:masterfrom
gabrielMalonso:fix/reintroduce-screen-edge-clamp
Open

Reintroduce screen-edge clamping for popup window#1364
gabrielMalonso wants to merge 1 commit into
p0deje:masterfrom
gabrielMalonso:fix/reintroduce-screen-edge-clamp

Conversation

@gabrielMalonso
Copy link
Copy Markdown

Summary

The clamping logic introduced in #709 was lost during the popup system rewrite in July 2024 (commits 43f1ccf and cf6edca). This PR restores and improves it.

  • Problem: Opening Maccy near screen edges (especially the bottom) causes the popup to extend beyond the visible area
  • Fix: Add a clamp() function to PopupPosition that constrains the popup origin to the screen's visibleFrame, applied to all 5 positioning modes
  • Improvements over Adjust popup position to clamp window into current screen region #709:
    • Adapted for bottom-left origin (AppKit convention) — the original treated pos as top-left
    • Added left-edge check (missing from original)
    • .window mode detects the correct screen in multi-monitor setups
    • .statusItem now uses visibleFrame instead of frame (respects Dock placement)
    • Replaces the partial right-edge guard in .statusItem with full 4-edge clamping
    • Includes 9 unit tests for the clamp() function

Test plan

  • Unit tests pass (PopupPositionTests — 9 tests covering all edges, corners, multi-monitor, boundary conditions, and oversized popups)
  • Manual testing: open popup with cursor at bottom/right/left edges — popup stays fully visible
  • Manual testing: .statusItem near right edge of menu bar — no overflow
  • Build succeeds with zero new warnings

🤖 Generated with Claude Code

The clamping logic from PR p0deje#709 was lost during the popup system
rewrite in July 2024. This restores and improves it, ensuring the
popup window stays fully within the visible screen area.

Changes:
- Add clamp() to PopupPosition that constrains origin to screen bounds
- Apply clamping to all 5 positioning modes (cursor, center, window,
  statusItem, lastPosition)
- Replace partial right-edge guard in statusItem with full 4-edge clamp
- Use visibleFrame instead of frame for statusItem (excludes Dock)
- Detect correct screen for window mode in multi-monitor setups
- Add left-edge check missing from original PR p0deje#709
- Add unit tests for clamp function

Fixes the issue where opening Maccy near screen edges (especially
the bottom) causes the popup to extend beyond the visible area.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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