From fe043154613e54316af6c493b12ca9fe8ddecd57 Mon Sep 17 00:00:00 2001 From: xXJsonDeruloXx Date: Tue, 29 Sep 2026 08:29:09 -0400 Subject: [PATCH] feat: Flatpak games on the desktop, Store apps on the Desktop page, safer remove --- .../com/droiddeck/launcher/SessionActivity.kt | 7 ++- .../launcher/runtime/BwrapSpawner.kt | 4 ++ .../droiddeck/launcher/store/StoreState.kt | 5 +- .../droiddeck/launcher/ui/FrontEndContent.kt | 1 + .../com/droiddeck/launcher/ui/StorePage.kt | 58 ++++++++++++++++++- tools/linuxfs/desktop/droiddeck-desktop-gpu | 21 +++++-- .../usr/local/bin/bannerlator-flatpak-run | 6 +- 7 files changed, 90 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 82d9f86e6..f077fe025 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -928,8 +928,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { return } // It stays until the user leaves: a failure read against a timer is a failure not read. + val what = when (SessionState.mode) { + SessionService.MODE_RUN -> com.droiddeck.launcher.frontend.Library.nameForProgram(SessionState.program) ?: "The program" + SessionService.MODE_DESKTOP -> "The desktop" + else -> "Steam" + } loading.showEnded( - hint ?: "Steam stopped unexpectedly. Share the logs with a bug report, or try again.", + hint ?: "$what stopped unexpectedly. Share the logs with a bug report, or try again.", "Exit status $status · ${SessionState.logFile?.path ?: "no log"}", ) focusEndedScreen() diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/BwrapSpawner.kt b/app/src/main/java/com/droiddeck/launcher/runtime/BwrapSpawner.kt index 89ca5826f..f5fc7dc17 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/BwrapSpawner.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/BwrapSpawner.kt @@ -231,6 +231,10 @@ object BwrapSpawner { val driver = File(lib, "libvulkan_freedreno.so") if (!driver.isFile || !File("/dev/kgsl-3d0").exists()) return null if (env.containsKey("VK_ICD_FILENAMES") || env.containsKey("VK_DRIVER_FILES")) return null + // A window on the desktop while labwc composites with pixman gets shared-memory buffers + // only; Zink cannot present there, so such an app keeps Flathub's own Mesa (llvmpipe). + // From the desktop, games go through droiddeck-gpu's gamescope and do get the GPU. + if (env["WLR_RENDERER"] == "pixman" && env["GAMESCOPE_WAYLAND_DISPLAY"] == null) return null val binds = ArrayList() for (name in listOf("libvulkan_freedreno.so", "libdisplay-info.so.3", "libSPIRV-Tools.so", "libSPIRV-Tools-opt.so")) { val f = File(lib, name) diff --git a/app/src/main/java/com/droiddeck/launcher/store/StoreState.kt b/app/src/main/java/com/droiddeck/launcher/store/StoreState.kt index e844a9e65..1564194df 100644 --- a/app/src/main/java/com/droiddeck/launcher/store/StoreState.kt +++ b/app/src/main/java/com/droiddeck/launcher/store/StoreState.kt @@ -25,6 +25,9 @@ object StoreState { private set var checkingUpdates by mutableStateOf(false) private set + /** Flathub has been asked this session, so an empty [updates] means up to date. */ + var updatesChecked by mutableStateOf(false) + private set /** What is running: "setup", an app id, or "update-all"; null when idle. */ var busy by mutableStateOf(null) private set @@ -132,7 +135,7 @@ object StoreState { val u = FlatpakManager.updates(app) main.post { checkingUpdates = false - if (u != null) updates = u else Toast.makeText(app, "Could not check Flathub for updates", Toast.LENGTH_SHORT).show() + if (u != null) { updates = u; updatesChecked = true } else Toast.makeText(app, "Could not check Flathub for updates", Toast.LENGTH_SHORT).show() } }, "store-updates").start() } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndContent.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndContent.kt index e183763af..ef9e1e288 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndContent.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndContent.kt @@ -197,6 +197,7 @@ private fun Content( Rise(3) { SectionTitle("Emulators", "${installed.size} installed") } Rise(4) { EmulatorGrid(installed, first = true, onSelect = onSelect) } } + Rise(5) { InstalledAppsGrid(a) } if (available.isNotEmpty()) { Rise(5) { SectionTitle("Available to install", available.size.toString()) } Rise(6) { EmulatorGrid(available, first = installed.isEmpty(), onSelect = onSelect) } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/StorePage.kt b/app/src/main/java/com/droiddeck/launcher/ui/StorePage.kt index 1cd283f5a..7f460e023 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/StorePage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/StorePage.kt @@ -181,7 +181,13 @@ private fun Discover(onOpen: (String) -> Unit, onCategory: (String) -> Unit) { @Composable private fun Search(query: String, category: String?, onQuery: (String) -> Unit, onCategory: (String?) -> Unit, onOpen: (String) -> Unit) { - val run = { StoreState.search(query.trim(), category) } + val view = androidx.compose.ui.platform.LocalView.current + val run = { + // The field is an Android EditText; Done leaves its keyboard over the results otherwise. + (view.context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE) as? android.view.inputmethod.InputMethodManager) + ?.hideSoftInputFromWindow(view.windowToken, 0) + StoreState.search(query.trim(), category) + } Rise(3) { Row(verticalAlignment = Alignment.Bottom, horizontalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.fillMaxWidth().padding(top = 12.dp)) { AdbTextField( @@ -224,7 +230,7 @@ private fun Installed(a: FrontEndActions, onOpen: (String) -> Unit) { } if (StoreState.updates.isNotEmpty()) PrimaryButton("Update all (${StoreState.updates.size})", enabled = StoreState.busy == null) { StoreState.update(ctx, null, "Updates") - } + } else if (StoreState.updatesChecked && !StoreState.checkingUpdates) ActionChip("● Everything is up to date", ok = true) } } if (apps.isEmpty()) { @@ -282,12 +288,18 @@ private fun AppDetail(s: FrontEndState, a: FrontEndActions, id: String, onBack: } val busyHere = StoreState.busy == id val installed = local != null + // Remove asks twice: one stray press of A should not cost a download. The second press has + // to come within a few seconds; the app's own data in ~/.var/app stays either way. + var confirmRemove by remember(id) { mutableStateOf(false) } + LaunchedEffect(confirmRemove) { if (confirmRemove) { kotlinx.coroutines.delay(4000); confirmRemove = false } } Rise(2) { Actions { if (installed) { PrimaryButton("Open", enabled = !busyHere, main = true) { a.onFlatpakApp(id, name) } if (id in StoreState.updates) SecondaryButton("Update", enabled = StoreState.busy == null) { StoreState.update(ctx, id, name) } - SecondaryButton(if (busyHere) "Working…" else "Remove", enabled = StoreState.busy == null) { StoreState.uninstall(ctx, id, name) } + SecondaryButton(if (busyHere) "Working…" else if (confirmRemove) "Press again to remove" else "Remove", enabled = StoreState.busy == null) { + if (confirmRemove) { confirmRemove = false; StoreState.uninstall(ctx, id, name) } else confirmRemove = true + } } else { PrimaryButton( if (busyHere) "Installing…" else "Install", main = true, @@ -423,3 +435,43 @@ private fun PillButton(label: String, selected: Boolean, onClick: () -> Unit) { .padding(horizontal = 14.dp, vertical = 9.dp), ) } + +/** The apps installed from the Store, as launch tiles - on the Desktop page beside the emulators. */ +@Composable +internal fun InstalledAppsGrid(a: FrontEndActions) { + val ctx = LocalContext.current + LaunchedEffect(Unit) { StoreState.refresh(ctx) } + val apps = StoreState.installed + if (apps.isEmpty()) return + val colors = MaterialTheme.colorScheme + val pal = LocalPalette.current + val columns = if (LocalNarrowPane.current) 1 else 3 + Column(verticalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.fillMaxWidth().padding(bottom = 8.dp)) { + SectionTitle("Apps from the Store", apps.size.toString()) + apps.chunked(columns).forEach { row -> + Row(horizontalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.fillMaxWidth().height(IntrinsicSize.Min)) { + row.forEach { app -> + key(app.id) { + val src = remember { MutableInteractionSource() } + val hot = rememberHot(src) + Row( + verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp), + modifier = Modifier.weight(1f).fillMaxHeight().paneItem("tile:flatpak:${app.id}") + .clip(Shape14).background(if (hot) pal.signal.copy(alpha = 0.10f) else colors.surface) + .border(if (hot) 2.dp else 1.dp, if (hot) pal.signal else pal.line, Shape14) + .hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, role = Role.Button) { a.onFlatpakApp(app.id, app.name) } + .padding(horizontal = 12.dp, vertical = 10.dp), + ) { + AppIcon(app.icon ?: StoreState.details[app.id]?.icon ?: FlathubApi.iconUrl(app.id), app.name, 44) + Column(modifier = Modifier.weight(1f)) { + Text(app.name, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis) + Text(app.summary ?: "Flatpak", fontSize = 13.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis) + } + } + } + } + repeat(columns - row.size) { Spacer(Modifier.weight(1f)) } + } + } + } +} diff --git a/tools/linuxfs/desktop/droiddeck-desktop-gpu b/tools/linuxfs/desktop/droiddeck-desktop-gpu index 08d280aec..4a53b3d4e 100644 --- a/tools/linuxfs/desktop/droiddeck-desktop-gpu +++ b/tools/linuxfs/desktop/droiddeck-desktop-gpu @@ -12,6 +12,8 @@ import re HOME = os.environ.get("HOME", "/root") SYSTEM_DIR = "/usr/share/applications" +# Flathub's games, as Flatpak exports them; the copies here win over these as they do over the system's. +FLATPAK_DIR = os.path.join(HOME, ".local/share/flatpak/exports/share/applications") USER_DIR = os.path.join(HOME, ".local/share/applications") MARK = "X-DroidDeck-GPU=1" # The client and its games already hand themselves to the app (bannerlator-steam-launch). @@ -37,6 +39,14 @@ def main_group(text): return lines[:start + 1], lines[start + 1:end], lines[end:] +def gpu_exec(exec_line): + """The Exec that runs a program on the GPU; a Flatpak app goes through its launcher, which + keeps it on gamescope's X server instead of the desktop's Wayland socket.""" + if exec_line.startswith("/usr/bin/flatpak run ") or exec_line.startswith("flatpak run "): + exec_line = "/usr/local/bin/bannerlator-flatpak-run " + exec_line.split(" run ", 1)[1] + return "droiddeck-gpu " + exec_line + + def wrap(text): head, group, rest = main_group(text) if group is None: @@ -59,7 +69,7 @@ def wrap(text): for l in group: k = l.split("=", 1)[0].strip() if "=" in l else None if k == "Exec": - out_group.append("Exec=droiddeck-gpu " + exec_line) + out_group.append("Exec=" + gpu_exec(exec_line)) elif k == "Actions": continue else: @@ -73,7 +83,7 @@ def wrap(text): wrapped_rest = [] for l in rest: if l.startswith("Exec=") and not l[5:].startswith("droiddeck-gpu "): - l = "Exec=droiddeck-gpu " + l[5:] + l = "Exec=" + gpu_exec(l[5:]) wrapped_rest.append(l) if wrapped_rest and wrapped_rest[0].strip(): wrapped_rest.insert(0, "") @@ -92,8 +102,9 @@ def main(): on = enabled() os.makedirs(USER_DIR, exist_ok=True) written = set() - if on and os.path.isdir(SYSTEM_DIR): - for name in sorted(os.listdir(SYSTEM_DIR)): + sources = [d for d in (SYSTEM_DIR, FLATPAK_DIR) if os.path.isdir(d)] if on else [] + for source in sources: + for name in sorted(os.listdir(source)): if not name.endswith(".desktop") or SKIP.match(name): continue target = os.path.join(USER_DIR, name) @@ -101,7 +112,7 @@ def main(): if os.path.exists(target) and not ours(target): continue try: - with open(os.path.join(SYSTEM_DIR, name), encoding="utf-8", errors="replace") as f: + with open(os.path.join(source, name), encoding="utf-8", errors="replace") as f: text = wrap(f.read()) except OSError: continue diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-flatpak-run b/tools/linuxfs/overlay/usr/local/bin/bannerlator-flatpak-run index 87f30a754..d7ffb149b 100644 --- a/tools/linuxfs/overlay/usr/local/bin/bannerlator-flatpak-run +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-flatpak-run @@ -9,9 +9,11 @@ case ":${XDG_DATA_DIRS:-}:" in esac # gamescope manages X windows. Flatpak would hand an app the app's own Wayland socket instead (it # finds wayland-0 in the runtime directory even with WAYLAND_DISPLAY unset), and the window would -# open behind gamescope - or not at all, with SDL told to use X11. So under gamescope: X11 only. +# open behind gamescope - or not at all, with SDL told to use X11. So under gamescope - a program's +# session (BL_INSIDE), or droiddeck-gpu from the desktop (GAMESCOPE_WAYLAND_DISPLAY) - X11 only. +# Its own flatpak options (--branch, --command, from a menu entry) come first, then the app id. socket=() -if [ -n "${BL_INSIDE:-}" ]; then +if [ -n "${BL_INSIDE:-}" ] || [ -n "${GAMESCOPE_WAYLAND_DISPLAY:-}" ]; then unset WAYLAND_DISPLAY socket=(--nosocket=wayland --socket=x11) fi