diff --git a/src/vs/code/electron-main/window.ts b/src/vs/code/electron-main/window.ts index 66e312d92de15a9f3d142fb7fde8da6db350b6d8..b0a839d5b9d65b598a8eabf8816caed38eb24e57 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; } }