Files
qbz/crates/qbz-ui/ui/shell/KioskLocalLibrary.slint
T
vicrodh f1eeaf9126 feat(steam-deck): game mode support (plan PR1-PR5)
- PR1: gamescope detection at boot — X11 backend, scale 1, kiosk
  fullscreen; tray + miniplayer suppressed (click-offset fix).
- PR2: full keyboard navigation for the kiosk (3 zones, focus ring,
  scroll-into-view; typing never navigates).
- PR3: native gamepad via gilrs — D-pad/stick/A/B to synthetic Slint
  keys with hysteresis, repeat and debounce; B suppresses Escape while
  a text field is focused (closes the Steam OSK).
- PR4: Steam OSK via the steam://open/keyboard deeplink on text focus.
- PR5: scripts/qbz-add-to-steam (stdlib-only, 19/19 unit tests) with
  artwork assets + pure-gamepad controller layout.

Spec: qbz-nix-docs/steam-deck/STEAM_DECK_GAME_MODE_PLAN.md

km
2026-07-25 12:04:58 -06:00

235 lines
11 KiB
Plaintext

// KioskLocalLibrary — lightweight kiosk Local Library (2.0.2 frente #3). Reads
// the same LocalLibraryState the desktop LocalLibraryView reads (3 sources
// unified: local / offline / plex). Tabs Albums / Artists / Folders / Tracks,
// rendered with the shared kiosk cards. Drives LocalLibraryActions directly
// (open-album routes to ContentView.local-album in Rust). v1 simplifications:
// no album-window / tracks-load-more hooks yet (first band loads), folders as a
// flat grid.
//
// Keyboard/gamepad nav (PR 2): same model as KioskLibrary — the index space
// is the 4 tabs followed by the active tab's items as a uniform grid
// (tracks = a 1-column list). The view publishes the geometry; containers
// mirror the focus index and answer the Enter pulse.
import { ListView } from "std-widgets.slint";
import { Theme } from "../foundation/semantic-colors.slint";
import { Radius } from "../foundation/radius.slint";
import { LocalLibraryState, LocalLibraryActions, KioskNavState } from "../state.slint";
import { KioskAlbumGrid } from "KioskAlbumGrid.slint";
import { KioskArtistCard } from "KioskArtistCard.slint";
import { KioskTrackRow } from "KioskTrackRow.slint";
component LLTab inherits Rectangle {
in property <string> label;
in property <string> id;
// Keyboard/gamepad nav (PR 2): this tab holds the shell focus ring.
in property <bool> nav-focused: false;
callback picked(string);
property <bool> active: LocalLibraryState.active-tab == root.id;
horizontal-stretch: 0;
border-width: root.nav-focused ? 2px : 0px;
border-color: Theme.accent;
border-radius: Radius.sm;
HorizontalLayout {
padding-left: 2px;
padding-right: 2px;
VerticalLayout {
Text {
text: root.label;
color: root.active ? Theme.text-primary : Theme.text-muted;
font-size: 15px;
font-weight: 600;
vertical-alignment: center;
}
Rectangle {
height: 2px;
background: root.active ? Theme.accent : transparent;
border-radius: 2px;
}
}
}
ta := TouchArea {
clicked => {
root.picked(root.id);
}
}
}
export component KioskLocalLibrary inherits Rectangle {
property <length> pad: 16px;
// ---- Nav geometry publish (PR 2): 4 tabs + the active tab's items.
function publish-nav() {
KioskNavState.tabs = 4;
KioskNavState.shelves = false;
if (LocalLibraryState.active-tab == "albums") {
KioskNavState.columns = 6;
KioskNavState.count = 4 + LocalLibraryState.albums-visible.length;
} else if (LocalLibraryState.active-tab == "artists") {
KioskNavState.columns = 7;
KioskNavState.count = 4 + LocalLibraryState.artists.length;
} else if (LocalLibraryState.active-tab == "folders") {
KioskNavState.columns = 6;
KioskNavState.count = 4 + LocalLibraryState.folders-visible.length;
} else {
KioskNavState.columns = 1;
KioskNavState.count = 4 + LocalLibraryState.tracks-visible.length;
}
KioskNavState.index = Math.max(0, Math.min(KioskNavState.index, KioskNavState.count - 1));
}
init => {
root.publish-nav();
}
property <string> nav-tab-probe: LocalLibraryState.active-tab;
changed nav-tab-probe => {
root.publish-nav();
}
property <int> nav-len-probe: LocalLibraryState.albums-visible.length
+ LocalLibraryState.artists.length
+ LocalLibraryState.folders-visible.length
+ LocalLibraryState.tracks-visible.length;
changed nav-len-probe => {
root.publish-nav();
}
// Enter on a tab → the same switch the tab TouchAreas drive.
property <int> act-probe: KioskNavState.activate-seq;
changed act-probe => {
if (KioskNavState.nav-active && KioskNavState.zone == "content"
&& KioskNavState.index < KioskNavState.tabs) {
if (KioskNavState.index == 0) {
LocalLibraryActions.select-tab("albums");
} else if (KioskNavState.index == 1) {
LocalLibraryActions.select-tab("artists");
} else if (KioskNavState.index == 2) {
LocalLibraryActions.select-tab("folders");
} else if (KioskNavState.index == 3) {
LocalLibraryActions.select-tab("tracks");
}
}
}
VerticalLayout {
spacing: 0px;
Rectangle {
height: 48px;
background: Theme.surface-main;
HorizontalLayout {
padding-left: root.pad;
padding-right: root.pad;
spacing: 22px;
alignment: start;
LLTab { label: @tr("Albums"); id: "albums"; nav-focused: KioskNavState.nav-active && KioskNavState.zone == "content" && KioskNavState.index == 0; picked(t) => { LocalLibraryActions.select-tab(t); } }
LLTab { label: @tr("Artists"); id: "artists"; nav-focused: KioskNavState.nav-active && KioskNavState.zone == "content" && KioskNavState.index == 1; picked(t) => { LocalLibraryActions.select-tab(t); } }
LLTab { label: @tr("Folders"); id: "folders"; nav-focused: KioskNavState.nav-active && KioskNavState.zone == "content" && KioskNavState.index == 2; picked(t) => { LocalLibraryActions.select-tab(t); } }
LLTab { label: @tr("Tracks"); id: "tracks"; nav-focused: KioskNavState.nav-active && KioskNavState.zone == "content" && KioskNavState.index == 3; picked(t) => { LocalLibraryActions.select-tab(t); } }
}
Rectangle {
y: parent.height - 1px;
height: 1px;
background: Theme.border-subtle;
}
}
content := Rectangle {
vertical-stretch: 1;
clip: true;
if LocalLibraryState.active-tab == "albums": KioskAlbumGrid {
albums: LocalLibraryState.albums-visible;
open(id) => {
LocalLibraryActions.open-album(id);
}
}
if LocalLibraryState.active-tab == "folders": KioskAlbumGrid {
albums: LocalLibraryState.folders-visible;
open(id) => {
LocalLibraryActions.open-album(id);
}
}
if LocalLibraryState.active-tab == "artists": arts := Flickable {
property <int> cols: 7;
property <length> gap: 14px;
property <length> cell: (self.width - 2 * root.pad - (self.cols - 1) * self.gap) / self.cols;
viewport-width: self.width;
viewport-height: Math.ceil(LocalLibraryState.artists.length / self.cols) * (self.cell + 26px + self.gap) + root.pad;
// PR 2 — focus ring + Enter + scroll-into-view.
property <int> focused-item: KioskNavState.index - KioskNavState.tabs;
property <bool> item-focused: KioskNavState.nav-active
&& KioskNavState.zone == "content"
&& self.focused-item >= 0
&& self.focused-item < LocalLibraryState.artists.length;
property <length> focus-top: root.pad + Math.floor(self.focused-item / self.cols) * (self.cell + 26px + self.gap);
property <int> nav-index-probe: KioskNavState.index;
changed nav-index-probe => {
if (self.item-focused) {
if (self.focus-top < -self.viewport-y) {
self.viewport-y = -(self.focus-top - 8px);
} else if (self.focus-top + self.cell + 26px > -self.viewport-y + self.height) {
self.viewport-y = -(self.focus-top + self.cell + 26px - self.height + 8px);
}
}
}
property <int> act-probe: KioskNavState.activate-seq;
changed act-probe => {
if (self.item-focused) {
// The TouchArea path passes the artist NAME as id.
LocalLibraryActions.open-artist(LocalLibraryState.artists[self.focused-item].name);
}
}
Rectangle {
for artist[i] in LocalLibraryState.artists: KioskArtistCard {
x: root.pad + Math.mod(i, arts.cols) * (arts.cell + arts.gap);
y: root.pad + Math.floor(i / arts.cols) * (arts.cell + 26px + arts.gap);
size: arts.cell;
id: artist.name;
name: artist.display-name;
avatar: artist.image;
nav-focused: arts.item-focused && arts.focused-item == i;
clicked(id) => {
LocalLibraryActions.open-artist(id);
}
}
}
}
if LocalLibraryState.active-tab == "tracks": tracks-list := ListView {
// PR 2 — focus ring + Enter + scroll-into-view (62px rows).
property <int> focused-item: KioskNavState.index - KioskNavState.tabs;
property <bool> item-focused: KioskNavState.nav-active
&& KioskNavState.zone == "content"
&& self.focused-item >= 0
&& self.focused-item < LocalLibraryState.tracks-visible.length;
property <int> nav-index-probe: KioskNavState.index;
changed nav-index-probe => {
if (self.item-focused) {
if (self.focused-item * 62px < -self.viewport-y) {
self.viewport-y = -(self.focused-item * 62px - 8px);
} else if (self.focused-item * 62px + 62px > -self.viewport-y + self.height) {
self.viewport-y = -(self.focused-item * 62px + 62px - self.height + 8px);
}
}
}
property <int> act-probe: KioskNavState.activate-seq;
changed act-probe => {
if (self.item-focused) {
LocalLibraryActions.track-action(LocalLibraryState.tracks-visible[self.focused-item].id, "play");
}
}
for track[i] in LocalLibraryState.tracks-visible: KioskTrackRow {
track: track;
nav-focused: tracks-list.item-focused && tracks-list.focused-item == i;
play(id) => {
LocalLibraryActions.track-action(id, "play");
}
}
}
}
}
}