diff --git a/README.md b/README.md index 4cdb225463..f6437a72d7 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,22 @@ client sees one pad either way. Connect a controller and the on-screen one disap and it comes back. Anywhere the controls are not is a touchpad: touch moves the pointer and a tap clicks, which is how the client's own on-screen keyboard is used to sign in. +## Keyboard + +**Keyboard** in the drawer opens the soft keyboard over the session. Steam's UI and the games +under it are X11 clients of gamescope and know nothing of Wayland text input, so what the +keyboard produces is turned into the key presses that would have typed it — Shift included, so +capitals and the symbol row (`@`, `!`, `_` …) arrive as themselves — and fed to the compositor as +key events. A hardware keyboard works as it is. + +## Compatibility tools + +**Compatibility tools** (main screen and drawer) installs GE-Proton or proton-cachyos — native +ARM64 builds — beside the ARM64 Proton Valve ships. The runtime's own registrar downloads and +installs a requested build when the next session starts (several hundred MB), patches it past +pressure-vessel like Valve's, and it then appears in Steam under Properties → Compatibility for +any game. The dialog queues or cancels a request and removes an installed build. + ## Frame generation Extra frames are generated between the real ones on the way to the screen — inside the app's diff --git a/app/src/main/java/com/steamdeck/launcher/MainActivity.kt b/app/src/main/java/com/steamdeck/launcher/MainActivity.kt index 37e20a9e13..77e4f56110 100644 --- a/app/src/main/java/com/steamdeck/launcher/MainActivity.kt +++ b/app/src/main/java/com/steamdeck/launcher/MainActivity.kt @@ -18,6 +18,9 @@ import com.steamdeck.launcher.gpu.FrameGen import com.steamdeck.launcher.gpu.LsfgNative import com.steamdeck.launcher.runtime.LinuxRuntime import com.steamdeck.launcher.runtime.LinuxRuntimeInstaller +import com.steamdeck.launcher.session.ProtonExtras +import com.steamdeck.launcher.ui.ProtonDialog +import com.steamdeck.launcher.ui.ProtonRow import com.steamdeck.launcher.ui.ConfirmDialog import com.steamdeck.launcher.ui.CreditsDialog import com.steamdeck.launcher.ui.FrameGenDialog @@ -45,6 +48,8 @@ class MainActivity : ComponentActivity() { private var showRemove by mutableStateOf(false) private var showFrameGen by mutableStateOf(false) private var showCredits by mutableStateOf(false) + private var showProtons by mutableStateOf(false) + private var protonRows by mutableStateOf>(emptyList()) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -61,8 +66,16 @@ class MainActivity : ComponentActivity() { onPlay = { startActivity(Intent(this, SessionActivity::class.java)) }, onRuntime = { onRuntimeButton() }, onFrameGen = { showFrameGen = true }, + onProtons = { refreshProtons(); showProtons = true }, onCredits = { showCredits = true }, ) + if (showProtons) ProtonDialog( + rows = protonRows, + onInstall = { id -> ProtonExtras.tools.first { it.id == id }.let { ProtonExtras.queue(this, it) }; refreshProtons() }, + onCancel = { id -> ProtonExtras.tools.first { it.id == id }.let { ProtonExtras.unqueue(this, it) }; refreshProtons() }, + onRemove = { id -> ProtonExtras.tools.first { it.id == id }.let { ProtonExtras.remove(this, it) }; refreshProtons() }, + onDismiss = { showProtons = false }, + ) if (showRemove) ConfirmDialog( title = "Remove Linux runtime", text = "This deletes the runtime, the Steam client inside it, and every game installed there.", @@ -98,6 +111,10 @@ class MainActivity : ComponentActivity() { if (!busy) Thread({ checkCatalog() }, "catalog").start() } + private fun refreshProtons() { + protonRows = ProtonExtras.tools.map { ProtonRow(it.id, it.name, ProtonExtras.installed(this, it), ProtonExtras.queued(this, it)) } + } + private fun refresh() { installed = LinuxRuntimeInstaller.installedVersion(this) ready = LinuxRuntime.isInstalled(this) diff --git a/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt b/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt index fdba4801d3..cb993e18ff 100644 --- a/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt @@ -26,11 +26,13 @@ import com.steamdeck.launcher.gpu.FrameGen import com.steamdeck.launcher.gpu.LsfgNative import com.steamdeck.launcher.gpu.TurnipDriver import com.steamdeck.launcher.input.EvdevKeys +import com.steamdeck.launcher.input.KeyboardHost import com.steamdeck.launcher.input.OnScreenControls import com.steamdeck.launcher.input.PadBridge import com.steamdeck.launcher.runtime.LinuxRuntime import com.steamdeck.launcher.session.LoadingState import com.steamdeck.launcher.session.PerfHud +import com.steamdeck.launcher.session.ProtonExtras import com.steamdeck.launcher.session.SessionPrefs import com.steamdeck.launcher.session.SessionService import com.steamdeck.launcher.session.SessionState @@ -38,6 +40,8 @@ import com.steamdeck.launcher.ui.DrawerActions import com.steamdeck.launcher.ui.FrameGenDialog import com.steamdeck.launcher.ui.HudText import com.steamdeck.launcher.ui.LoadingOverlay +import com.steamdeck.launcher.ui.ProtonDialog +import com.steamdeck.launcher.ui.ProtonRow import com.steamdeck.launcher.ui.SessionDrawer import com.steamdeck.launcher.ui.SteamDeckTheme import com.steamdeck.launcher.wayland.CompositorHost @@ -61,11 +65,14 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { private lateinit var hud: PerfHud private var padBridge: PadBridge? = null private var onScreenControls: OnScreenControls? = null + private var keyboard: KeyboardHost? = null private var watching = true // Compose reads these; the activity writes them. private var drawerOpen by mutableStateOf(false) private var showFrameGen by mutableStateOf(false) + private var showProtons by mutableStateOf(false) + private var protonRows by mutableStateOf>(emptyList()) private var hudOn by mutableStateOf(true) private var frameGenLabel by mutableStateOf("Off") private var oscMode by mutableStateOf(SessionPrefs.OSC_AUTO) @@ -101,6 +108,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { val bridge = PadBridge(File(LinuxRuntime.sessionRoot(this), "dev/input")) padBridge = bridge onScreenControls = OnScreenControls(this, bridge).also { root.addView(it) } + keyboard = KeyboardHost(this).also { root.addView(it) } loading = LoadingState(this) hud = PerfHud(this) @@ -126,6 +134,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { shapeMode = if (shapeMode == SessionPrefs.SHAPE_WIDE) "16:9" else "panel", onHud = { on -> SessionPrefs.setHudEnabled(this@SessionActivity, on); hudOn = on; hud.refresh() }, onFrameGen = { showFrameGen = true }, + onKeyboard = { drawerOpen = false; keyboard?.toggle() }, + onProtons = { refreshProtons(); showProtons = true }, onOsc = { val next = when (SessionPrefs.oscMode(this@SessionActivity)) { SessionPrefs.OSC_AUTO -> SessionPrefs.OSC_ALWAYS @@ -146,6 +156,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { onStop = { drawerOpen = false; SessionService.stop(this@SessionActivity); finish() }, onClose = { drawerOpen = false }, )) + if (showProtons) ProtonDialog( + rows = protonRows, + onInstall = { id -> ProtonExtras.tools.first { it.id == id }.let { ProtonExtras.queue(this@SessionActivity, it) }; refreshProtons() }, + onCancel = { id -> ProtonExtras.tools.first { it.id == id }.let { ProtonExtras.unqueue(this@SessionActivity, it) }; refreshProtons() }, + onRemove = { id -> ProtonExtras.tools.first { it.id == id }.let { ProtonExtras.remove(this@SessionActivity, it) }; refreshProtons() }, + onDismiss = { showProtons = false }, + ) if (showFrameGen) FrameGenDialog( engine = FrameGen.engine(this@SessionActivity), multiplier = FrameGen.multiplier(this@SessionActivity), @@ -177,12 +194,22 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { // from a button a game might also be reading. onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) { override fun handleOnBackPressed() { - if (showFrameGen) showFrameGen = false else drawerOpen = !drawerOpen + when { + showFrameGen -> showFrameGen = false + showProtons -> showProtons = false + else -> drawerOpen = !drawerOpen + } } }) watchSession() } + private fun refreshProtons() { + protonRows = ProtonExtras.tools.map { + ProtonRow(it.id, it.name, ProtonExtras.installed(this, it), ProtonExtras.queued(this, it)) + } + } + private fun readPrefs() { hudOn = SessionPrefs.hudEnabled(this) frameGenLabel = FrameGen.label(this) @@ -336,14 +363,36 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { if (padBridge?.onKeyEvent(event) == true) return true // A hardware keyboard, forwarded to the compositor's wl_keyboard. Back is left to the // activity, which opens the drawer. - if (CompositorHost.isStarted && event.keyCode != KeyEvent.KEYCODE_BACK - && event.device != null && !PadBridge.isFromController(event.device)) { + val fromPad = event.device != null && PadBridge.isFromController(event.device) + if (CompositorHost.isStarted && event.keyCode != KeyEvent.KEYCODE_BACK && !fromPad) { val down = event.action == KeyEvent.ACTION_DOWN if (down || event.action == KeyEvent.ACTION_UP) { var evdev = EvdevKeys.fromKeyCode(event.keyCode) - if (evdev < 0 && event.scanCode > 0) evdev = event.scanCode + // What the key stands for, and the key it would sit on without Shift — non-zero + // only for a character Shift puts there: every capital and the symbol row. + val ch = event.unicodeChar + val plain = if (ch > 0) EvdevKeys.unshiftedChar(ch) else 0 + // A soft keyboard's symbol keys are in neither the table nor a scan code, so they + // reached the session as nothing at all — a sign-in took an address without its @. + // Work back from the character instead: which key carries it. + if (evdev <= 0 && ch > 0) { + val code = EvdevKeys.fromKeyCode(EvdevKeys.keycodeForChar(if (plain != 0) plain else ch)) + if (code > 0) evdev = code + } + // The modifier has to be made here. A soft keyboard reports Shift in the event's + // meta state and sends no Shift key of its own, so a capital arrives as a key this + // side already knows and came out lowercase. A hardware keyboard sends its own + // Shift, and a second one would release the modifier while the key is still held. + val shiftEvdev = if (evdev > 0 && plain != 0 && event.deviceId <= 0) 42 else 0 + if (evdev <= 0 && event.scanCode > 0) evdev = event.scanCode if (evdev > 0) { - WaylandCompositor.nativeSendKey(evdev, if (down) 1 else 0) + if (down) { + if (shiftEvdev != 0) WaylandCompositor.nativeSendKey(shiftEvdev, 1) + WaylandCompositor.nativeSendKey(evdev, 1) + } else { + WaylandCompositor.nativeSendKey(evdev, 0) + if (shiftEvdev != 0) WaylandCompositor.nativeSendKey(shiftEvdev, 0) + } return true } } @@ -419,6 +468,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { (getSystemService(INPUT_SERVICE) as? InputManager)?.unregisterInputDeviceListener(deviceListener) // A button held when the app goes away would stay held in the ring for the whole session. onScreenControls?.releaseAll() + keyboard?.takeIf { it.shown }?.hide() super.onPause() } diff --git a/app/src/main/java/com/steamdeck/launcher/input/EvdevKeys.java b/app/src/main/java/com/steamdeck/launcher/input/EvdevKeys.java index 15c8909d0b..6261c81013 100644 --- a/app/src/main/java/com/steamdeck/launcher/input/EvdevKeys.java +++ b/app/src/main/java/com/steamdeck/launcher/input/EvdevKeys.java @@ -69,4 +69,41 @@ public final class EvdevKeys { default: return -1; } } + + /** + * The character a key carries when Shift is not held, for a character that needs it - so '@' + * gives '2' and 'A' gives 'a'. Returns 0 when the character is typed without Shift, which is + * also the answer for anything this layout does not place on a key. US layout, which is what + * the session's keymap is. + */ + public static int unshiftedChar(int ch) { + if (ch >= 'A' && ch <= 'Z') return Character.toLowerCase(ch); + int at = SHIFTED_CHARS.indexOf(ch); + return at >= 0 ? PLAIN_CHARS.charAt(at) : 0; + } + + // Index-aligned: the symbol, and the key it shares with Shift held. + private static final String SHIFTED_CHARS = "!@#$%^&*()_+{}|:\"<>?~"; + private static final String PLAIN_CHARS = "1234567890-=[]\\;',./`"; + + /** The Android key code that carries an unshifted character, or 0 when nothing does. */ + public static int keycodeForChar(int ch) { + if (ch >= 'a' && ch <= 'z') return KeyEvent.KEYCODE_A + (ch - 'a'); + if (ch >= '0' && ch <= '9') return KeyEvent.KEYCODE_0 + (ch - '0'); + switch (ch) { + case '-': return KeyEvent.KEYCODE_MINUS; + case '=': return KeyEvent.KEYCODE_EQUALS; + case '[': return KeyEvent.KEYCODE_LEFT_BRACKET; + case ']': return KeyEvent.KEYCODE_RIGHT_BRACKET; + case '\\': return KeyEvent.KEYCODE_BACKSLASH; + case ';': return KeyEvent.KEYCODE_SEMICOLON; + case '\'': return KeyEvent.KEYCODE_APOSTROPHE; + case ',': return KeyEvent.KEYCODE_COMMA; + case '.': return KeyEvent.KEYCODE_PERIOD; + case '/': return KeyEvent.KEYCODE_SLASH; + case '`': return KeyEvent.KEYCODE_GRAVE; + case ' ': return KeyEvent.KEYCODE_SPACE; + default: return 0; + } + } } diff --git a/app/src/main/java/com/steamdeck/launcher/input/KeyboardHost.kt b/app/src/main/java/com/steamdeck/launcher/input/KeyboardHost.kt new file mode 100644 index 0000000000..be97cf80b2 --- /dev/null +++ b/app/src/main/java/com/steamdeck/launcher/input/KeyboardHost.kt @@ -0,0 +1,123 @@ +package com.steamdeck.launcher.input + +import android.app.Activity +import android.content.Context +import android.text.InputType +import android.view.KeyCharacterMap +import android.view.KeyEvent +import android.view.View +import android.view.inputmethod.BaseInputConnection +import android.view.inputmethod.EditorInfo +import android.view.inputmethod.InputConnection +import android.view.inputmethod.InputMethodManager + +/** + * A place for the soft keyboard to land. Steam's UI and the games under it are X11 clients of + * gamescope and know nothing of Wayland text input, so everything the keyboard produces has to + * become key events: what the IME commits as text is turned into the key presses that would have + * typed it (Shift included, from the key character map), and handed to the activity, whose key + * path turns them into evdev codes for the compositor. Backspace, Enter and the keys an IME sends + * directly go the same way. + * + * Invisible and unfocusable until asked for: a focused View would take D-pad and stick motion + * away from the pad. + */ +class KeyboardHost(private val activity: Activity) : View(activity) { + private val imm = activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager + private val map: KeyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD) + var shown = false + private set + + init { + isFocusable = false + isFocusableInTouchMode = false + visibility = VISIBLE // present in the tree, draws nothing + layoutParams = android.widget.FrameLayout.LayoutParams(1, 1) + } + + override fun onCheckIsTextEditor(): Boolean = shown + + override fun onCreateInputConnection(outAttrs: EditorInfo): InputConnection? { + if (!shown) return null + // No suggestions and no autocorrect: the keyboard sends what was pressed, key by key, which + // is what a password field on the other side needs. + outAttrs.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS or + InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD + outAttrs.imeOptions = EditorInfo.IME_ACTION_NONE or EditorInfo.IME_FLAG_NO_FULLSCREEN or + EditorInfo.IME_FLAG_NO_EXTRACT_UI + return KeyConnection() + } + + fun toggle() = if (shown) hide() else show() + + fun show() { + shown = true + isFocusable = true + isFocusableInTouchMode = true + requestFocus() + imm.restartInput(this) + imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT) + } + + fun hide() { + shown = false + imm.hideSoftInputFromWindow(windowToken, 0) + isFocusable = false + isFocusableInTouchMode = false + clearFocus() + } + + private inner class KeyConnection : BaseInputConnection(this, false) { + override fun commitText(text: CharSequence?, newCursorPosition: Int): Boolean { + if (text.isNullOrEmpty()) return true + // The key events that type this text on a US layout - a capital arrives as Shift + // down, the letter, Shift up. Characters the map cannot place are sent as a bare + // key event carrying the character, which the activity's key path works back from. + val events = map.getEvents(text.toString().toCharArray()) + if (events != null) { + for (event in events) activity.dispatchKeyEvent(event) + } else { + for (ch in text) { + val t = System.currentTimeMillis() + val down = KeyEvent(t, t, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_UNKNOWN, 0, 0, + KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, 0) + activity.dispatchKeyEvent(CharKeyEvent(down, ch)) + activity.dispatchKeyEvent(CharKeyEvent(KeyEvent.changeAction(down, KeyEvent.ACTION_UP), ch)) + } + } + return true + } + + override fun setComposingText(text: CharSequence?, newCursorPosition: Int): Boolean = true + override fun finishComposingText(): Boolean = true + + override fun deleteSurroundingText(beforeLength: Int, afterLength: Int): Boolean { + repeat(beforeLength) { tap(KeyEvent.KEYCODE_DEL) } + repeat(afterLength) { tap(KeyEvent.KEYCODE_FORWARD_DEL) } + return true + } + + override fun sendKeyEvent(event: KeyEvent): Boolean = activity.dispatchKeyEvent(event) + + override fun performEditorAction(actionCode: Int): Boolean { + tap(KeyEvent.KEYCODE_ENTER) + return true + } + + private fun tap(keyCode: Int) { + val t = System.currentTimeMillis() + activity.dispatchKeyEvent(KeyEvent(t, t, KeyEvent.ACTION_DOWN, keyCode, 0)) + activity.dispatchKeyEvent(KeyEvent(t, t, KeyEvent.ACTION_UP, keyCode, 0)) + } + + override fun getTextBeforeCursor(n: Int, flags: Int): CharSequence = "" + override fun getTextAfterCursor(n: Int, flags: Int): CharSequence = "" + override fun getSelectedText(flags: Int): CharSequence? = null + } + + /** A key event that carries a character the key map could not place. */ + private class CharKeyEvent(origin: KeyEvent, private val ch: Char) : KeyEvent(origin) { + override fun getUnicodeChar(): Int = ch.code + override fun getUnicodeChar(metaState: Int): Int = ch.code + } +} diff --git a/app/src/main/java/com/steamdeck/launcher/session/ProtonExtras.kt b/app/src/main/java/com/steamdeck/launcher/session/ProtonExtras.kt new file mode 100644 index 0000000000..0a4de51fcb --- /dev/null +++ b/app/src/main/java/com/steamdeck/launcher/session/ProtonExtras.kt @@ -0,0 +1,56 @@ +package com.steamdeck.launcher.session + +import android.content.Context +import com.steamdeck.launcher.core.FileUtils +import com.steamdeck.launcher.runtime.LinuxRuntime +import java.io.File + +/** + * Third-party Proton builds for the client — GE-Proton and proton-cachyos, both published as + * native ARM64 tarballs. The runtime's own registrar (bannerlator-proton-extra) downloads and + * installs one into the client's compatibilitytools.d and patches it past pressure-vessel; this + * side only leaves it the request, one line in ~/.bl-proton-extra, which the session script reads + * before the client starts. A line is dropped once it has succeeded; a failed download stays and + * is retried next session. Hundreds of megabytes each, so only ever on request. + */ +object ProtonExtras { + class Tool(val id: String, val name: String, val prefix: String) + + val tools = listOf( + Tool("ge", "GE-Proton", "GE-Proton"), + Tool("cachyos", "proton-cachyos", "proton-cachyos"), + ) + + private fun home(context: Context) = File(LinuxRuntime.rootDir(context), "root") + private fun requests(context: Context) = File(home(context), ".bl-proton-extra") + private fun toolsDir(context: Context) = + File(home(context), ".local/share/Steam/compatibilitytools.d") + + /** The installed build's directory name (e.g. GE-Proton11-7), or null. */ + fun installed(context: Context, tool: Tool): String? = + toolsDir(context).listFiles() + ?.filter { it.isDirectory && it.name.startsWith(tool.prefix) && File(it, "toolmanifest.vdf").isFile } + ?.maxByOrNull { it.name }?.name + + fun queued(context: Context, tool: Tool): Boolean = + requestLines(context).any { it.trim() == tool.id || it.trim().startsWith(tool.id + " ") } + + fun queue(context: Context, tool: Tool) { + if (queued(context, tool)) return + val lines = requestLines(context) + tool.id + FileUtils.writeString(requests(context), lines.joinToString("\n") + "\n") + } + + fun unqueue(context: Context, tool: Tool) { + val lines = requestLines(context).filterNot { it.trim() == tool.id || it.trim().startsWith(tool.id + " ") } + FileUtils.writeString(requests(context), if (lines.isEmpty()) "" else lines.joinToString("\n") + "\n") + } + + /** Deletes the installed build; the client forgets it on its next start. */ + fun remove(context: Context, tool: Tool) { + installed(context, tool)?.let { FileUtils.delete(File(toolsDir(context), it)) } + } + + private fun requestLines(context: Context): List = + FileUtils.readString(requests(context))?.lines()?.filter { it.isNotBlank() } ?: emptyList() +} diff --git a/app/src/main/java/com/steamdeck/launcher/ui/MainScreen.kt b/app/src/main/java/com/steamdeck/launcher/ui/MainScreen.kt index 4a4b6aae93..d20597ea47 100644 --- a/app/src/main/java/com/steamdeck/launcher/ui/MainScreen.kt +++ b/app/src/main/java/com/steamdeck/launcher/ui/MainScreen.kt @@ -59,6 +59,7 @@ fun MainScreen( onPlay: () -> Unit, onRuntime: () -> Unit, onFrameGen: () -> Unit, + onProtons: () -> Unit, onCredits: () -> Unit, ) { BoxWithConstraints( @@ -142,6 +143,10 @@ fun MainScreen( onClick = onFrameGen, modifier = Modifier.fillMaxWidth().padding(top = 5.dp * k).height(buttonHeight + 5.dp * k), ) { Text("Frame generation: ${state.frameGenLabel}", fontSize = 13.sp * k) } + OutlinedButton( + onClick = onProtons, + modifier = Modifier.fillMaxWidth().padding(top = 5.dp * k).height(buttonHeight + 5.dp * k), + ) { Text("Compatibility tools", fontSize = 13.sp * k) } Spacer(Modifier.height(10.dp * k)) Text( "by The412Banner and maxjivi05 · credits", diff --git a/app/src/main/java/com/steamdeck/launcher/ui/ProtonDialog.kt b/app/src/main/java/com/steamdeck/launcher/ui/ProtonDialog.kt new file mode 100644 index 0000000000..e9c986f5f3 --- /dev/null +++ b/app/src/main/java/com/steamdeck/launcher/ui/ProtonDialog.kt @@ -0,0 +1,70 @@ +package com.steamdeck.launcher.ui + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.AlertDialog +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp + +/** One third-party Proton as the dialog shows it. */ +class ProtonRow(val id: String, val name: String, val installed: String?, val queued: Boolean) + +/** + * GE-Proton and proton-cachyos: installed, queued for the next session, or neither. Installing + * happens inside the runtime when a session starts (a download of several hundred MB), so the + * dialog only ever queues or cancels a request, and removes an installed build. + */ +@Composable +fun ProtonDialog( + rows: List, + onInstall: (String) -> Unit, + onCancel: (String) -> Unit, + onRemove: (String) -> Unit, + onDismiss: () -> Unit, +) { + AlertDialog( + onDismissRequest = onDismiss, + title = { Text("Compatibility tools") }, + text = { + Column { + Text( + "Native ARM64 Proton builds beside the ARM64 Proton Valve ships. Installed when a session starts — a large download — and then chosen per game in Steam under Properties → Compatibility.", + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + Spacer(Modifier.height(10.dp)) + for (row in rows) { + Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp)) { + Column(modifier = Modifier.weight(1f)) { + Text(row.name, style = MaterialTheme.typography.bodyMedium) + Text( + when { + row.installed != null -> "installed: ${row.installed}" + row.queued -> "installs at the next session start" + else -> "not installed" + }, + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + } + when { + row.installed != null -> TextButton(onClick = { onRemove(row.id) }) { Text("Remove") } + row.queued -> TextButton(onClick = { onCancel(row.id) }) { Text("Cancel") } + else -> TextButton(onClick = { onInstall(row.id) }) { Text("Install") } + } + } + } + } + }, + confirmButton = { TextButton(onClick = onDismiss) { Text("OK") } }, + ) +} diff --git a/app/src/main/java/com/steamdeck/launcher/ui/SessionOverlay.kt b/app/src/main/java/com/steamdeck/launcher/ui/SessionOverlay.kt index 60c460b8c8..ad92d4f458 100644 --- a/app/src/main/java/com/steamdeck/launcher/ui/SessionOverlay.kt +++ b/app/src/main/java/com/steamdeck/launcher/ui/SessionOverlay.kt @@ -90,6 +90,8 @@ class DrawerActions( val shapeMode: String, val onHud: (Boolean) -> Unit, val onFrameGen: () -> Unit, + val onKeyboard: () -> Unit, + val onProtons: () -> Unit, val onOsc: () -> Unit, val onShape: () -> Unit, val onBackground: () -> Unit, @@ -124,9 +126,15 @@ fun SessionDrawer(a: DrawerActions) { Text("Performance HUD", color = Color(0xFFDDDDDD), fontSize = 13.sp, modifier = Modifier.weight(1f)) Switch(checked = a.hudOn, onCheckedChange = a.onHud) } - OutlinedButton(onClick = a.onFrameGen, modifier = Modifier.fillMaxWidth().padding(top = 8.dp)) { + OutlinedButton(onClick = a.onKeyboard, modifier = Modifier.fillMaxWidth().padding(top = 8.dp)) { + Text("Keyboard", fontSize = 13.sp) + } + OutlinedButton(onClick = a.onFrameGen, modifier = Modifier.fillMaxWidth().padding(top = 6.dp)) { Text("Frame generation: ${a.frameGenLabel}", fontSize = 13.sp) } + OutlinedButton(onClick = a.onProtons, modifier = Modifier.fillMaxWidth().padding(top = 6.dp)) { + Text("Compatibility tools", fontSize = 13.sp) + } OutlinedButton(onClick = a.onOsc, modifier = Modifier.fillMaxWidth().padding(top = 6.dp)) { Text("On-screen controls: ${a.oscMode}", fontSize = 13.sp) }