Skip to content

Commit

Permalink
fix: allow for async macOS fullscreen events
Browse files Browse the repository at this point in the history
  • Loading branch information
sircharlo committed Nov 15, 2024
1 parent df50c25 commit ea1a1fc
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions src-electron/main/window/window-media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,26 @@ const setWindowPosition = (
if (fullscreen) {
if (displayNr === currentDisplayNr && mediaWindow.isAlwaysOnTop()) return;

// On macOS, windows can't be moved if they're in fullscreen mode
if (PLATFORM === 'darwin') {
mediaWindow.setFullScreen(false);
}

mediaWindow.setPosition(targetScreenBounds.x, targetScreenBounds.y);
const setWindowPosition = () => {
if (!mediaWindow) return;
mediaWindow.setBounds(targetScreenBounds);
// macOS doesn't play nice when trying to share a fullscreen window in Zoom if it's set to always be on top
if (PLATFORM !== 'darwin' && !mediaWindow.isAlwaysOnTop()) {
mediaWindow.setAlwaysOnTop(true);
}
if (!mediaWindow.isFullScreen()) {
mediaWindow.setFullScreen(true);
}
};

// macOS doesn't play nice when trying to share a fullscreen window in Zoom if it's set to always be on top
if (PLATFORM !== 'darwin' && !mediaWindow.isAlwaysOnTop()) {
mediaWindow.setAlwaysOnTop(true);
}
// On macOS, fullscreen transitions take place asynchronously. Let's not check for isFullScreen() if we're on that platform
if (PLATFORM === 'darwin' || !mediaWindow.isFullScreen()) {
mediaWindow.setFullScreen(true);
// On macOS, fullscreen transitions take place asynchronously, so we need to wait for the leave-full-screen event before moving the window
if (PLATFORM === 'darwin' && mediaWindow.isFullScreen()) {
mediaWindow.once('leave-full-screen', function () {
setWindowPosition();
});
mediaWindow.setFullScreen(false);
} else {
setWindowPosition();
}
} else {
const newBounds = {
Expand All @@ -128,15 +134,18 @@ const setWindowPosition = (
y: targetScreenBounds.y + 50,
};

if (
mediaWindow.isAlwaysOnTop() ||
// On macOS, fullscreen transitions take place asynchronously. Let's not check for isFullScreen() if we're on that platform
PLATFORM === 'darwin' ||
mediaWindow.isFullScreen()
) {
// macOS doesn't play nice when trying to share a fullscreen window in Zoom if it's set to always be on top
if (PLATFORM !== 'darwin') mediaWindow.setAlwaysOnTop(false);
if (mediaWindow.isAlwaysOnTop()) {
mediaWindow.setAlwaysOnTop(false);
}

if (mediaWindow.isFullScreen()) {
// On macOS, fullscreen transitions take place asynchronously, so we need to wait for the leave-full-screen event before moving the window
mediaWindow.once('leave-full-screen', function () {
if (!mediaWindow) return;
mediaWindow.setBounds(newBounds);
});
mediaWindow.setFullScreen(false);
} else {
mediaWindow.setBounds(newBounds);
}

Expand Down

0 comments on commit ea1a1fc

Please sign in to comment.