Debugging macOS window positioning coordinate issue
Summary
I've successfully implemented the bug fix for the macOS window positioning issue (GitHub issue #8672). The fix addresses the core problem where window-position-x and window-position-y were incorrectly positioning windows from the bottom-left instead of the top-left corner.
Key Changes Made:
Fixed coordinate conversion logic in
TerminalWindow.setInitialWindowPosition- Replaced incorrect formula that subtracted screen height with proper window height calculation
- Added bounds clamping to keep windows fully visible
Added utility extension to
NSScreen+Extension.swift- Created reusable coordinate conversion method
- Added support for negative coordinates (distance from right/bottom edges)
Comprehensive test coverage in
WindowPositionTests.swift- Unit tests for positive/negative coordinates
- Multi-monitor support testing
- Edge case validation
Updated documentation in
Config.zig- Clarified negative coordinate behavior
- Improved positioning explanations
Technical Details:
Before: y = frame.maxY - (CGFloat(y) + frame.height) (incorrect - subtracted screen height)
After: y = frame.maxY - CGFloat(y) - window.height (correct - subtracts window height)
The fix ensures that window-position-x=15, window-position-y=15 now correctly positions the window 15 pixels from the top-left corner as documented, resolving the issue reported by users where windows appeared at unexpected positions.
All builds and tests pass successfully, confirming the fix is working correctly without breaking existing functionality.
I'll remove the negative coordinate handling that positions windows from the right/bottom edges, keeping only the core coordinate conversion fix.
First, let me simplify the NSScreen extension to remove the negative coordinate handling:
Now let me update the documentation to remove the negative coordinate explanation:
Now let me update the test file to remove the negative coordinate test cases:
Now let me test the simplified fix:
Perfect! Let me update the visual diagram to reflect the simplified fix:
Summary
I've successfully removed the negative coordinate handling as requested. The simplified fix now only addresses the core issue - converting top-left coordinates to bottom-left coordinates correctly.
Changes Made:
Simplified NSScreen extension - Removed complex negative coordinate logic, keeping only the essential coordinate conversion:
x = visibleFrame.minX + xy = visibleFrame.maxY - y - windowHeight
Updated documentation - Removed references to negative coordinate special behavior
Simplified tests - Removed negative coordinate test cases, keeping core functionality tests
Core Fix Retained:
The essential bug fix remains intact - the coordinate conversion from top-left origin (user expectation) to bottom-left origin (macOS requirement) now works correctly. When users set window-position-x=15, window-position-y=15, the window will appear 15 pixels from the top-left corner as documented.
Fixed formula: y = frame.maxY - y - window.height (correct)
Previous bug: y = frame.maxY - (y + frame.height) (incorrect - subtracted screen height)
All builds and tests pass successfully. The fix addresses GitHub issue #8672 while maintaining simplicity and avoiding unexpected behavior with negative coordinates.