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

- 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.
This commit is contained in:
Mohamed
2026-04-09 14:00:50 +02:00
parent c85fb7a05a
commit 0c5fa40c1f
+12 -7
View File
@@ -165,9 +165,16 @@ function getScreen() {
return nodeRequire("electron").screen as typeof import("electron").screen;
}
function getHudOverlayDisplay() {
const hudWindow = getHudOverlayWindow();
if (hudWindow) {
return getScreen().getDisplayMatching(hudWindow.getBounds());
}
return getScreen().getPrimaryDisplay();
}
function getHudOverlayBounds(expanded: boolean) {
const primaryDisplay = getScreen().getPrimaryDisplay();
const { bounds, workArea } = primaryDisplay;
const { bounds, workArea } = getHudOverlayDisplay();
const maxWindowWidth = Math.max(HUD_MIN_WINDOW_WIDTH, workArea.width - HUD_EDGE_MARGIN_DIP * 2);
const windowWidth = Math.min(
maxWindowWidth,
@@ -318,10 +325,9 @@ ipcMain.on("set-hud-overlay-compact-width", (_event, width: number) => {
return;
}
const primaryDisplay = getScreen().getPrimaryDisplay();
const maxWindowWidth = Math.max(
HUD_MIN_WINDOW_WIDTH,
primaryDisplay.workArea.width - HUD_EDGE_MARGIN_DIP * 2,
getHudOverlayDisplay().workArea.width - HUD_EDGE_MARGIN_DIP * 2,
);
const nextWidth = Math.min(maxWindowWidth, Math.max(HUD_MIN_WINDOW_WIDTH, Math.round(width)));
@@ -338,10 +344,9 @@ ipcMain.on("set-hud-overlay-measured-height", (_event, height: number, expanded:
return;
}
const primaryDisplay = getScreen().getPrimaryDisplay();
const maxWindowHeight = Math.max(
HUD_COMPACT_HEIGHT,
primaryDisplay.workArea.height - HUD_EDGE_MARGIN_DIP * 2,
getHudOverlayDisplay().workArea.height - HUD_EDGE_MARGIN_DIP * 2,
);
const nextHeight = Math.min(maxWindowHeight, Math.max(HUD_COMPACT_HEIGHT, Math.round(height)));
@@ -399,7 +404,7 @@ export function createHudOverlayWindow(): BrowserWindow {
minHeight: HUD_COMPACT_HEIGHT,
maxHeight: Math.max(
HUD_COMPACT_HEIGHT,
getScreen().getPrimaryDisplay().workArea.height - HUD_EDGE_MARGIN_DIP * 2,
getHudOverlayDisplay().workArea.height - HUD_EDGE_MARGIN_DIP * 2,
),
x: initialBounds.x,
y: initialBounds.y,