mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 05:16:01 +00:00
feat(steam): sync QAM controls and pass held Back shortcuts (#1621)
Steam's native QAM sliders now control Android brightness and media volume, with device changes reflected back in Steam. Holding Android Back for 700 ms sends a real held QAM button for Steam shortcuts. Single and double taps keep the existing menu/QAM order and swap setting; the double-tap window remains 500 ms. - Discover native brightness through a guest backlight descriptor and use Android's Modify system settings permission. Retain the latest pending request until permission is granted or the session stops, with a notification action for hidden sessions. - Give DirectAudio and fallback AAudio sinks Android media volume/mute callbacks, keeping software gain at unity. Recover when initial volume state is absent or invalid, brightness acknowledgements differ or never arrive, or the Display bridge is not ready yet. - Forward other buttons while QAM is held in Steam Deck and Steam Controller modes. Consume release after a hold and clear pending input on overlays, focus loss, pause, disconnect, and teardown. The session menu retains its compact Back choice without an explanatory paragraph. Validation: - Local ARM64 release build passed. The latest timing change passed 20 targeted input tests, including release at 600 ms remaining a tap. The preceding full feature check passed 61 Android input/device-control tests, with permission cases on API 28 and 33. - 66 Linux Python/Node/C tests passed for device controls, audio recovery, Steam compatibility, and file dialogs. Both audio sink modules rebuilt with Android NDK 27.2. - Release-signed integration build 14d12cf0 is installed on the unrooted AYN Thor, carrying the Android/input changes through749ade4aplus the existing portrait changes. Device checks confirmed the configured QAM/menu tap order, Back dismissal, removal of the inline menu description, and held QAM overlapping X with clean release. Hands-on testing confirmed this installed build works. - Earlier Thor testing covered brightness permission and pending requests, brightness synchronization in both directions, native volume changes, hardware volume key readback, and both sink backends. Failure recovery is covered by the automated tests above. The subsequent queued-notification fix in4d7ceb23is covered by the Linux regression suite and has not replaced the Thor install. Bluetooth/wired output switching and other device models remain untested. CI and CodeRabbit monitoring continue against the pushed head.
This commit is contained in:
19 files changed
+1243
-8
No files matched your search
@@ -2,6 +2,7 @@
|
||||
import base64
|
||||
import ctypes
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
import runpy
|
||||
import select
|
||||
@@ -15,6 +16,50 @@ import time
|
||||
HERE = os.path.dirname(os.path.realpath(__file__))
|
||||
COMPAT = runpy.run_path(os.path.join(HERE, "steam-compatibility"))
|
||||
BINDING = "droiddeckCompatChanged"
|
||||
BRIGHTNESS_BINDING = "droiddeckBrightnessChanged"
|
||||
CONTROLS_DIR = "/etc/droiddeck-device-controls"
|
||||
BRIGHTNESS_JS = r"""
|
||||
(() => {
|
||||
if (window.__droiddeckBrightness) return "present";
|
||||
const display = SteamClient.System?.Display;
|
||||
if (!display?.RegisterForBrightnessChanges || !display?.SetBrightness) return "unavailable";
|
||||
const self = { expected: null, updating: true, revision: 0 };
|
||||
self.set = value => {
|
||||
if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1) return;
|
||||
if (!self.updating && self.expected !== null && Math.abs(value - self.expected) < 0.0001) return;
|
||||
self.expected = value;
|
||||
self.updating = true;
|
||||
const revision = ++self.revision;
|
||||
setTimeout(() => { if (self.revision === revision) self.updating = false; }, 500);
|
||||
display.SetBrightness(value);
|
||||
};
|
||||
self.subscription = display.RegisterForBrightnessChanges(state => {
|
||||
const value = state?.flBrightness;
|
||||
if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1 || self.expected === null) return;
|
||||
if (Math.abs(value - self.expected) < 0.0001) { self.updating = false; return; }
|
||||
if (self.updating) { self.updating = false; return; }
|
||||
self.expected = value;
|
||||
if (typeof window.__BINDING__ === "function") window.__BINDING__(String(value));
|
||||
});
|
||||
window.__droiddeckBrightness = self;
|
||||
return "installed";
|
||||
})()
|
||||
""".replace("__BINDING__", BRIGHTNESS_BINDING)
|
||||
|
||||
|
||||
def brightness_request(payload, directory=CONTROLS_DIR):
|
||||
try:
|
||||
value = float(payload)
|
||||
if not math.isfinite(value) or not 0 <= value <= 1:
|
||||
return
|
||||
path = os.path.join(directory, "brightness.request")
|
||||
with open(path + ".tmp", "w") as target:
|
||||
target.write(str(value) + "\n")
|
||||
os.replace(path + ".tmp", path)
|
||||
except (ValueError, TypeError, OSError):
|
||||
return
|
||||
|
||||
|
||||
INSTALL_JS = r"""
|
||||
(() => {
|
||||
if (window.__droiddeckCompat) return "present";
|
||||
@@ -633,6 +678,29 @@ class Helper:
|
||||
self.tools_checked = None
|
||||
self.vr_launch = None
|
||||
self.chooser = None
|
||||
self.controls_state = None
|
||||
self.controls_installed = False
|
||||
|
||||
def sync_controls(self):
|
||||
try:
|
||||
with open(os.path.join(CONTROLS_DIR, "state.json")) as source:
|
||||
state = json.load(source)
|
||||
value = state.get("brightness")
|
||||
if isinstance(value, bool) or not isinstance(value, (int, float)) or not math.isfinite(value) or not 0 <= value <= 1:
|
||||
return
|
||||
if not self.controls_installed:
|
||||
self.page.call("Runtime.addBinding", {"name": BRIGHTNESS_BINDING})
|
||||
self.controls_installed = self.page.evaluate(BRIGHTNESS_JS) in ("installed", "present")
|
||||
if not self.controls_installed:
|
||||
return
|
||||
if state != self.controls_state:
|
||||
if self.page.evaluate("!!window.__droiddeckBrightness && (window.__droiddeckBrightness.set(%s), true)" % json.dumps(value)) is True:
|
||||
self.controls_state = state
|
||||
else:
|
||||
self.controls_installed = False
|
||||
self.controls_state = None
|
||||
except (OSError, ValueError, TypeError):
|
||||
pass
|
||||
|
||||
def open_chooser(self, payload):
|
||||
try:
|
||||
@@ -709,6 +777,9 @@ class Helper:
|
||||
page.call("Runtime.addBinding", {"name": FILE_BINDING})
|
||||
page.evaluate(FILE_JS)
|
||||
self.page = page
|
||||
self.controls_state = None
|
||||
self.controls_installed = False
|
||||
self.sync_controls()
|
||||
return True
|
||||
page.call("Runtime.addBinding", {"name": BINDING})
|
||||
page.call("Runtime.addBinding", {"name": VR_BINDING})
|
||||
@@ -728,6 +799,9 @@ class Helper:
|
||||
page.ws.close()
|
||||
raise
|
||||
self.page = page
|
||||
self.controls_state = None
|
||||
self.controls_installed = False
|
||||
self.sync_controls()
|
||||
return True
|
||||
|
||||
def reconcile(self):
|
||||
@@ -854,6 +928,8 @@ class Helper:
|
||||
say("preparing SteamVR for library app(s): " + ", ".join(sorted(vr_games)))
|
||||
self.vr_launch = launch_steamvr()
|
||||
for e in events:
|
||||
if called(e, BRIGHTNESS_BINDING):
|
||||
brightness_request(e.get("params", {}).get("payload"))
|
||||
if called(e, FILE_BINDING) and isinstance(e.get("params", {}).get("payload"), str):
|
||||
self.open_chooser(e["params"]["payload"])
|
||||
return events
|
||||
@@ -861,15 +937,14 @@ class Helper:
|
||||
def serve_files(self):
|
||||
say("attached to the client on port %d for its file dialogs" % self.port)
|
||||
while True:
|
||||
self.sync_controls()
|
||||
sources = [self.page.ws] + ([self.chooser[1].stdout] if self.chooser is not None else [])
|
||||
queued = self.page.ws.pending() or bool(self.page.events)
|
||||
ready = [self.page.ws] if queued else select.select(sources, [], [], 30)[0]
|
||||
ready = [self.page.ws] if queued else select.select(sources, [], [], 0.25)[0]
|
||||
if self.chooser is not None and self.chooser[1].stdout in ready:
|
||||
self.chooser_done()
|
||||
if self.page.ws in ready or self.page.events:
|
||||
for e in self.page.drain():
|
||||
if called(e, FILE_BINDING) and isinstance(e.get("params", {}).get("payload"), str):
|
||||
self.open_chooser(e["params"]["payload"])
|
||||
self.drain()
|
||||
|
||||
def serve(self, watcher):
|
||||
if self.files_only:
|
||||
@@ -880,10 +955,12 @@ class Helper:
|
||||
self.reconcile()
|
||||
self.ensure_tools()
|
||||
while True:
|
||||
self.sync_controls()
|
||||
sources = [self.page.ws] + ([watcher] if watcher.fileno() >= 0 else [])
|
||||
if self.chooser is not None:
|
||||
sources.append(self.chooser[1].stdout)
|
||||
ready = [self.page.ws] if self.page.ws.pending() else select.select(sources, [], [], 30 if watcher.fileno() >= 0 else 2)[0]
|
||||
queued = self.page.ws.pending() or bool(self.page.events)
|
||||
ready = [self.page.ws] if queued else select.select(sources, [], [], 0.25)[0]
|
||||
if self.chooser is not None and self.chooser[1].stdout in ready:
|
||||
self.chooser_done()
|
||||
due = False
|
||||
|
||||
Reference in new issue
Block a user