Skip to content

Commit 756a503

Browse files
authored
Merge pull request #654 from CodinGame/gce/fix-fullscreen-body
[FIX] prevent IDE from entering fullscreen if fullscreen is requested on body
2 parents d59816f + 8ada77a commit 756a503

3 files changed

Lines changed: 144 additions & 6 deletions

File tree

src/service-override/host.ts

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,75 @@
1+
import { mainWindow } from 'vs/base/browser/window'
12
import type { IEditorOverrideServices } from 'vs/editor/standalone/browser/standaloneServices'
3+
import { IConfigurationService } from 'vs/platform/configuration/common/configuration.service'
4+
import { IDialogService } from 'vs/platform/dialogs/common/dialogs.service'
5+
import { IFileService } from 'vs/platform/files/common/files.service'
26
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'
3-
import { IHostService } from 'vs/workbench/services/host/browser/host.service'
4-
import { IHostColorSchemeService } from 'vs/workbench/services/themes/common/hostColorSchemeService.service'
7+
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'
8+
import { ILabelService } from 'vs/platform/label/common/label.service'
9+
import { ILayoutService } from 'vs/platform/layout/browser/layoutService.service'
10+
import { ILogService } from 'vs/platform/log/common/log.service'
11+
import { IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile.service'
12+
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace.service'
13+
import { IBrowserWorkbenchEnvironmentService } from 'vs/workbench/services/environment/browser/environmentService.service'
514
import { BrowserHostService } from 'vs/workbench/services/host/browser/browserHostService'
15+
import { IHostService } from 'vs/workbench/services/host/browser/host.service'
16+
import type { BrowserLifecycleService } from 'vs/workbench/services/lifecycle/browser/lifecycleService'
17+
import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecycle.service'
618
import { BrowserHostColorSchemeService } from 'vs/workbench/services/themes/browser/browserHostColorSchemeService'
19+
import { IHostColorSchemeService } from 'vs/workbench/services/themes/common/hostColorSchemeService.service'
20+
21+
class CustomBrowserHostService extends BrowserHostService {
22+
constructor(
23+
private _toggleFullScreen: () => Promise<void> | undefined,
24+
@ILayoutService layoutService: ILayoutService,
25+
@IConfigurationService configurationService: IConfigurationService,
26+
@IFileService fileService: IFileService,
27+
@ILabelService labelService: ILabelService,
28+
@IBrowserWorkbenchEnvironmentService environmentService: IBrowserWorkbenchEnvironmentService,
29+
@IInstantiationService instantiationService: IInstantiationService,
30+
@ILifecycleService lifecycleService: BrowserLifecycleService,
31+
@ILogService logService: ILogService,
32+
@IDialogService dialogService: IDialogService,
33+
@IWorkspaceContextService contextService: IWorkspaceContextService,
34+
@IUserDataProfilesService userDataProfilesService: IUserDataProfilesService
35+
) {
36+
super(
37+
layoutService,
38+
configurationService,
39+
fileService,
40+
labelService,
41+
environmentService,
42+
instantiationService,
43+
lifecycleService,
44+
logService,
45+
dialogService,
46+
contextService,
47+
userDataProfilesService
48+
)
49+
}
750

8-
export default function getServiceOverride(): IEditorOverrideServices {
51+
override async toggleFullScreen(targetWindow: Window): Promise<void> {
52+
if (this._toggleFullScreen != null && targetWindow === mainWindow) {
53+
await this._toggleFullScreen()
54+
} else {
55+
await super.toggleFullScreen(targetWindow)
56+
}
57+
}
58+
}
59+
60+
interface BrowserHostServiceOverrideParams {
61+
toggleFullScreen?: () => Promise<void>
62+
}
63+
64+
export default function getServiceOverride({
65+
toggleFullScreen
66+
}: BrowserHostServiceOverrideParams = {}): IEditorOverrideServices {
967
return {
10-
[IHostService.toString()]: new SyncDescriptor(BrowserHostService, [], true),
68+
[IHostService.toString()]: new SyncDescriptor(
69+
CustomBrowserHostService,
70+
[toggleFullScreen],
71+
true
72+
),
1173
[IHostColorSchemeService.toString()]: new SyncDescriptor(
1274
BrowserHostColorSchemeService,
1375
[],

src/service-override/workbench.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ class CustomWorkbench extends Workbench {
5959
}
6060
}
6161

62-
const detectedFullScreen = detectFullscreen(mainWindow)
63-
setFullscreen(detectedFullScreen != null && !detectedFullScreen.guess, mainWindow)
6462
onLayout(async (accessor) => {
6563
;(accessor.get(IWorkbenchLayoutService) as Workbench).startup()
64+
const detectedFullScreen = detectFullscreen(mainWindow, getWorkbenchContainer())
65+
setFullscreen(detectedFullScreen != null && !detectedFullScreen.guess, mainWindow)
6666
})
6767
onRenderWorkbench(async (accessor) => {
6868
accessor.get(IInstantiationService).createInstance(BrowserWindow)
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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, 10 insertions(+), 6 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+
};

0 commit comments

Comments
 (0)