Skip to content

Commit

Permalink
fix: check if window is offscreen of the target screen and reset as n…
Browse files Browse the repository at this point in the history
…eeded
  • Loading branch information
sircharlo committed Nov 22, 2024
1 parent 11777f8 commit d0a5867
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src-electron/main/window/window-media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,25 @@ const mediaWindowIsFullScreen = (parentScreenBounds: Electron.Rectangle) =>
boundsAreSame(mediaWindow?.getBounds(), parentScreenBounds) ||
mediaWindow?.isFullScreen();

const mediaWindowIsOffscreen = (parentScreenBounds: Electron.Rectangle) => {
const mediaWindowBounds = mediaWindow?.getBounds();
if (!mediaWindowBounds) return true;

const visibleWidth =
Math.min(
mediaWindowBounds.x + mediaWindowBounds.width,
parentScreenBounds.x + parentScreenBounds.width,
) - Math.max(mediaWindowBounds.x, parentScreenBounds.x);

const visibleHeight =
Math.min(
mediaWindowBounds.y + mediaWindowBounds.height,
parentScreenBounds.y + parentScreenBounds.height,
) - Math.max(mediaWindowBounds.y, parentScreenBounds.y);

return visibleWidth <= 100 || visibleHeight <= 100;
};

export const moveMediaWindow = (
displayNr?: number,
fullscreen?: boolean,
Expand Down Expand Up @@ -175,7 +194,8 @@ const setWindowPosition = (
};
if (
displayNr !== currentDisplayNr ||
mediaWindowIsFullScreen(targetScreenBounds)
mediaWindowIsFullScreen(targetScreenBounds) ||
mediaWindowIsOffscreen(targetScreenBounds)
) {
handleMacFullScreenTransition(() => {
setWindowBounds(newBounds, false);
Expand Down

0 comments on commit d0a5867

Please sign in to comment.