Skip to content

Commit

Permalink
fix(web): allow keyboard input even if the mouse is off the area of c…
Browse files Browse the repository at this point in the history
…anvas (#685)
  • Loading branch information
irvingoujAtDevolution authored Mar 5, 2025
1 parent 7f08a09 commit 5214929
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
15 changes: 11 additions & 4 deletions web-client/iron-remote-gui/src/iron-remote-gui.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@
} = $props();
let isVisible = $state(false);
let capturingInputs = $state(false);
let capturingInputs = () => {
loggingService.info(`
capturingInputs: ${document.activeElement === canvas}
current active element: ${document.activeElement}
`);
return document.activeElement === canvas;
};
let inner: HTMLDivElement;
let wrapper: HTMLDivElement;
Expand Down Expand Up @@ -367,7 +374,7 @@
userInteractionListeners();
function captureKeys(evt: KeyboardEvent) {
if (capturingInputs) {
if (capturingInputs()) {
if (ffPostponeKeyboardEvents) {
evt.preventDefault();
ffDelayedKeyboardEvents.push(evt);
Expand Down Expand Up @@ -599,12 +606,11 @@
}
function setMouseIn(evt: MouseEvent) {
capturingInputs = true;
canvas.focus();
wasmService.mouseIn(evt);
}
function setMouseOut(evt: MouseEvent) {
capturingInputs = false;
wasmService.mouseOut(evt);
}
Expand Down Expand Up @@ -699,6 +705,7 @@
oncontextmenu={(event) => event.preventDefault()}
onwheel={mouseWheel}
id="renderer"
tabindex="0"
></canvas>
</div>
</div>
Expand Down
10 changes: 1 addition & 9 deletions web-client/iron-remote-gui/src/services/wasm-bridge.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export class WasmBridgeService {
private sessionEvent: Subject<SessionEvent> = new Subject();
private scale: BehaviorSubject<ScreenScale> = new BehaviorSubject(ScreenScale.Fit as ScreenScale);
private canvas?: HTMLCanvasElement;
private keyboardActive: boolean = false;
private keyboardUnicodeMode: boolean = false;
private backendSupportsUnicodeKeyboardShortcuts: boolean | undefined = undefined;
private onRemoteClipboardChanged?: OnRemoteClipboardChanged;
Expand Down Expand Up @@ -98,18 +97,14 @@ export class WasmBridgeService {

mouseIn(event: MouseEvent) {
this.syncModifier(event);
this.keyboardActive = true;
}

mouseOut(_event: MouseEvent) {
this.keyboardActive = false;
this.releaseAllInputs();
}

sendKeyboardEvent(evt: KeyboardEvent) {
if (this.keyboardActive) {
this.sendKeyboard(evt);
}
this.sendKeyboard(evt);
}

shutdown() {
Expand All @@ -125,9 +120,6 @@ export class WasmBridgeService {
}

updateMousePosition(position: MousePosition) {
if (!this.keyboardActive) {
this.keyboardActive = true;
}
this.doTransactionFromDeviceEvents([DeviceEvent.new_mouse_move(position.x, position.y)]);
this.mousePosition.next(position);
}
Expand Down

0 comments on commit 5214929

Please sign in to comment.