From 230f677e24b8f98ecfcf0319ff7ae3d24b2206be Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Mon, 16 Dec 2019 18:36:30 +0100 Subject: [PATCH] window - more changes to ensure window is not out of display bounds (#86771) --- src/vs/code/electron-main/window.ts | 35 ++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/vs/code/electron-main/window.ts b/src/vs/code/electron-main/window.ts index 66e312d92de..b0a839d5b9d 100644 --- a/src/vs/code/electron-main/window.ts +++ b/src/vs/code/electron-main/window.ts @@ -795,33 +795,48 @@ export class CodeWindow extends Disposable implements ICodeWindow { } // Single Monitor: be strict about x/y positioning + // macOS & Linux: these OS seem to be pretty good in ensuring that a window is never outside of it's bounds. + // Windows: it is possible to have a window with a size that makes it fall out of the window. our strategy + // is to try as much as possible to keep the window in the monitor bounds. we are not as strict as + // macOS and Linux and allow the window to exceed the monitor bounds as long as the window is still + // some pixels (128) visible on the screen for the user to drag it back. if (displays.length === 1) { const displayWorkingArea = this.getWorkingArea(displays[0]); if (displayWorkingArea) { this.logService.trace('window#validateWindowState: 1 monitor working area', displayWorkingArea); if (state.x < displayWorkingArea.x) { - state.x = displayWorkingArea.x; // prevent window from falling out of the screen to the left + // prevent window from falling out of the screen to the left + state.x = displayWorkingArea.x; } if (state.y < displayWorkingArea.y) { - state.y = displayWorkingArea.y; // prevent window from falling out of the screen to the top + // prevent window from falling out of the screen to the top + state.y = displayWorkingArea.y; } - if (state.x > (displayWorkingArea.x + displayWorkingArea.width)) { - state.x = displayWorkingArea.x; // prevent window from falling out of the screen to the right + if (state.width > displayWorkingArea.width) { + // prevent window from exceeding display bounds width + state.width = displayWorkingArea.width; } - if (state.y > (displayWorkingArea.y + displayWorkingArea.height)) { - state.y = displayWorkingArea.y; // prevent window from falling out of the screen to the bottom + if (state.height > displayWorkingArea.height) { + // prevent window from exceeding display bounds height + state.height = displayWorkingArea.height; } - if (state.width > displayWorkingArea.width) { - state.width = displayWorkingArea.width; // prevent window from exceeding display bounds width + if (state.x > (displayWorkingArea.x + displayWorkingArea.width - 128)) { + // prevent window from falling out of the screen to the right with + // 128px margin by positioning the window to the far right edge of + // the screen + state.x = displayWorkingArea.x + displayWorkingArea.width - state.width; } - if (state.height > displayWorkingArea.height) { - state.height = displayWorkingArea.height; // prevent window from exceeding display bounds height + if (state.y > (displayWorkingArea.y + displayWorkingArea.height - 128)) { + // prevent window from falling out of the screen to the bottom with + // 128px margin by positioning the window to the far bottom edge of + // the screen + state.y = displayWorkingArea.y + displayWorkingArea.height - state.height; } } -- GitLab