Compare commits

...
Author SHA1 Message Date
WendelinandClaude Opus 5.5 5f1c8a24fd Capture the camera player's input listeners
The options on a listener object are ignored by addEventListener, so the
listeners didn't capture and missed key presses stopped by dialogs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-30 17:13:46 +01:00
WendelinandClaude Opus 5.5 a350eaa9a7 Always hide the camera player controls after a few seconds
Hover only keeps the controls after mouse input, as a tapped button stays
hovered on touch screens. Focus only keeps them after keyboard input, as
focus moved by a script can look like keyboard focus. The hide timer also
starts again when the player is added back to the page.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-30 16:55:17 +01:00
+24 -3
View File
@@ -168,6 +168,16 @@ export class HaCameraPlayer extends LitElement {
private _controlsTimeout?: number;
// A pointer type or "keyboard", as hover sticks after a tap on touch
// screens and focus moved by a script can look like keyboard focus
private _lastInput?: string;
// Captured, as dialogs stop the propagation of their key presses
private _inputChanged = (ev: KeyboardEvent | PointerEvent) => {
this._lastInput =
ev.type === "keydown" ? "keyboard" : (ev as PointerEvent).pointerType;
};
private _wheelHintTimeout?: number;
private _videoRequest = 0;
@@ -205,6 +215,12 @@ export class HaCameraPlayer extends LitElement {
"webkitfullscreenchange",
this._fullscreenChanged
);
const inputOptions = { capture: true, passive: true };
document.addEventListener("keydown", this._inputChanged, inputOptions);
document.addEventListener("pointerdown", this._inputChanged, inputOptions);
if (this._controlsVisible) {
this._scheduleHideControls();
}
}
public disconnectedCallback() {
@@ -216,6 +232,8 @@ export class HaCameraPlayer extends LitElement {
"webkitfullscreenchange",
this._fullscreenChanged
);
document.removeEventListener("keydown", this._inputChanged, true);
document.removeEventListener("pointerdown", this._inputChanged, true);
clearTimeout(this._controlsTimeout);
clearTimeout(this._wheelHintTimeout);
this._streamInfoCallbacks.clear();
@@ -533,9 +551,10 @@ export class HaCameraPlayer extends LitElement {
this._controlsTimeout = window.setTimeout(() => {
this._controlsTimeout = undefined;
if (
this._overlay?.querySelector(
".control:hover, ha-camera-stream-badge:hover"
) ||
(this._lastInput === "mouse" &&
this._overlay?.querySelector(
".control:hover, ha-camera-stream-badge:hover"
)) ||
this._hasKeyboardFocus()
) {
this._scheduleHideControls();
@@ -547,6 +566,7 @@ export class HaCameraPlayer extends LitElement {
private _hasKeyboardFocus(): boolean {
return Boolean(
this._lastInput === "keyboard" &&
this.shadowRoot &&
deepActiveElement(this.shadowRoot)?.matches(":focus-visible")
);
@@ -956,6 +976,7 @@ export class HaCameraPlayer extends LitElement {
private _pointerMove(ev: PointerEvent) {
if (ev.pointerType === "mouse" && !this._pointers.size) {
this._lastInput = "mouse";
this._showControls();
}
const pointer = this._pointers.get(ev.pointerId);