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
+18 -7
View File
@@ -3,9 +3,10 @@
* @license MIT
*/
import { Disposable, toDisposable } from 'common/Lifecycle';
import { Disposable, MutableDisposable, toDisposable } from 'common/Lifecycle';
import { ICoreBrowserService } from './Services';
import { EventEmitter, forwardEvent } from 'common/EventEmitter';
import { addDisposableDomListener } from 'browser/Lifecycle';
export class CoreBrowserService extends Disposable implements ICoreBrowserService {
public serviceBrand: undefined;
@@ -26,6 +27,7 @@ export class CoreBrowserService extends Disposable implements ICoreBrowserServic
) {
super();
// Monitor device pixel ratio
this.register(this.onWindowChange(w => this._screenDprMonitor.setWindow(w)));
this.register(forwardEvent(this._screenDprMonitor.onDprChange, this._onDprChange));
@@ -72,6 +74,7 @@ class ScreenDprMonitor extends Disposable {
private _currentDevicePixelRatio: number;
private _outerListener: ((this: MediaQueryList, ev: MediaQueryListEvent) => any) | undefined;
private _resolutionMediaMatchList: MediaQueryList | undefined;
private _windowResizeListener = this.register(new MutableDisposable());
private readonly _onDprChange = this.register(new EventEmitter<number>());
public readonly onDprChange = this._onDprChange.event;
@@ -80,21 +83,29 @@ class ScreenDprMonitor extends Disposable {
super();
// Initialize listener and dpr value
this._outerListener = () => {
if (this._parentWindow.devicePixelRatio !== this._currentDevicePixelRatio) {
this._onDprChange.fire(this._parentWindow.devicePixelRatio);
}
this._updateDpr();
};
this._outerListener = () => this._setDprAndFireIfDiffers();
this._currentDevicePixelRatio = this._parentWindow.devicePixelRatio;
this._updateDpr();
// Monitor active window resize
this._setWindowResizeListener();
// Setup additional disposables
this.register(toDisposable(() => this.clearListener()));
}
public setWindow(parentWindow: Window): void {
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) {
this._onDprChange.fire(this._parentWindow.devicePixelRatio);
}
+1 -11
View File
@@ -3,12 +3,11 @@
* @license MIT
*/
import { addDisposableDomListener } from 'browser/Lifecycle';
import { RenderDebouncer } from 'browser/RenderDebouncer';
import { IRenderDebouncerWithCallback } from 'browser/Types';
import { IRenderDimensions, IRenderer } from 'browser/renderer/shared/Types';
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 { DebouncedIdleTask } from 'common/TaskQueue';
import { IBufferService, IDecorationService, IInstantiationService, IOptionsService } from 'common/services/Services';
@@ -101,15 +100,6 @@ export class RenderService extends Disposable implements IRenderService {
'cursorStyle'
], () => 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()));
// Detect whether IntersectionObserver is detected and enable renderer pause