Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions electron/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)));

Expand All @@ -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)));

Expand Down Expand Up @@ -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,
Expand Down