Skip to content

remember last cursor position per monitor on focus switch - #6

Open
zzJinux wants to merge 1 commit into
jnsahaj:mainfrom
zzJinux:remember-cursor-position
Open

zzJinux wants to merge 1 commit into
jnsahaj:mainfrom
zzJinux:remember-cursor-position

Conversation

@zzJinux

@zzJinux zzJinux commented Mar 30, 2026

Copy link
Copy Markdown

Save cursor position before warping to a new monitor and restore it
when switching back, instead of always warping to center.

Summary by CodeRabbit

  • Improvements
    • Monitor switching now intelligently preserves cursor position across display transitions, automatically restoring your cursor to its previous location when refocusing on monitors for a more seamless multi-display experience.

@coderabbitai

coderabbitai Bot commented Mar 30, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 85c03ace-77e1-4f55-b0ad-855a3ee9f3d9

📥 Commits

Reviewing files that changed from the base of the PR and between bd99667 and 91aebbc.

📒 Files selected for processing (2)
  • Sources/MonitorManager.swift
  • Sources/main.swift

📝 Walkthrough

Walkthrough

The changes implement cursor position restoration during monitor focus transitions. The focusMonitor function now accepts an optional restorePoint parameter, and the main tracking loop captures and stores the cursor position per monitor ID, then passes the stored position when switching focus.

Changes

Cohort / File(s) Summary
Monitor Focus Controller
Sources/MonitorManager.swift
Added restorePoint: CGPoint? parameter to focusMonitor function. Target point for mouse warping now conditionally uses restorePoint if provided and within bounds, otherwise falls back to display center. Debug logging and click positioning updated to reference targetPoint instead of center.
Cursor Position Tracking
Sources/main.swift
Tracking loop now maintains lastCursorPosition dictionary keyed by monitor ID. Captures current cursor location before monitor-focus transitions and passes the stored position as restorePoint argument to focusMonitor.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A rabbit hops from screen to screen,
But always remembers where they've been,
With whisker-precise coordinate care,
The cursor knows exactly where—
No whiskers lost, just homeward bound! 🖱️

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly summarizes the main change: adding per-monitor cursor position tracking for restoration on monitor focus switches, which is the core objective of the PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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