Move window resize edge case into dpr monitor

This commit is contained in:
Daniel Imms
2023-10-17 09:18:46 -07:00
parent 6e12d94f11
commit 81e0718a74
5 changed files with 23 additions and 39 deletions
-7
View File
@@ -94,14 +94,7 @@ export class AccessibilityManager extends Disposable {
this.register(this._terminal.onKey(e => this._handleKey(e.key))); this.register(this._terminal.onKey(e => this._handleKey(e.key)));
this.register(this._terminal.onBlur(() => this._clearLiveRegion())); this.register(this._terminal.onBlur(() => this._clearLiveRegion()));
this.register(this._renderService.onDimensionsChange(() => this._refreshRowsDimensions())); this.register(this._renderService.onDimensionsChange(() => this._refreshRowsDimensions()));
this.register(this._coreBrowserService.onDprChange(() => this._refreshRowsDimensions())); this.register(this._coreBrowserService.onDprChange(() => this._refreshRowsDimensions()));
// This shouldn't be needed on modern browsers but is present in case the
// media query that drives the ScreenDprMonitor isn't supported
const windowResizeListener = this.register(new MutableDisposable());
this.register(runAndSubscribe(this._coreBrowserService.onWindowChange, () => {
windowResizeListener.value = addDisposableDomListener(this._coreBrowserService.window, 'resize', () => this._refreshRowsDimensions());
}));
this._refreshRows(); this._refreshRows();
this.register(toDisposable(() => { this.register(toDisposable(() => {
@@ -3,10 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { addDisposableDomListener } from 'browser/Lifecycle';
import { ICoreBrowserService, IRenderService } from 'browser/services/Services'; import { ICoreBrowserService, IRenderService } from 'browser/services/Services';
import { runAndSubscribe } from 'common/EventEmitter'; import { Disposable, toDisposable } from 'common/Lifecycle';
import { Disposable, MutableDisposable, toDisposable } from 'common/Lifecycle';
import { IBufferService, IDecorationService, IInternalDecoration } from 'common/services/Services'; import { IBufferService, IDecorationService, IInternalDecoration } from 'common/services/Services';
export class BufferDecorationRenderer extends Disposable { export class BufferDecorationRenderer extends Disposable {
@@ -35,10 +33,7 @@ export class BufferDecorationRenderer extends Disposable {
this._dimensionsChanged = true; this._dimensionsChanged = true;
this._queueRefresh(); this._queueRefresh();
})); }));
const windowResizeListener = this.register(new MutableDisposable()); this.register(this._coreBrowserService.onDprChange(() => this._queueRefresh()));
this.register(runAndSubscribe(this._coreBrowserService.onWindowChange, () => {
windowResizeListener.value = addDisposableDomListener(this._coreBrowserService.window, 'resize', () => this._queueRefresh());
}));
this.register(this._bufferService.buffers.onBufferActivate(() => { this.register(this._bufferService.buffers.onBufferActivate(() => {
this._altBufferIsActive = this._bufferService.buffer === this._bufferService.buffers.alt; this._altBufferIsActive = this._bufferService.buffer === this._bufferService.buffers.alt;
})); }));
@@ -4,10 +4,8 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { ColorZoneStore, IColorZone, IColorZoneStore } from 'browser/decorations/ColorZoneStore'; import { ColorZoneStore, IColorZone, IColorZoneStore } from 'browser/decorations/ColorZoneStore';
import { addDisposableDomListener } from 'browser/Lifecycle';
import { ICoreBrowserService, IRenderService } from 'browser/services/Services'; import { ICoreBrowserService, IRenderService } from 'browser/services/Services';
import { runAndSubscribe } from 'common/EventEmitter'; import { Disposable, toDisposable } from 'common/Lifecycle';
import { Disposable, MutableDisposable, toDisposable } from 'common/Lifecycle';
import { IBufferService, IDecorationService, IOptionsService } from 'common/services/Services'; import { IBufferService, IDecorationService, IOptionsService } from 'common/services/Services';
// Helper objects to avoid excessive calculation and garbage collection during rendering. These are // Helper objects to avoid excessive calculation and garbage collection during rendering. These are
@@ -113,10 +111,7 @@ export class OverviewRulerRenderer extends Disposable {
// overview ruler width changed // overview ruler width changed
this.register(this._optionsService.onSpecificOptionChange('overviewRulerWidth', () => this._queueRefresh(true))); this.register(this._optionsService.onSpecificOptionChange('overviewRulerWidth', () => this._queueRefresh(true)));
// device pixel ratio changed // device pixel ratio changed
const windowResizeListener = this.register(new MutableDisposable()); this.register(this._coreBrowserService.onDprChange(() => this._queueRefresh(true)));
this.register(runAndSubscribe(this._coreBrowserService.onWindowChange, () => {
windowResizeListener.value = addDisposableDomListener(this._coreBrowserService.window, 'resize', () => this._queueRefresh(true));
}));
// set the canvas dimensions // set the canvas dimensions
this._queueRefresh(true); this._queueRefresh(true);
} }
+18 -7
View File
@@ -3,9 +3,10 @@
* @license MIT * @license MIT
*/ */
import { Disposable, toDisposable } from 'common/Lifecycle'; import { Disposable, MutableDisposable, toDisposable } from 'common/Lifecycle';
import { ICoreBrowserService } from './Services'; import { ICoreBrowserService } from './Services';
import { EventEmitter, forwardEvent } from 'common/EventEmitter'; import { EventEmitter, forwardEvent } from 'common/EventEmitter';
import { addDisposableDomListener } from 'browser/Lifecycle';
export class CoreBrowserService extends Disposable implements ICoreBrowserService { export class CoreBrowserService extends Disposable implements ICoreBrowserService {
public serviceBrand: undefined; public serviceBrand: undefined;
@@ -26,6 +27,7 @@ export class CoreBrowserService extends Disposable implements ICoreBrowserServic
) { ) {
super(); super();
// Monitor device pixel ratio
this.register(this.onWindowChange(w => this._screenDprMonitor.setWindow(w))); this.register(this.onWindowChange(w => this._screenDprMonitor.setWindow(w)));
this.register(forwardEvent(this._screenDprMonitor.onDprChange, this._onDprChange)); this.register(forwardEvent(this._screenDprMonitor.onDprChange, this._onDprChange));
@@ -72,6 +74,7 @@ class ScreenDprMonitor extends Disposable {
private _currentDevicePixelRatio: number; private _currentDevicePixelRatio: number;
private _outerListener: ((this: MediaQueryList, ev: MediaQueryListEvent) => any) | undefined; private _outerListener: ((this: MediaQueryList, ev: MediaQueryListEvent) => any) | undefined;
private _resolutionMediaMatchList: MediaQueryList | undefined; private _resolutionMediaMatchList: MediaQueryList | undefined;
private _windowResizeListener = this.register(new MutableDisposable());
private readonly _onDprChange = this.register(new EventEmitter<number>()); private readonly _onDprChange = this.register(new EventEmitter<number>());
public readonly onDprChange = this._onDprChange.event; public readonly onDprChange = this._onDprChange.event;
@@ -80,21 +83,29 @@ class ScreenDprMonitor extends Disposable {
super(); super();
// Initialize listener and dpr value // Initialize listener and dpr value
this._outerListener = () => { this._outerListener = () => this._setDprAndFireIfDiffers();
if (this._parentWindow.devicePixelRatio !== this._currentDevicePixelRatio) {
this._onDprChange.fire(this._parentWindow.devicePixelRatio);
}
this._updateDpr();
};
this._currentDevicePixelRatio = this._parentWindow.devicePixelRatio; this._currentDevicePixelRatio = this._parentWindow.devicePixelRatio;
this._updateDpr(); this._updateDpr();
// Monitor active window resize
this._setWindowResizeListener();
// Setup additional disposables // Setup additional disposables
this.register(toDisposable(() => this.clearListener())); this.register(toDisposable(() => this.clearListener()));
} }
public setWindow(parentWindow: Window): void { public setWindow(parentWindow: Window): void {
this._parentWindow = parentWindow; this._parentWindow = parentWindow;
this._setWindowResizeListener();
this._setDprAndFireIfDiffers();
}
private _setWindowResizeListener(): void {
this._windowResizeListener.value = addDisposableDomListener(this._parentWindow, 'resize', () => this._setDprAndFireIfDiffers());
}
private _setDprAndFireIfDiffers(): void {
if (this._parentWindow.devicePixelRatio !== this._currentDevicePixelRatio) { if (this._parentWindow.devicePixelRatio !== this._currentDevicePixelRatio) {
this._onDprChange.fire(this._parentWindow.devicePixelRatio); this._onDprChange.fire(this._parentWindow.devicePixelRatio);
} }
+1 -11
View File
@@ -3,12 +3,11 @@
* @license MIT * @license MIT
*/ */
import { addDisposableDomListener } from 'browser/Lifecycle';
import { RenderDebouncer } from 'browser/RenderDebouncer'; import { RenderDebouncer } from 'browser/RenderDebouncer';
import { IRenderDebouncerWithCallback } from 'browser/Types'; import { IRenderDebouncerWithCallback } from 'browser/Types';
import { IRenderDimensions, IRenderer } from 'browser/renderer/shared/Types'; import { IRenderDimensions, IRenderer } from 'browser/renderer/shared/Types';
import { ICharSizeService, ICoreBrowserService, IRenderService, IThemeService } from 'browser/services/Services'; import { ICharSizeService, ICoreBrowserService, IRenderService, IThemeService } from 'browser/services/Services';
import { EventEmitter, runAndSubscribe } from 'common/EventEmitter'; import { EventEmitter } from 'common/EventEmitter';
import { Disposable, MutableDisposable } from 'common/Lifecycle'; import { Disposable, MutableDisposable } from 'common/Lifecycle';
import { DebouncedIdleTask } from 'common/TaskQueue'; import { DebouncedIdleTask } from 'common/TaskQueue';
import { IBufferService, IDecorationService, IInstantiationService, IOptionsService } from 'common/services/Services'; import { IBufferService, IDecorationService, IInstantiationService, IOptionsService } from 'common/services/Services';
@@ -101,15 +100,6 @@ export class RenderService extends Disposable implements IRenderService {
'cursorStyle' 'cursorStyle'
], () => this.refreshRows(bufferService.buffer.y, bufferService.buffer.y, true))); ], () => this.refreshRows(bufferService.buffer.y, bufferService.buffer.y, true)));
// dprchange should handle this case, we need this as well for browsers that don't support the
// matchMedia query.
// TODO: Merge this into onDprChange?
const windowResizeListener = this.register(new MutableDisposable());
this.register(runAndSubscribe(coreBrowserService.onWindowChange, () => {
windowResizeListener.value = addDisposableDomListener(coreBrowserService.window, 'resize', () => this.handleDevicePixelRatioChange());
}));
this.register(addDisposableDomListener(coreBrowserService.window, 'resize', () => this.handleDevicePixelRatioChange()));
this.register(themeService.onChangeColors(() => this._fullRefresh())); this.register(themeService.onChangeColors(() => this._fullRefresh()));
// Detect whether IntersectionObserver is detected and enable renderer pause // Detect whether IntersectionObserver is detected and enable renderer pause