From 4ac8e4ca51db8008fdeb5d10326629791b0b0a48 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Fri, 29 Jul 2022 11:09:19 -0700 Subject: [PATCH] Remove reliance on core in some webgl parts --- addons/xterm-addon-webgl/src/WebglAddon.ts | 5 ++-- addons/xterm-addon-webgl/src/WebglRenderer.ts | 5 ++-- .../src/renderLayer/CursorRenderLayer.ts | 28 +++++++++---------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/addons/xterm-addon-webgl/src/WebglAddon.ts b/addons/xterm-addon-webgl/src/WebglAddon.ts index c04cd0d4..02ab942e 100644 --- a/addons/xterm-addon-webgl/src/WebglAddon.ts +++ b/addons/xterm-addon-webgl/src/WebglAddon.ts @@ -9,7 +9,7 @@ import { ICharacterJoinerService, ICoreBrowserService, IRenderService } from 'br import { IColorSet } from 'browser/Types'; import { EventEmitter } from 'common/EventEmitter'; import { isSafari } from 'common/Platform'; -import { IDecorationService } from 'common/services/Services'; +import { ICoreService, IDecorationService } from 'common/services/Services'; export class WebglAddon implements ITerminalAddon { private _terminal?: Terminal; @@ -32,9 +32,10 @@ export class WebglAddon implements ITerminalAddon { const renderService: IRenderService = (terminal as any)._core._renderService; const characterJoinerService: ICharacterJoinerService = (terminal as any)._core._characterJoinerService; const coreBrowserService: ICoreBrowserService = (terminal as any)._core._coreBrowserService; + const coreService: ICoreService = (terminal as any)._core.coreService; const decorationService: IDecorationService = (terminal as any)._core._decorationService; const colors: IColorSet = (terminal as any)._core._colorManager.colors; - this._renderer = new WebglRenderer(terminal, colors, characterJoinerService, coreBrowserService, decorationService, this._preserveDrawingBuffer); + this._renderer = new WebglRenderer(terminal, colors, characterJoinerService, coreBrowserService, coreService, decorationService, this._preserveDrawingBuffer); this._renderer.onContextLoss(() => this._onContextLoss.fire()); renderService.setRenderer(this._renderer); } diff --git a/addons/xterm-addon-webgl/src/WebglRenderer.ts b/addons/xterm-addon-webgl/src/WebglRenderer.ts index af1ceef5..be7517a3 100644 --- a/addons/xterm-addon-webgl/src/WebglRenderer.ts +++ b/addons/xterm-addon-webgl/src/WebglRenderer.ts @@ -24,7 +24,7 @@ import { addDisposableDomListener } from 'browser/Lifecycle'; import { ICharacterJoinerService, ICoreBrowserService } from 'browser/services/Services'; import { CharData, ICellData } from 'common/Types'; import { AttributeData } from 'common/buffer/AttributeData'; -import { IDecorationService } from 'common/services/Services'; +import { ICoreService, IDecorationService } from 'common/services/Services'; export class WebglRenderer extends Disposable implements IRenderer { private _renderLayers: IRenderLayer[]; @@ -56,6 +56,7 @@ export class WebglRenderer extends Disposable implements IRenderer { private _colors: IColorSet, private readonly _characterJoinerService: ICharacterJoinerService, private readonly _coreBrowserService: ICoreBrowserService, + coreService: ICoreService, private readonly _decorationService: IDecorationService, preserveDrawingBuffer?: boolean ) { @@ -65,7 +66,7 @@ export class WebglRenderer extends Disposable implements IRenderer { this._renderLayers = [ new LinkRenderLayer(this._core.screenElement!, 2, this._colors, this._core), - new CursorRenderLayer(_terminal, this._core.screenElement!, 3, this._colors, this._core, this._onRequestRedraw) + new CursorRenderLayer(_terminal, this._core.screenElement!, 3, this._colors, this._onRequestRedraw, this._coreBrowserService, coreService) ]; this.dimensions = { scaledCharWidth: 0, diff --git a/addons/xterm-addon-webgl/src/renderLayer/CursorRenderLayer.ts b/addons/xterm-addon-webgl/src/renderLayer/CursorRenderLayer.ts index fd686cc7..04e2b387 100644 --- a/addons/xterm-addon-webgl/src/renderLayer/CursorRenderLayer.ts +++ b/addons/xterm-addon-webgl/src/renderLayer/CursorRenderLayer.ts @@ -10,6 +10,8 @@ import { CellData } from 'common/buffer/CellData'; import { IColorSet, ITerminal } from 'browser/Types'; import { IRenderDimensions, IRequestRedrawEvent } from 'browser/renderer/Types'; import { IEventEmitter } from 'common/EventEmitter'; +import { ICoreBrowserService } from 'browser/services/Services'; +import { ICoreService } from 'common/services/Services'; interface ICursorState { x: number; @@ -35,8 +37,9 @@ export class CursorRenderLayer extends BaseRenderLayer { container: HTMLElement, zIndex: number, colors: IColorSet, - private readonly _terminal: ITerminal, - private _onRequestRefreshRowsEvent: IEventEmitter + private _onRequestRefreshRowsEvent: IEventEmitter, + private readonly _coreBrowserService: ICoreBrowserService, + private readonly _coreService: ICoreService ) { super(container, 'cursor', zIndex, true, colors); this._state = { @@ -91,9 +94,9 @@ export class CursorRenderLayer extends BaseRenderLayer { public onOptionsChanged(terminal: Terminal): void { if (terminal.options.cursorBlink) { if (!this._cursorBlinkStateManager) { - this._cursorBlinkStateManager = new CursorBlinkStateManager(terminal, () => { + this._cursorBlinkStateManager = new CursorBlinkStateManager(() => { this._render(terminal, true); - }); + }, this._coreBrowserService); } } else { this._cursorBlinkStateManager?.dispose(); @@ -118,8 +121,7 @@ export class CursorRenderLayer extends BaseRenderLayer { private _render(terminal: Terminal, triggeredByAnimationFrame: boolean): void { // Don't draw the cursor if it's hidden - // TODO: Need to expose API for this - if (!this._terminal.coreService.isCursorInitialized || this._terminal.coreService.isCursorHidden) { + if (!this._coreService.isCursorInitialized || this._coreService.isCursorHidden) { this._clearCursor(); return; } @@ -142,7 +144,7 @@ export class CursorRenderLayer extends BaseRenderLayer { return; } - if (!isTerminalFocused(terminal)) { + if (!this._coreBrowserService.isFocused) { this._clearCursor(); this._ctx.save(); this._ctx.fillStyle = this._colors.cursor.css; @@ -171,7 +173,7 @@ export class CursorRenderLayer extends BaseRenderLayer { // The cursor is already in the correct spot, don't redraw if (this._state.x === cursorX && this._state.y === viewportRelativeCursorY && - this._state.isFocused === isTerminalFocused(terminal) && + this._state.isFocused === this._coreBrowserService.isFocused && this._state.style === terminal.options.cursorStyle && this._state.width === this._cell.getWidth()) { return; @@ -254,11 +256,11 @@ class CursorBlinkStateManager { private _animationTimeRestarted: number | undefined; constructor( - terminal: Terminal, - private _renderCallback: () => void + private _renderCallback: () => void, + coreBrowserService: ICoreBrowserService ) { this.isCursorVisible = true; - if (isTerminalFocused(terminal)) { + if (coreBrowserService.isFocused) { this._restartInterval(); } } @@ -373,7 +375,3 @@ class CursorBlinkStateManager { this.restartBlinkAnimation(terminal); } } - -function isTerminalFocused(terminal: Terminal): boolean { - return document.activeElement === terminal.textarea && document.hasFocus(); -}