Move win32 input mode into a class to avoid init cost

This commit is contained in:
Daniel Imms
2026-01-30 07:07:55 -08:00
parent 01450f044a
commit d35481c3f9
3 changed files with 268 additions and 266 deletions
+12 -3
View File
@@ -6,7 +6,7 @@
import { IKeyboardService } from 'browser/services/Services';
import { evaluateKeyboardEvent } from 'common/input/Keyboard';
import { evaluateKeyboardEventKitty, KittyKeyboardEventType, KittyKeyboardFlags, shouldUseKittyProtocol } from 'common/input/KittyKeyboard';
import { evaluateKeyboardEventWin32 } from 'common/input/Win32InputMode';
import { Win32InputMode } from 'common/input/Win32InputMode';
import { isMac } from 'common/Platform';
import { ICoreService, IOptionsService } from 'common/services/Services';
import { IKeyboardResult } from 'common/Types';
@@ -14,16 +14,25 @@ import { IKeyboardResult } from 'common/Types';
export class KeyboardService implements IKeyboardService {
public serviceBrand: undefined;
private _win32InputMode: Win32InputMode | undefined;
constructor(
@ICoreService private readonly _coreService: ICoreService,
@IOptionsService private readonly _optionsService: IOptionsService
) {
}
private _getWin32InputMode(): Win32InputMode {
if (!this._win32InputMode) {
this._win32InputMode = new Win32InputMode();
}
return this._win32InputMode;
}
public evaluateKeyDown(event: KeyboardEvent): IKeyboardResult {
// Win32 input mode takes priority (most raw)
if (this.useWin32InputMode) {
return evaluateKeyboardEventWin32(event, true);
return this._getWin32InputMode().evaluateKeyboardEvent(event, true);
}
const kittyFlags = this._coreService.kittyKeyboard.flags;
return this.useKitty
@@ -34,7 +43,7 @@ export class KeyboardService implements IKeyboardService {
public evaluateKeyUp(event: KeyboardEvent): IKeyboardResult | undefined {
// Win32 input mode sends key up events
if (this.useWin32InputMode) {
return evaluateKeyboardEventWin32(event, false);
return this._getWin32InputMode().evaluateKeyboardEvent(event, false);
}
const kittyFlags = this._coreService.kittyKeyboard.flags;
if (this.useKitty && (kittyFlags & KittyKeyboardFlags.REPORT_EVENT_TYPES)) {