|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Gaspar Chefdeville <gaspar.chefdeville@coderpad.io> |
| 3 | +Date: Wed, 9 Jul 2025 17:25:14 +0200 |
| 4 | +Subject: [PATCH] feat: prevent IDE from entering fullscreen if not occupying |
| 5 | + the entire screen |
| 6 | + |
| 7 | +--- |
| 8 | + src/vs/base/browser/dom.ts | 12 ++++++++---- |
| 9 | + src/vs/workbench/browser/web.main.ts | 2 +- |
| 10 | + .../services/host/browser/browserHostService.ts | 4 ++-- |
| 11 | + 3 files changed, 11 insertions(+), 7 deletions(-) |
| 12 | + |
| 13 | +diff --git a/src/vs/base/browser/dom.ts b/src/vs/base/browser/dom.ts |
| 14 | +index 49549236908..af89a7f1e46 100644 |
| 15 | +--- a/src/vs/base/browser/dom.ts |
| 16 | ++++ b/src/vs/base/browser/dom.ts |
| 17 | +@@ -1626,10 +1626,12 @@ export interface IDetectedFullscreen { |
| 18 | + guess: boolean; |
| 19 | + } |
| 20 | + |
| 21 | +-export function detectFullscreen(targetWindow: Window): IDetectedFullscreen | null { |
| 22 | ++export function detectFullscreen(targetWindow: Window, containerElement: Element): IDetectedFullscreen | null { |
| 23 | + |
| 24 | + // Browser fullscreen: use DOM APIs to detect |
| 25 | +- if (targetWindow.document.fullscreenElement || (<any>targetWindow.document).webkitFullscreenElement || (<any>targetWindow.document).webkitIsFullScreen) { |
| 26 | ++ const fullscreenElement: Element | undefined = |
| 27 | ++ targetWindow.document.fullscreenElement ?? (<any>targetWindow.document).webkitFullscreenElement ?? (<any>targetWindow.document).webkitIsFullScreen; |
| 28 | ++ if (fullscreenElement === containerElement) { |
| 29 | + return { mode: DetectedFullscreenMode.DOCUMENT, guess: false }; |
| 30 | + } |
| 31 | + |
| 32 | +@@ -1638,7 +1640,9 @@ export function detectFullscreen(targetWindow: Window): IDetectedFullscreen | nu |
| 33 | + // height and comparing that to window height, we can guess |
| 34 | + // it though. |
| 35 | + |
| 36 | +- if (targetWindow.innerHeight === targetWindow.screen.height) { |
| 37 | ++ const isContainerFullScreen = containerElement.getBoundingClientRect().height >= targetWindow.screen.height; |
| 38 | ++ |
| 39 | ++ if (targetWindow.innerHeight === targetWindow.screen.height && isContainerFullScreen) { |
| 40 | + // if the height of the window matches the screen height, we can |
| 41 | + // safely assume that the browser is fullscreen because no browser |
| 42 | + // chrome is taking height away (e.g. like toolbars). |
| 43 | +@@ -1647,7 +1651,7 @@ export function detectFullscreen(targetWindow: Window): IDetectedFullscreen | nu |
| 44 | + |
| 45 | + if (platform.isMacintosh || platform.isLinux) { |
| 46 | + // macOS and Linux do not properly report `innerHeight`, only Windows does |
| 47 | +- if (targetWindow.outerHeight === targetWindow.screen.height && targetWindow.outerWidth === targetWindow.screen.width) { |
| 48 | ++ if (targetWindow.outerHeight === targetWindow.screen.height && targetWindow.outerWidth === targetWindow.screen.width && isContainerFullScreen) { |
| 49 | + // if the height of the browser matches the screen height, we can |
| 50 | + // only guess that we are in fullscreen. It is also possible that |
| 51 | + // the user has turned off taskbars in the OS and the browser is |
| 52 | +diff --git a/src/vs/workbench/browser/web.main.ts b/src/vs/workbench/browser/web.main.ts |
| 53 | +index 8aec734eb49..98b40d6603f 100644 |
| 54 | +--- a/src/vs/workbench/browser/web.main.ts |
| 55 | ++++ b/src/vs/workbench/browser/web.main.ts |
| 56 | +@@ -113,7 +113,7 @@ export class BrowserMain extends Disposable { |
| 57 | + private init(): void { |
| 58 | + |
| 59 | + // Browser config |
| 60 | +- setFullscreen(!!detectFullscreen(mainWindow), mainWindow); |
| 61 | ++ setFullscreen(!!detectFullscreen(mainWindow, this.domElement), mainWindow); |
| 62 | + } |
| 63 | + |
| 64 | + async open(): Promise<IWorkbench> { |
| 65 | +diff --git a/src/vs/workbench/services/host/browser/browserHostService.ts b/src/vs/workbench/services/host/browser/browserHostService.ts |
| 66 | +index 6f62f49b906..6e41a554052 100644 |
| 67 | +--- a/src/vs/workbench/services/host/browser/browserHostService.ts |
| 68 | ++++ b/src/vs/workbench/services/host/browser/browserHostService.ts |
| 69 | +@@ -218,7 +218,7 @@ export class BrowserHostService extends Disposable implements IHostService { |
| 70 | + const viewport = isIOS && window.visualViewport ? window.visualViewport /** Visual viewport */ : window /** Layout viewport */; |
| 71 | + |
| 72 | + const isFullScreen = () => { |
| 73 | +- const fullScreen = detectFullscreen(window); |
| 74 | ++ const fullScreen = detectFullscreen(window, this.layoutService.getContainer(window)); |
| 75 | + return fullScreen !== null && !fullScreen.guess; |
| 76 | + }; |
| 77 | + |
| 78 | +@@ -523,7 +523,7 @@ export class BrowserHostService extends Disposable implements IHostService { |
| 79 | + } |
| 80 | + |
| 81 | + async toggleFullScreen(targetWindow: Window): Promise<void> { |
| 82 | +- const target = this.layoutService.getContainer(targetWindow); |
| 83 | ++ const target = targetWindow === mainWindow ? targetWindow.document.body : this.layoutService.getContainer(targetWindow); |
| 84 | + |
| 85 | + // Chromium |
| 86 | + if (targetWindow.document.fullscreen !== undefined) { |
0 commit comments