mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 03:54:24 +01:00
window - more changes to ensure window is not out of display bounds (#86771)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
if (state.x > (displayWorkingArea.x + displayWorkingArea.width)) {
|
||||
state.x = displayWorkingArea.x; // prevent window from falling out of the screen to the right
|
||||
}
|
||||
|
||||
if (state.y > (displayWorkingArea.y + displayWorkingArea.height)) {
|
||||
state.y = displayWorkingArea.y; // prevent window from falling out of the screen to the bottom
|
||||
// prevent window from falling out of the screen to the top
|
||||
state.y = displayWorkingArea.y;
|
||||
}
|
||||
|
||||
if (state.width > displayWorkingArea.width) {
|
||||
state.width = displayWorkingArea.width; // prevent window from exceeding display bounds width
|
||||
// prevent window from exceeding display bounds width
|
||||
state.width = displayWorkingArea.width;
|
||||
}
|
||||
|
||||
if (state.height > displayWorkingArea.height) {
|
||||
state.height = displayWorkingArea.height; // prevent window from exceeding display bounds height
|
||||
// prevent window from exceeding display bounds height
|
||||
state.height = displayWorkingArea.height;
|
||||
}
|
||||
|
||||
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.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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user