Skip to content
Merged
Show file tree
Hide file tree
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
70 changes: 66 additions & 4 deletions src/service-override/host.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,75 @@
import { mainWindow } from 'vs/base/browser/window'
import type { IEditorOverrideServices } from 'vs/editor/standalone/browser/standaloneServices'
import { IConfigurationService } from 'vs/platform/configuration/common/configuration.service'
import { IDialogService } from 'vs/platform/dialogs/common/dialogs.service'
import { IFileService } from 'vs/platform/files/common/files.service'
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'
import { IHostService } from 'vs/workbench/services/host/browser/host.service'
import { IHostColorSchemeService } from 'vs/workbench/services/themes/common/hostColorSchemeService.service'
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'
import { ILabelService } from 'vs/platform/label/common/label.service'
import { ILayoutService } from 'vs/platform/layout/browser/layoutService.service'
import { ILogService } from 'vs/platform/log/common/log.service'
import { IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile.service'
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace.service'
import { IBrowserWorkbenchEnvironmentService } from 'vs/workbench/services/environment/browser/environmentService.service'
import { BrowserHostService } from 'vs/workbench/services/host/browser/browserHostService'
import { IHostService } from 'vs/workbench/services/host/browser/host.service'
import type { BrowserLifecycleService } from 'vs/workbench/services/lifecycle/browser/lifecycleService'
import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecycle.service'
import { BrowserHostColorSchemeService } from 'vs/workbench/services/themes/browser/browserHostColorSchemeService'
import { IHostColorSchemeService } from 'vs/workbench/services/themes/common/hostColorSchemeService.service'

class CustomBrowserHostService extends BrowserHostService {
constructor(
private _toggleFullScreen: () => Promise<void> | undefined,
@ILayoutService layoutService: ILayoutService,
@IConfigurationService configurationService: IConfigurationService,
@IFileService fileService: IFileService,
@ILabelService labelService: ILabelService,
@IBrowserWorkbenchEnvironmentService environmentService: IBrowserWorkbenchEnvironmentService,
@IInstantiationService instantiationService: IInstantiationService,
@ILifecycleService lifecycleService: BrowserLifecycleService,
@ILogService logService: ILogService,
@IDialogService dialogService: IDialogService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IUserDataProfilesService userDataProfilesService: IUserDataProfilesService
) {
super(
layoutService,
configurationService,
fileService,
labelService,
environmentService,
instantiationService,
lifecycleService,
logService,
dialogService,
contextService,
userDataProfilesService
)
}

export default function getServiceOverride(): IEditorOverrideServices {
override async toggleFullScreen(targetWindow: Window): Promise<void> {
if (this._toggleFullScreen != null && targetWindow === mainWindow) {
await this._toggleFullScreen()
} else {
await super.toggleFullScreen(targetWindow)
}
}
}

interface BrowserHostServiceOverrideParams {
toggleFullScreen?: () => Promise<void>
}

export default function getServiceOverride({
toggleFullScreen
}: BrowserHostServiceOverrideParams = {}): IEditorOverrideServices {
return {
[IHostService.toString()]: new SyncDescriptor(BrowserHostService, [], true),
[IHostService.toString()]: new SyncDescriptor(
CustomBrowserHostService,
[toggleFullScreen],
true
),
[IHostColorSchemeService.toString()]: new SyncDescriptor(
BrowserHostColorSchemeService,
[],
Expand Down
4 changes: 2 additions & 2 deletions src/service-override/workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ class CustomWorkbench extends Workbench {
}
}

const detectedFullScreen = detectFullscreen(mainWindow)
setFullscreen(detectedFullScreen != null && !detectedFullScreen.guess, mainWindow)
onLayout(async (accessor) => {
;(accessor.get(IWorkbenchLayoutService) as Workbench).startup()
const detectedFullScreen = detectFullscreen(mainWindow, getWorkbenchContainer())
setFullscreen(detectedFullScreen != null && !detectedFullScreen.guess, mainWindow)
})
onRenderWorkbench(async (accessor) => {
accessor.get(IInstantiationService).createInstance(BrowserWindow)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Gaspar Chefdeville <gaspar.chefdeville@coderpad.io>
Date: Wed, 9 Jul 2025 17:25:14 +0200
Subject: [PATCH] feat: prevent IDE from entering fullscreen if not occupying
the entire screen

---
src/vs/base/browser/dom.ts | 12 ++++++++----
src/vs/workbench/browser/web.main.ts | 2 +-
.../services/host/browser/browserHostService.ts | 4 +-
3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/vs/base/browser/dom.ts b/src/vs/base/browser/dom.ts
index 49549236908..af89a7f1e46 100644
--- a/src/vs/base/browser/dom.ts
+++ b/src/vs/base/browser/dom.ts
@@ -1626,10 +1626,12 @@ export interface IDetectedFullscreen {
guess: boolean;
}

-export function detectFullscreen(targetWindow: Window): IDetectedFullscreen | null {
+export function detectFullscreen(targetWindow: Window, containerElement: Element): IDetectedFullscreen | null {

// Browser fullscreen: use DOM APIs to detect
- if (targetWindow.document.fullscreenElement || (<any>targetWindow.document).webkitFullscreenElement || (<any>targetWindow.document).webkitIsFullScreen) {
+ const fullscreenElement: Element | undefined =
+ targetWindow.document.fullscreenElement ?? (<any>targetWindow.document).webkitFullscreenElement ?? (<any>targetWindow.document).webkitIsFullScreen;
+ if (fullscreenElement === containerElement) {
return { mode: DetectedFullscreenMode.DOCUMENT, guess: false };
}

@@ -1638,7 +1640,9 @@ export function detectFullscreen(targetWindow: Window): IDetectedFullscreen | nu
// height and comparing that to window height, we can guess
// it though.

- if (targetWindow.innerHeight === targetWindow.screen.height) {
+ const isContainerFullScreen = containerElement.getBoundingClientRect().height >= targetWindow.screen.height;
+
+ if (targetWindow.innerHeight === targetWindow.screen.height && isContainerFullScreen) {
// if the height of the window matches the screen height, we can
// safely assume that the browser is fullscreen because no browser
// chrome is taking height away (e.g. like toolbars).
@@ -1647,7 +1651,7 @@ export function detectFullscreen(targetWindow: Window): IDetectedFullscreen | nu

if (platform.isMacintosh || platform.isLinux) {
// macOS and Linux do not properly report `innerHeight`, only Windows does
- if (targetWindow.outerHeight === targetWindow.screen.height && targetWindow.outerWidth === targetWindow.screen.width) {
+ if (targetWindow.outerHeight === targetWindow.screen.height && targetWindow.outerWidth === targetWindow.screen.width && isContainerFullScreen) {
// if the height of the browser matches the screen height, we can
// only guess that we are in fullscreen. It is also possible that
// the user has turned off taskbars in the OS and the browser is
diff --git a/src/vs/workbench/browser/web.main.ts b/src/vs/workbench/browser/web.main.ts
index 8aec734eb49..98b40d6603f 100644
--- a/src/vs/workbench/browser/web.main.ts
+++ b/src/vs/workbench/browser/web.main.ts
@@ -113,7 +113,7 @@ export class BrowserMain extends Disposable {
private init(): void {

// Browser config
- setFullscreen(!!detectFullscreen(mainWindow), mainWindow);
+ setFullscreen(!!detectFullscreen(mainWindow, this.domElement), mainWindow);
}

async open(): Promise<IWorkbench> {
diff --git a/src/vs/workbench/services/host/browser/browserHostService.ts b/src/vs/workbench/services/host/browser/browserHostService.ts
index 6f62f49b906..6e41a554052 100644
--- a/src/vs/workbench/services/host/browser/browserHostService.ts
+++ b/src/vs/workbench/services/host/browser/browserHostService.ts
@@ -218,7 +218,7 @@ export class BrowserHostService extends Disposable implements IHostService {
const viewport = isIOS && window.visualViewport ? window.visualViewport /** Visual viewport */ : window /** Layout viewport */;

const isFullScreen = () => {
- const fullScreen = detectFullscreen(window);
+ const fullScreen = detectFullscreen(window, this.layoutService.getContainer(window));
return fullScreen !== null && !fullScreen.guess;
};