Skip to content

fix(hud): resolve overlay snap to primary on multi-monitor#207

Merged
webadderall merged 1 commit intowebadderall:mainfrom
MohamedV0:fix/multi-monitor-hud-position
Apr 9, 2026
Merged

fix(hud): resolve overlay snap to primary on multi-monitor#207
webadderall merged 1 commit intowebadderall:mainfrom
MohamedV0:fix/multi-monitor-hud-position

Conversation

@MohamedV0
Copy link
Copy Markdown
Contributor

@MohamedV0 MohamedV0 commented Apr 9, 2026

Summary

Fix the HUD overlay snapping to the primary monitor when recording
starts on a multi-monitor setup. The positioning logic now detects
which display the HUD is on using screen.getDisplayMatching()
instead of always defaulting to getPrimaryDisplay().

Context / Motivation

  • On multi-monitor setups, users position the HUD on the external
    monitor (typically the screen being recorded)
  • Clicking Record triggers a React re-render that swaps idle controls
    for recording controls, firing the ResizeObserver
  • The ResizeObserver sends set-hud-overlay-compact-width and
    set-hud-overlay-measured-height IPC messages to the main process
  • These handlers call applyHudOverlayBounds(), which computes x,y
    from the primary display's workArea — always re-centering on
    primary regardless of where the user placed the HUD
  • The fix follows the same getDisplayMatching() pattern already
    used by getUpdateToastBounds() in this file

Changes

  • [windows] Add getHudOverlayDisplay() helper that uses
    getDisplayMatching(hudWindow.getBounds()) with fallback to
    getPrimaryDisplay() when the window doesn't exist yet
  • [windows] Replace getPrimaryDisplay() in getHudOverlayBounds()
  • [windows] Replace getPrimaryDisplay() in
    set-hud-overlay-compact-width IPC handler
  • [windows] Replace getPrimaryDisplay() in
    set-hud-overlay-measured-height IPC handler
  • [windows] Replace getPrimaryDisplay() in
    createHudOverlayWindow() maxHeight constraint

Testing

  • Manual testing on Windows 11 Pro dual-monitor setup
  • Verified HUD stays on external monitor through recording
    start/stop cycle
  • Verified dropdown expand/collapse on external monitor
  • Verified single-monitor — zero behavior change
  • Automated tests (N/A — Electron window positioning)

Manual test — Windows 11 Pro (Build 26200):

  1. Built with npx vite build && npx electron-builder --win --dir
  2. Moved HUD to external monitor (positioned left of primary)
  3. Clicked Record — HUD stayed on external after countdown
  4. Opened/closed dropdowns — HUD stayed on external
  5. Stopped recording — HUD collapsed on external correctly
  6. Diagnostic logging confirmed getDisplayMatching() returned
    the correct display throughout the entire cycle

Single monitor: getDisplayMatching() with one display
always returns that display — identical to getPrimaryDisplay().
No behavioral change.

Cross-platform: screen.getDisplayMatching() is a core Electron
API on Windows, macOS, and Linux. No platform-specific code added.

Risks & Impact

  • No breaking changes
  • No renderer or IPC protocol changes
  • Single-monitor setups: zero behavioral difference
  • getDisplayMatching() returns the display with largest overlap —
    same behavior as Electron's own transparent window positioning

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved HUD overlay positioning and sizing for multi-display setups. The HUD now correctly identifies which display it's on and adjusts layout accordingly, rather than always defaulting to the primary display, ensuring proper alignment and dimensions when using multiple monitors.

- Add getHudOverlayDisplay() helper using getDisplayMatching()
  to detect which display the HUD is currently on
- Replace getPrimaryDisplay() in getHudOverlayBounds(),
  set-hud-overlay-compact-width, set-hud-overlay-measured-height
  handlers, and createHudOverlayWindow() maxHeight constraint
- Falls back to primary display when HUD window doesn't exist

Tested on Windows 11 with dual-monitor setup. HUD stays on
the external monitor through recording start/stop and
expand/collapse cycles.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

Warning

.coderabbit.yaml has a parsing error

The CodeRabbit configuration file in this repository has a parsing error and default settings were used instead. Please fix the error(s) in the configuration file. You can initialize chat with CodeRabbit to get help with the configuration file.

💥 Parsing errors (1)
Validation error: Invalid regex pattern for base branch. Received: "*" at "reviews.auto_review.base_branches[0]"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 49e50356-dc29-4e40-bcc8-c8d0baeb03fe

📥 Commits

Reviewing files that changed from the base of the PR and between 6703e6f and 0c5fa40.

📒 Files selected for processing (1)
  • electron/windows.ts

📝 Walkthrough

Walkthrough

The PR introduces getHudOverlayDisplay() to intelligently select the appropriate display for HUD layout calculations. When an HUD overlay window exists, the function uses the display matching the HUD's current bounds; otherwise, it falls back to the primary display. This selection logic is then applied across HUD positioning, sizing, and clamping operations.

Changes

Cohort / File(s) Summary
HUD Display Selection & Sizing
electron/windows.ts
Added getHudOverlayDisplay() function for intelligent display selection. Updated getHudOverlayBounds(), IPC handlers set-hud-overlay-compact-width and set-hud-overlay-measured-height, and createHudOverlayWindow() to use the selected display's bounds/workArea instead of always referencing the primary display.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Fix Linux HUD input handling #157: Modifies createHudOverlayWindow() in the same file to adjust HUD mouse passthrough behavior, alongside the display selection changes in this PR.

Suggested labels

Checked

Poem

🐰 A HUD so smart, no longer tied,
To primary display's stubborn pride,
Now finds the screen where it should be,
Multi-monitor harmony! 🖥️✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing HUD overlay snapping to primary monitor on multi-monitor setups.
Description check ✅ Passed The PR description includes all key sections from the template: summary, motivation/context, detailed changes, comprehensive testing (including manual verification on dual-monitor setup), and risk assessment.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

@webadderall webadderall merged commit 433173e into webadderall:main Apr 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants