feat(session): console game library — Skia coverflow + SkSL aurora, --browse (phase 4b)
The run loop grows a browse mode: the console library idles between streams in ONE window (no gamescope handoff), overlay actions launch sessions via run_browse's callback, session end returns to the library. The Overlay contract gains menu routing (MenuEvent → haptic pulse), action draining, and session-phase edges. pf-console-ui ports the GTK launcher wholesale: the coverflow's springs, cursor arithmetic and recede/tilt constants move verbatim with their tests (plus new projection tests — focused-card centering, the inner- edge-recedes corridor); paint order is draw order (the gtk::Fixed restack hack is gone); the aurora renders as an SkSL runtime shader at full rate on every box (the 30 Hz CPU-upscale path and its frozen-on- Deck fallback are deleted — the generated SkSL is compile-tested); titles/scenes shape through textlayout (CJK-safe). Poster art streams in as encoded bytes through the shared model and decodes renderer-side. The session binary wires --browse host[:port] [--mgmt PORT]: KnownHosts lookup (unpaired renders the pair-first scene), library + art fetch on threads, PUNKTFUNK_FAKE_LIBRARY dev hook, and a session_params helper shared with --connect. The minimal build refuses --browse cleanly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,184 @@
|
||||
//! `--browse host[:port]` — the console game library (phase 4b of the plan): the Skia
|
||||
//! coverflow idles in the session window, A launches the focused title as a stream in
|
||||
//! the SAME window (no gamescope window handoff — the whole point of one process), the
|
||||
//! session's end returns to the library, B quits to Gaming Mode.
|
||||
//!
|
||||
//! The host must already be paired (the stored pin fetches the library and connects
|
||||
//! silently; no ceremony can run under gamescope) — an unpaired target renders the
|
||||
//! pair-first scene. `PUNKTFUNK_FAKE_LIBRARY=<file.json>` feeds canned entries with no
|
||||
//! host (portrait paths starting with `/` load from disk), the GPU-only dev path.
|
||||
|
||||
use crate::session_main::{arg_flag, arg_value, fullscreen_mode, parse_host_port, session_params};
|
||||
use pf_client_core::{library, trust};
|
||||
use pf_console_ui::{LibraryGame, LibraryPhase, LibraryShared, SkiaOverlay};
|
||||
use pf_presenter::overlay::OverlayAction;
|
||||
use pf_presenter::ActionOutcome;
|
||||
use std::collections::VecDeque;
|
||||
|
||||
pub fn run(target: &str) -> u8 {
|
||||
let (addr, port) = parse_host_port(target);
|
||||
let known = trust::KnownHosts::load();
|
||||
let k = known
|
||||
.hosts
|
||||
.iter()
|
||||
.find(|h| h.addr == addr && h.port == port);
|
||||
let host_label = k.map_or_else(|| addr.clone(), |h| h.name.clone());
|
||||
let paired = k.is_some_and(|h| h.paired);
|
||||
let pin = k.and_then(|h| trust::parse_hex32(&h.fp_hex));
|
||||
let mgmt = arg_value("--mgmt")
|
||||
.and_then(|p| p.parse().ok())
|
||||
.unwrap_or(library::DEFAULT_MGMT_PORT);
|
||||
|
||||
let identity = match trust::load_or_create_identity() {
|
||||
Ok(i) => i,
|
||||
Err(e) => {
|
||||
eprintln!("client identity: {e:#}");
|
||||
return crate::session_main::EXIT_CONNECT_FAILED;
|
||||
}
|
||||
};
|
||||
let settings = trust::Settings::load();
|
||||
|
||||
let (overlay, shared) = match SkiaOverlay::with_library(host_label.clone()) {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
eprintln!("console UI: {e:#}");
|
||||
return crate::session_main::EXIT_PRESENTER_FAILED;
|
||||
}
|
||||
};
|
||||
|
||||
// The library fetch — paired hosts only (the fake-library hook exists precisely for
|
||||
// host-less/pairing-less UI work).
|
||||
let fake = std::env::var_os("PUNKTFUNK_FAKE_LIBRARY").is_some();
|
||||
if paired || fake {
|
||||
spawn_fetch(shared.clone(), addr.clone(), mgmt, identity.clone(), pin);
|
||||
} else {
|
||||
shared.set_phase(LibraryPhase::PairFirst);
|
||||
}
|
||||
|
||||
let opts = pf_presenter::SessionOpts {
|
||||
window_title: format!("Punktfunk · {host_label}"),
|
||||
fullscreen: fullscreen_mode(),
|
||||
print_stats: settings.show_stats || arg_flag("--stats"),
|
||||
json_status: false, // browse has no shell parent reading stdout
|
||||
on_connected: Some(Box::new(|fingerprint: [u8; 32]| {
|
||||
trust::touch_last_used(&trust::hex(&fingerprint));
|
||||
})),
|
||||
overlay: Some(Box::new(overlay)),
|
||||
};
|
||||
|
||||
let result = pf_presenter::run_browse(opts, |action, gamepad, native, force_software| {
|
||||
match action {
|
||||
OverlayAction::Launch { id, title } => {
|
||||
// The carousel only renders for a paired host, so the pin exists; the
|
||||
// guard keeps a logic slip from turning into a pinless connect.
|
||||
let Some(pin) = pin else {
|
||||
tracing::warn!("launch without a stored pin — refusing");
|
||||
return ActionOutcome::Handled;
|
||||
};
|
||||
tracing::info!(%id, %title, "launching from the library");
|
||||
ActionOutcome::Start(session_params(
|
||||
&settings,
|
||||
addr.clone(),
|
||||
port,
|
||||
pin,
|
||||
identity.clone(),
|
||||
Some(id),
|
||||
gamepad,
|
||||
native,
|
||||
force_software,
|
||||
))
|
||||
}
|
||||
OverlayAction::Retry => {
|
||||
spawn_fetch(shared.clone(), addr.clone(), mgmt, identity.clone(), pin);
|
||||
ActionOutcome::Handled
|
||||
}
|
||||
OverlayAction::Quit => ActionOutcome::Quit,
|
||||
}
|
||||
});
|
||||
|
||||
match result {
|
||||
Ok(()) => 0,
|
||||
Err(e) => {
|
||||
eprintln!("browse: {e:#}");
|
||||
crate::session_main::EXIT_PRESENTER_FAILED
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetch the library off the main thread, then stream poster art into the shared model
|
||||
/// as results land (the GTK launcher's `load` + `load_art`, minus the main-loop hops —
|
||||
/// the renderer drains `push_art` per frame).
|
||||
fn spawn_fetch(
|
||||
shared: LibraryShared,
|
||||
addr: String,
|
||||
mgmt: u16,
|
||||
identity: (String, String),
|
||||
pin: Option<[u8; 32]>,
|
||||
) {
|
||||
shared.set_phase(LibraryPhase::Loading);
|
||||
std::thread::Builder::new()
|
||||
.name("punktfunk-library".into())
|
||||
.spawn(move || {
|
||||
if let Ok(path) = std::env::var("PUNKTFUNK_FAKE_LIBRARY") {
|
||||
load_fake(&shared, &path);
|
||||
return;
|
||||
}
|
||||
match library::fetch_games(&addr, mgmt, &identity, pin) {
|
||||
Ok(games) => {
|
||||
let base = library::base_url(&addr, mgmt);
|
||||
let jobs: VecDeque<(String, Vec<String>)> = games
|
||||
.iter()
|
||||
.map(|g| (g.id.clone(), g.art.poster_candidates(&base)))
|
||||
.filter(|(_, candidates)| !candidates.is_empty())
|
||||
.collect();
|
||||
shared.set_games(
|
||||
games
|
||||
.iter()
|
||||
.map(|g| LibraryGame {
|
||||
id: g.id.clone(),
|
||||
title: g.title.clone(),
|
||||
store: g.store.clone(),
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
if !jobs.is_empty() {
|
||||
let rx = library::spawn_art_fetch(base, identity, pin, jobs);
|
||||
while let Ok((id, bytes)) = rx.recv_blocking() {
|
||||
shared.push_art(id, bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => shared.set_phase(LibraryPhase::Error {
|
||||
title: "Couldn't load the library".into(),
|
||||
body: e.to_string(),
|
||||
can_retry: true,
|
||||
}),
|
||||
}
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
|
||||
/// Dev hook: entries from a JSON file; portrait paths starting with `/` load from disk.
|
||||
fn load_fake(shared: &LibraryShared, path: &str) {
|
||||
let games: Vec<library::GameEntry> = std::fs::read_to_string(path)
|
||||
.ok()
|
||||
.and_then(|s| serde_json::from_str(&s).ok())
|
||||
.unwrap_or_default();
|
||||
for g in &games {
|
||||
if let Some(p) = g.art.portrait.as_deref().filter(|p| p.starts_with('/')) {
|
||||
if let Ok(bytes) = std::fs::read(p) {
|
||||
shared.push_art(g.id.clone(), bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
shared.set_games(
|
||||
games
|
||||
.iter()
|
||||
.map(|g| LibraryGame {
|
||||
id: g.id.clone(),
|
||||
title: g.title.clone(),
|
||||
store: g.store.clone(),
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
@@ -12,11 +12,17 @@
|
||||
//! `{"ended": …}` JSON line on the way out. Logs go to stderr. Exit codes: 0 clean end,
|
||||
//! 2 connect failed, 3 trust rejected / pairing required, 4 presenter init failed.
|
||||
|
||||
#[cfg(all(target_os = "linux", feature = "ui"))]
|
||||
mod browse;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
mod session_main {
|
||||
use pf_client_core::gamepad::GamepadService;
|
||||
use pf_client_core::session::SessionParams;
|
||||
use pf_client_core::trust;
|
||||
use punktfunk_core::config::{CompositorPref, GamepadPref, Mode};
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
pub const EXIT_CONNECT_FAILED: u8 = 2;
|
||||
@@ -24,24 +30,32 @@ mod session_main {
|
||||
pub const EXIT_PRESENTER_FAILED: u8 = 4;
|
||||
|
||||
/// The value following `flag` in argv, if present (`--flag value`).
|
||||
fn arg_value(flag: &str) -> Option<String> {
|
||||
pub(crate) fn arg_value(flag: &str) -> Option<String> {
|
||||
std::env::args()
|
||||
.skip_while(|a| a != flag)
|
||||
.nth(1)
|
||||
.filter(|v| !v.starts_with("--"))
|
||||
}
|
||||
|
||||
fn arg_flag(flag: &str) -> bool {
|
||||
pub(crate) fn arg_flag(flag: &str) -> bool {
|
||||
std::env::args().any(|a| a == flag)
|
||||
}
|
||||
|
||||
/// Run fullscreen: `--fullscreen`, or the Deck/gamescope env as a fallback so a
|
||||
/// manual launch under Gaming Mode does the right thing too.
|
||||
pub(crate) fn fullscreen_mode() -> bool {
|
||||
arg_flag("--fullscreen")
|
||||
|| std::env::var_os("SteamDeck").is_some()
|
||||
|| std::env::var_os("GAMESCOPE_WAYLAND_DISPLAY").is_some()
|
||||
}
|
||||
|
||||
/// `host[:port]`, port defaulting to the native 9777.
|
||||
fn parse_host_port(target: &str) -> (String, u16) {
|
||||
pub(crate) fn parse_host_port(target: &str) -> (String, u16) {
|
||||
match target.rsplit_once(':') {
|
||||
Some((a, p)) => match p.parse() {
|
||||
Ok(port) => (a.to_string(), port),
|
||||
Err(_) => {
|
||||
eprintln!("--connect: unparsable port in '{target}', using default 9777");
|
||||
eprintln!("unparsable port in '{target}', using default 9777");
|
||||
(a.to_string(), 9777)
|
||||
}
|
||||
},
|
||||
@@ -49,6 +63,65 @@ mod session_main {
|
||||
}
|
||||
}
|
||||
|
||||
/// One session's pump parameters from the Settings store — shared by `--connect`
|
||||
/// and every `--browse` launch. Explicit settings, `0` fields resolved to the
|
||||
/// window's display (the GTK client reads the monitor under its window — same
|
||||
/// contract).
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn session_params(
|
||||
settings: &trust::Settings,
|
||||
addr: String,
|
||||
port: u16,
|
||||
pin: [u8; 32],
|
||||
identity: (String, String),
|
||||
launch: Option<String>,
|
||||
gamepad: &GamepadService,
|
||||
native: Mode,
|
||||
force_software: Arc<AtomicBool>,
|
||||
) -> SessionParams {
|
||||
let mode = Mode {
|
||||
width: if settings.width == 0 {
|
||||
native.width
|
||||
} else {
|
||||
settings.width
|
||||
},
|
||||
height: if settings.width == 0 {
|
||||
native.height
|
||||
} else {
|
||||
settings.height
|
||||
},
|
||||
refresh_hz: if settings.refresh_hz == 0 {
|
||||
native.refresh_hz.max(30)
|
||||
} else {
|
||||
settings.refresh_hz
|
||||
},
|
||||
};
|
||||
SessionParams {
|
||||
host: addr,
|
||||
port,
|
||||
mode,
|
||||
compositor: CompositorPref::from_name(&settings.compositor)
|
||||
.unwrap_or(CompositorPref::Auto),
|
||||
gamepad: match GamepadPref::from_name(&settings.gamepad) {
|
||||
Some(GamepadPref::Auto) | None => gamepad.auto_pref(),
|
||||
Some(explicit) => explicit,
|
||||
},
|
||||
bitrate_kbps: settings.bitrate_kbps,
|
||||
audio_channels: settings.audio_channels,
|
||||
preferred_codec: settings.preferred_codec(),
|
||||
mic_enabled: settings.mic_enabled,
|
||||
// The Settings preference (auto → VAAPI where it exists; the presenter
|
||||
// demotes to software on boxes whose Vulkan can't import the dmabufs).
|
||||
// PUNKTFUNK_DECODER still overrides inside the decoder for bisects.
|
||||
decoder: settings.decoder.clone(),
|
||||
launch,
|
||||
pin: Some(pin),
|
||||
identity,
|
||||
connect_timeout: Duration::from_secs(15),
|
||||
force_software,
|
||||
}
|
||||
}
|
||||
|
||||
/// One JSON status line on stdout (the shell parses these; strings hand-escaped via
|
||||
/// the minimal rules a reason string can need).
|
||||
fn json_line(key: &str, msg: &str, trust_rejected: Option<bool>) {
|
||||
@@ -91,11 +164,26 @@ mod session_main {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(target) = arg_value("--browse") {
|
||||
#[cfg(feature = "ui")]
|
||||
return crate::browse::run(&target);
|
||||
#[cfg(not(feature = "ui"))]
|
||||
{
|
||||
let _ = target;
|
||||
eprintln!(
|
||||
"--browse needs the console UI — this is the minimal build \
|
||||
(rebuild without --no-default-features)"
|
||||
);
|
||||
return EXIT_PRESENTER_FAILED;
|
||||
}
|
||||
}
|
||||
let Some(target) = arg_value("--connect") else {
|
||||
eprintln!(
|
||||
"usage: punktfunk-session --connect host[:port] [--fp HEX] [--launch id] [--fullscreen]\n\
|
||||
\x20 punktfunk-session --browse host[:port] [--mgmt PORT] [--fullscreen]\n\
|
||||
\n\
|
||||
Streams from a paired punktfunk host in a Vulkan window. Pair first via the\n\
|
||||
Streams from a paired punktfunk host in a Vulkan window; --browse opens the\n\
|
||||
console game library instead (paired hosts only). Pair first via the\n\
|
||||
desktop client or `punktfunk-client --pair <PIN> --connect host[:port]` —\n\
|
||||
this binary never connects to a host it has no pinned fingerprint for."
|
||||
);
|
||||
@@ -161,41 +249,17 @@ mod session_main {
|
||||
};
|
||||
|
||||
let outcome = pf_presenter::run_session(opts, move |gamepad, native, force_software| {
|
||||
// Explicit settings, `0` fields resolved to the window's display (the GTK
|
||||
// client reads the monitor under its window — same contract).
|
||||
let mode = Mode {
|
||||
width: if settings.width == 0 { native.width } else { settings.width },
|
||||
height: if settings.width == 0 { native.height } else { settings.height },
|
||||
refresh_hz: if settings.refresh_hz == 0 {
|
||||
native.refresh_hz.max(30)
|
||||
} else {
|
||||
settings.refresh_hz
|
||||
},
|
||||
};
|
||||
SessionParams {
|
||||
host: addr,
|
||||
session_params(
|
||||
&settings,
|
||||
addr,
|
||||
port,
|
||||
mode,
|
||||
compositor: CompositorPref::from_name(&settings.compositor)
|
||||
.unwrap_or(CompositorPref::Auto),
|
||||
gamepad: match GamepadPref::from_name(&settings.gamepad) {
|
||||
Some(GamepadPref::Auto) | None => gamepad.auto_pref(),
|
||||
Some(explicit) => explicit,
|
||||
},
|
||||
bitrate_kbps: settings.bitrate_kbps,
|
||||
audio_channels: settings.audio_channels,
|
||||
preferred_codec: settings.preferred_codec(),
|
||||
mic_enabled: settings.mic_enabled,
|
||||
// The Settings preference (auto → VAAPI where it exists; the presenter
|
||||
// demotes to software on boxes whose Vulkan can't import the dmabufs).
|
||||
// PUNKTFUNK_DECODER still overrides inside the decoder for bisects.
|
||||
decoder: settings.decoder.clone(),
|
||||
launch,
|
||||
pin: Some(pin),
|
||||
pin,
|
||||
identity,
|
||||
connect_timeout: Duration::from_secs(15),
|
||||
launch,
|
||||
gamepad,
|
||||
native,
|
||||
force_software,
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
match outcome {
|
||||
|
||||
Reference in New Issue
Block a user