Files
qbz/crates/qbz-ui/ui/shell/KioskSearch.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

580 lines
27 KiB
Plaintext

// KioskSearch — lightweight kiosk Search results (2.0.2 frente #3).
//
// Reads the SAME SearchState the desktop SearchResultsView reads (albums,
// tracks, artists, playlists + tab int), rendered with the simple kiosk cards.
// The query is entered in the KioskShell back-bar field (SearchActions.submit);
// this view is the tabbed results. Covers are push-only, so binding the shared
// arrays is enough.
import { ListView } from "std-widgets.slint";
import { Theme } from "../foundation/semantic-colors.slint";
import { Radius } from "../foundation/radius.slint";
import { SearchState, SearchActions, KioskNavState } from "../state.slint";
import { KioskAlbumGrid } from "KioskAlbumGrid.slint";
import { KioskArtistCard } from "KioskArtistCard.slint";
import { KioskTrackRow } from "KioskTrackRow.slint";
import { KioskCard } from "KioskCard.slint";
component SearchTab inherits Rectangle {
in property <string> label;
in property <int> index;
// Keyboard/gamepad nav (PR 2): this tab holds the shell focus ring.
in property <bool> nav-focused: false;
callback picked(int);
property <bool> active: SearchState.tab == root.index;
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.index);
}
}
}
// Section header for the All dashboard — title on the left, an optional
// "View all" affordance on the right that jumps to that type's tab.
component SectionHeader inherits Rectangle {
in property <string> title;
in property <bool> show-all: true;
callback view-all;
height: 34px;
HorizontalLayout {
Text {
text: root.title;
color: Theme.text-primary;
font-size: 18px;
font-weight: 700;
vertical-alignment: center;
}
Rectangle {
horizontal-stretch: 1;
}
if root.show-all: Rectangle {
width: 74px;
Text {
text: @tr("View all");
color: Theme.accent;
font-size: 13px;
font-weight: 600;
horizontal-alignment: right;
vertical-alignment: center;
}
va-ta := TouchArea {
clicked => {
root.view-all();
}
}
}
}
}
export component KioskSearch inherits Rectangle {
callback open-album(string);
callback open-artist(string);
callback media-action(string, string, string);
property <length> pad: 16px;
// ---- Keyboard/gamepad nav (PR 2). The index space is the 5 tabs
// (All/Albums/Tracks/Artists/Playlists) followed by the active tab's
// items as a uniform grid. The All dashboard publishes NO items in v1
// (tabs only — its hero/preview mosaic isn't a uniform grid); the tab
// strips remain fully reachable. Containers mirror the focus index and
// answer the Enter pulse; the albums grid wires itself (KioskAlbumGrid).
function publish-nav() {
KioskNavState.tabs = 5;
KioskNavState.shelves = false;
if (SearchState.tab == 1) {
KioskNavState.columns = 6;
KioskNavState.count = 5 + SearchState.albums.length;
} else if (SearchState.tab == 2) {
KioskNavState.columns = 1;
KioskNavState.count = 5 + SearchState.tracks.length;
} else if (SearchState.tab == 3) {
KioskNavState.columns = 7;
KioskNavState.count = 5 + SearchState.artists.length;
} else if (SearchState.tab == 4) {
KioskNavState.columns = 6;
KioskNavState.count = 5 + SearchState.playlists.length;
} else {
KioskNavState.columns = 1;
KioskNavState.count = 5;
}
KioskNavState.index = Math.max(0, Math.min(KioskNavState.index, KioskNavState.count - 1));
}
init => {
root.publish-nav();
}
property <int> nav-tab-probe: SearchState.tab;
changed nav-tab-probe => {
root.publish-nav();
}
property <int> nav-len-probe: SearchState.albums.length + SearchState.tracks.length
+ SearchState.artists.length + SearchState.playlists.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) {
SearchActions.tab-changed(KioskNavState.index);
}
}
VerticalLayout {
spacing: 0px;
// Tabs — All / Albums / Tracks / Artists / Playlists.
Rectangle {
height: 48px;
background: Theme.surface-main;
HorizontalLayout {
padding-left: root.pad;
padding-right: root.pad;
spacing: 22px;
alignment: start;
SearchTab { label: @tr("All"); index: 0; nav-focused: KioskNavState.nav-active && KioskNavState.zone == "content" && KioskNavState.index == 0; picked(i) => { SearchActions.tab-changed(i); } }
SearchTab { label: @tr("Albums"); index: 1; nav-focused: KioskNavState.nav-active && KioskNavState.zone == "content" && KioskNavState.index == 1; picked(i) => { SearchActions.tab-changed(i); } }
SearchTab { label: @tr("Tracks"); index: 2; nav-focused: KioskNavState.nav-active && KioskNavState.zone == "content" && KioskNavState.index == 2; picked(i) => { SearchActions.tab-changed(i); } }
SearchTab { label: @tr("Artists"); index: 3; nav-focused: KioskNavState.nav-active && KioskNavState.zone == "content" && KioskNavState.index == 3; picked(i) => { SearchActions.tab-changed(i); } }
SearchTab { label: @tr("Playlists"); index: 4; nav-focused: KioskNavState.nav-active && KioskNavState.zone == "content" && KioskNavState.index == 4; picked(i) => { SearchActions.tab-changed(i); } }
}
Rectangle {
y: parent.height - 1px;
height: 1px;
background: Theme.border-subtle;
}
}
// Content.
content := Rectangle {
vertical-stretch: 1;
clip: true;
// All — a dashboard (NOT a flat album grid): Most-popular hero +
// per-type previews, each with "View all" jumping to that tab.
// Mirrors the desktop SearchResultsView hierarchy; reads SearchState
// verbatim (no local re-ranking — the hero order is Qobuz's own
// most_popular block, same as desktop).
if SearchState.tab == 0: Flickable {
viewport-width: self.width;
viewport-height: dash.preferred-height;
dash := VerticalLayout {
padding: root.pad;
spacing: 26px;
alignment: start;
// Most-popular hero — polymorphic on most-popular-kind.
if SearchState.most-popular-kind != "": VerticalLayout {
spacing: 10px;
HorizontalLayout {
alignment: start;
spacing: 8px;
Image {
source: @image-url("../assets/icons/crown.svg");
colorize: #ffd24a;
width: 18px;
height: 18px;
}
Text {
text: @tr("Most popular");
color: Theme.text-secondary;
font-size: 14px;
font-weight: 700;
vertical-alignment: center;
}
}
HorizontalLayout {
alignment: start;
if SearchState.most-popular-kind == "artist": KioskArtistCard {
size: 150px;
id: SearchState.most-popular-artist.id;
name: SearchState.most-popular-artist.title;
avatar: SearchState.most-popular-artist.artwork;
clicked(id) => {
root.open-artist(id);
}
}
if SearchState.most-popular-kind == "album": KioskCard {
art-size: 150px;
album: SearchState.most-popular-album;
clicked(id) => {
root.open-album(id);
}
}
if SearchState.most-popular-kind == "track": Rectangle {
width: 380px;
height: 96px;
border-radius: Radius.md;
background: Theme.surface-card;
HorizontalLayout {
padding: 8px;
spacing: 12px;
Rectangle {
width: 80px;
height: 80px;
border-radius: Radius.sm;
background: Theme.surface-elevated;
clip: true;
if SearchState.most-popular-track.artwork.width > 0: Image {
width: 100%;
height: 100%;
source: SearchState.most-popular-track.artwork;
image-fit: cover;
}
}
VerticalLayout {
alignment: center;
spacing: 3px;
Text {
text: SearchState.most-popular-track.title;
color: Theme.text-primary;
font-size: 16px;
font-weight: 700;
overflow: elide;
wrap: no-wrap;
}
Text {
text: SearchState.most-popular-track.artist;
color: Theme.text-secondary;
font-size: 13px;
overflow: elide;
wrap: no-wrap;
}
if SearchState.most-popular-quality-label != "": Text {
text: SearchState.most-popular-quality-label;
color: Theme.text-muted;
font-size: 11px;
}
}
}
hero-track-ta := TouchArea {
clicked => {
root.media-action("track", SearchState.most-popular-track.id, "play");
}
}
}
}
}
// Artists preview (hero-deduped list).
if SearchState.artists-carousel.length > 0: VerticalLayout {
spacing: 10px;
SectionHeader {
title: @tr("Artists");
view-all => {
SearchActions.tab-changed(3);
}
}
HorizontalLayout {
spacing: 0px;
alignment: start;
for artist[i] in SearchState.artists-carousel: HorizontalLayout {
if i < 6: HorizontalLayout {
padding-right: 14px;
KioskArtistCard {
size: 120px;
id: artist.id;
name: artist.title;
avatar: artist.artwork;
clicked(id) => {
root.open-artist(id);
}
}
}
}
}
}
// Albums preview.
if SearchState.albums.length > 0: VerticalLayout {
spacing: 10px;
SectionHeader {
title: @tr("Albums");
view-all => {
SearchActions.tab-changed(1);
}
}
HorizontalLayout {
spacing: 0px;
alignment: start;
for album[i] in SearchState.albums: HorizontalLayout {
if i < 6: HorizontalLayout {
padding-right: 14px;
KioskCard {
art-size: 140px;
album: album;
clicked(id) => {
root.open-album(id);
}
}
}
}
}
}
// Tracks preview (capped at 6).
if SearchState.tracks.length > 0: VerticalLayout {
spacing: 6px;
SectionHeader {
title: @tr("Tracks");
show-all: SearchState.tracks-total > 6;
view-all => {
SearchActions.tab-changed(2);
}
}
for track[i] in SearchState.tracks: VerticalLayout {
if i < 6: KioskTrackRow {
track: track;
play(id) => {
root.media-action("track", id, "play");
}
}
}
}
// Playlists preview.
if SearchState.playlists.length > 0: VerticalLayout {
spacing: 10px;
SectionHeader {
title: @tr("Playlists");
view-all => {
SearchActions.tab-changed(4);
}
}
HorizontalLayout {
spacing: 0px;
alignment: start;
for pl[i] in SearchState.playlists: HorizontalLayout {
if i < 6: HorizontalLayout {
padding-right: 14px;
Rectangle {
width: 140px;
VerticalLayout {
alignment: start;
spacing: 7px;
Rectangle {
width: 140px;
height: 140px;
border-radius: Radius.sm;
background: Theme.surface-elevated;
clip: true;
Image {
width: 100%;
height: 100%;
source: pl.cover1;
image-fit: cover;
}
}
Text {
text: pl.title;
color: Theme.text-primary;
font-size: 13px;
font-weight: 600;
overflow: elide;
wrap: no-wrap;
}
}
pl-prev-ta := TouchArea {
clicked => {
root.media-action("playlist", pl.id, "open");
}
}
}
}
}
}
}
}
}
// Albums tab — full grid.
if SearchState.tab == 1: KioskAlbumGrid {
albums: SearchState.albums;
open(id) => {
root.open-album(id);
}
}
// Tracks — windowed list (ListView mounts only the visible band).
if SearchState.tab == 2: 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 < SearchState.tracks.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) {
root.media-action("track", SearchState.tracks[self.focused-item].id, "play");
}
}
for track[i] in SearchState.tracks: KioskTrackRow {
track: track;
nav-focused: tracks-list.item-focused && tracks-list.focused-item == i;
play(id) => {
root.media-action("track", id, "play");
}
}
}
// Artists — round-card wrapping grid.
if SearchState.tab == 3: agrid := 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(SearchState.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 < SearchState.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) {
root.open-artist(SearchState.artists[self.focused-item].id);
}
}
Rectangle {
for artist[i] in SearchState.artists: KioskArtistCard {
x: root.pad + Math.mod(i, agrid.cols) * (agrid.cell + agrid.gap);
y: root.pad + Math.floor(i / agrid.cols) * (agrid.cell + 26px + agrid.gap);
size: agrid.cell;
id: artist.id;
name: artist.title;
avatar: artist.artwork;
nav-focused: agrid.item-focused && agrid.focused-item == i;
clicked(id) => {
root.open-artist(id);
}
}
}
}
// Playlists — square cover grid (uses the first collage cover).
if SearchState.tab == 4: pgrid := Flickable {
property <int> cols: 6;
property <length> gap: 16px;
property <length> cell: (self.width - 2 * root.pad - (self.cols - 1) * self.gap) / self.cols;
viewport-width: self.width;
viewport-height: Math.ceil(SearchState.playlists.length / self.cols) * (self.cell + 42px + 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 < SearchState.playlists.length;
property <length> focus-top: root.pad + Math.floor(self.focused-item / self.cols) * (self.cell + 42px + 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 + 42px > -self.viewport-y + self.height) {
self.viewport-y = -(self.focus-top + self.cell + 42px - self.height + 8px);
}
}
}
property <int> act-probe: KioskNavState.activate-seq;
changed act-probe => {
if (self.item-focused) {
root.media-action("playlist", SearchState.playlists[self.focused-item].id, "open");
}
}
Rectangle {
for pl[i] in SearchState.playlists: Rectangle {
x: root.pad + Math.mod(i, pgrid.cols) * (pgrid.cell + pgrid.gap);
y: root.pad + Math.floor(i / pgrid.cols) * (pgrid.cell + 42px + pgrid.gap);
width: pgrid.cell;
border-width: pgrid.item-focused && pgrid.focused-item == i ? 3px : 0px;
border-color: Theme.accent;
border-radius: Radius.sm;
background: pgrid.item-focused && pgrid.focused-item == i ? Theme.accent.with-alpha(0.12) : transparent;
VerticalLayout {
alignment: start;
spacing: 7px;
Rectangle {
width: parent.width;
height: parent.width;
border-radius: Radius.sm;
background: Theme.surface-elevated;
clip: true;
Image {
width: 100%;
height: 100%;
source: pl.cover1;
image-fit: cover;
}
}
Text {
text: pl.title;
color: Theme.text-primary;
font-size: 14px;
font-weight: 600;
overflow: elide;
wrap: no-wrap;
}
}
pl-ta := TouchArea {
clicked => {
root.media-action("playlist", pl.id, "open");
}
}
}
}
}
}
}
}