Merge from vscode 4636be2b71c87bfb0bfe3c94278b447a5efcc1f1 (#8722)

* Merge from vscode 4636be2b71c87bfb0bfe3c94278b447a5efcc1f1

* remove tests that aren't working
This commit is contained in:
Anthony Dresser
2019-12-18 00:14:28 -08:00
committed by GitHub
parent 0fd870d156
commit 30d9e9c141
289 changed files with 5537 additions and 3039 deletions

View File

@@ -130,11 +130,6 @@ export class CodeWindow extends Disposable implements ICodeWindow {
show: !isFullscreenOrMaximized,
title: product.nameLong,
webPreferences: {
// By default if Code is in the background, intervals and timeouts get throttled, so we
// want to enforce that Code stays in the foreground. This triggers a disable_hidden_
// flag that Electron provides via patch:
// https://github.com/electron/libchromiumcontent/blob/master/patches/common/chromium/disable_hidden.patch
backgroundThrottling: false,
nodeIntegration: true,
nodeIntegrationInWorker: RUN_TEXTMATE_IN_WORKER,
webviewTag: true
@@ -778,6 +773,8 @@ export class CodeWindow extends Disposable implements ICodeWindow {
}
private validateWindowState(state: IWindowState, displays: Display[]): IWindowState | undefined {
this.logService.trace(`window#validateWindowState: validating window state on ${displays.length} display(s)`, state);
if (typeof state.x !== 'number'
|| typeof state.y !== 'number'
|| typeof state.width !== 'number'
@@ -793,34 +790,62 @@ 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 display', 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
function ensureStateInDisplayWorkingArea(): void {
if (!state || typeof state.x !== 'number' || typeof state.y !== 'number' || !displayWorkingArea) {
return;
}
if (state.x < displayWorkingArea.x) {
// prevent window from falling out of the screen to the left
state.x = displayWorkingArea.x;
}
if (state.y < displayWorkingArea.y) {
// prevent window from falling out of the screen to the top
state.y = displayWorkingArea.y;
}
}
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
}
// ensure state is not outside display working area (top, left)
ensureStateInDisplayWorkingArea();
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;
}
// again ensure state is not outside display working area
// (it may have changed from the previous validation step)
ensureStateInDisplayWorkingArea();
}
return state;
@@ -840,19 +865,18 @@ export class CodeWindow extends Disposable implements ICodeWindow {
}
}
// Multi Monitor (non-fullscreen): be less strict because metrics can be crazy
const bounds = { x: state.x, y: state.y, width: state.width, height: state.height };
const display = screen.getDisplayMatching(bounds);
// Multi Monitor (non-fullscreen): ensure window is within display bounds
const display = screen.getDisplayMatching({ x: state.x, y: state.y, width: state.width, height: state.height });
const displayWorkingArea = this.getWorkingArea(display);
if (
display && // we have a display matching the desired bounds
displayWorkingArea && // we have valid working area bounds
bounds.x < displayWorkingArea.x + displayWorkingArea.width && // prevent window from falling out of the screen to the right
bounds.y < displayWorkingArea.y + displayWorkingArea.height && // prevent window from falling out of the screen to the bottom
bounds.x + bounds.width > displayWorkingArea.x && // prevent window from falling out of the screen to the left
bounds.y + bounds.height > displayWorkingArea.y // prevent window from falling out of the scree nto the top
state.x + state.width > displayWorkingArea.x && // prevent window from falling out of the screen to the left
state.y + state.height > displayWorkingArea.y && // prevent window from falling out of the screen to the top
state.x < displayWorkingArea.x + displayWorkingArea.width && // prevent window from falling out of the screen to the right
state.y < displayWorkingArea.y + displayWorkingArea.height // prevent window from falling out of the screen to the bottom
) {
this.logService.trace('window#validateWindowState: multi display', displayWorkingArea);
this.logService.trace('window#validateWindowState: multi-monitor working area', displayWorkingArea);
return state;
}