fix(desktop): address KDE feedback and keep local builds in sync with CI (#488)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-09 21:35:37 +00:00
1 parent c761b83112
commit d99ed8e00b
41 files changed
+1252 -191

No files matched your search

+36 -3
View File
@@ -198,6 +198,28 @@ def stageSessionScripts = tasks.register('stageSessionScripts', Copy) {
}
tasks.named('preBuild').configure { dependsOn(stageSessionScripts) }
// Prepared audio lives under build/, so native builds never rewrite the tracked base bundle.
// Copying into one asset root also prevents an old base bundle winning a duplicate asset merge.
def runtimeAssetsDir = layout.buildDirectory.dir('runtimeAssets')
def stageRuntimeAssets = tasks.register('stageRuntimeAssets', Sync) {
dependsOn(stageSessionScripts)
from(layout.projectDirectory.dir('src/main/assets')) { exclude 'pulseaudio.tzst' }
from(layout.buildDirectory.dir('prepared-assets'))
into(runtimeAssetsDir)
}
android.sourceSets.main.assets.setSrcDirs([runtimeAssetsDir])
tasks.named('preBuild').configure { dependsOn(stageRuntimeAssets) }
// Unit tests and previews remain usable without Docker. Packaging an APK requires the complete
// runtime payload prepared by the local helper or CI, with matching sources and output hashes.
def verifyRuntimeInputs = tasks.register('verifyRuntimeInputs', Exec) {
workingDir rootProject.projectDir
commandLine 'python3', 'tools/release/runtime_inputs.py', 'verify'
}
tasks.configureEach { task ->
if (task.name in ['packageDebug', 'packageRelease']) task.dependsOn(verifyRuntimeInputs)
}
// The GOG / Epic / Amazon download engines are Rust (app/src/main/rust/stores, ported from
// Bannerlator's bl-steam-client crate). cargo-ndk cross-compiles them for arm64-v8a into the build
// directory, which is one more jniLibs source below: nothing compiled is committed, the same rule
@@ -214,6 +236,11 @@ def buildRustStores = tasks.register('buildRustStores', Exec) {
onlyIf { !skipRust }
inputs.dir(rustCrateDir.dir('src'))
inputs.files(rustCrateDir.file('Cargo.toml'), rustCrateDir.file('Cargo.lock'))
inputs.property('ndkVersion', android.ndkVersion)
if (!skipRust) inputs.property('rustToolchain', providers.exec {
environment 'PATH', "${System.getProperty('user.home')}/.cargo/bin${File.pathSeparator}${System.getenv('PATH')}"
commandLine 'rustup', 'run', 'stable', 'rustc', '-Vv'
}.standardOutput.asText)
outputs.dir(rustJniLibsDir)
workingDir rustCrateDir
// The configuration cache serialises the task, so everything it needs is resolved here, not
@@ -223,12 +250,18 @@ def buildRustStores = tasks.register('buildRustStores', Exec) {
environment 'PATH', "${cargoBin}${File.pathSeparator}${System.getenv('PATH')}"
environment 'ANDROID_NDK_HOME', android.ndkDirectory.absolutePath
environment 'CARGO_TERM_COLOR', 'never'
if (!skipRust) environment 'RUSTC', providers.exec {
commandLine 'rustup', 'which', '--toolchain', 'stable', 'rustc'
}.standardOutput.asText.get().trim()
// --platform 26 = minSdkVersion: the engines link against the API 26 libc, like the C++ code.
commandLine 'cargo', 'ndk', '--target', 'arm64-v8a', '--platform', '26',
// Homebrew's cargo/rustc can precede rustup on macOS and use a different sysroot, despite
// rustup reporting the Android target installed. Run both through the selected toolchain.
commandLine 'rustup', 'run', 'stable', 'cargo', 'ndk', '--target', 'arm64-v8a', '--platform', '26',
'--output-dir', rustJniLibsDir.get().asFile.absolutePath,
'build', '--release'
'build', '--release', '--locked'
}
android.sourceSets.main.jniLibs.srcDir(rustJniLibsDir)
// Skipping Rust must omit its library even if another build left a cached .so behind.
if (!skipRust) android.sourceSets.main.jniLibs.srcDir(rustJniLibsDir)
tasks.named('preBuild').configure { dependsOn(buildRustStores) }
dependencies {
@@ -595,11 +595,10 @@ class MainActivity : ComponentActivity() {
),
FrontEndActions(
onPlay = { startSteamSession() },
// Steam's desktop client as a window on the desktop: under gamescope the
// client puts itself into Big Picture whatever it is started with.
// The client's desktop UI, with gamescope's Deck integration disabled.
onPlayDesktopUi = {
startSession(Intent(this, SessionActivity::class.java)
.putExtra(SessionService.EXTRA_MODE, SessionService.MODE_DESKTOP)
.putExtra(SessionService.EXTRA_MODE, SessionService.MODE_STEAM)
.putExtra(SessionService.EXTRA_STEAM_UI, "desktop"), steamSession = true)
},
// A store game may need something done first (an Epic game its sign-in code).
@@ -1330,7 +1330,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
return super.dispatchKeyEvent(event)
}
if (pipUi) return true
val fromController = event.device != null && PadBridge.isFromController(event.device)
val fromController = PadBridge.isControllerKey(event)
if (fromController && event.action == KeyEvent.ACTION_DOWN) {
if (drawerOpen && !drawerControllerActive) sessionOverlay.requestFocus()
drawerControllerActive = true
@@ -1382,11 +1382,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
}
return true
}
if (pcKeyboardOpen && event.device != null && PadBridge.isFromController(event.device)) return super.dispatchKeyEvent(event)
if (pcKeyboardOpen && fromController) return super.dispatchKeyEvent(event)
if (event.keyCode != KeyEvent.KEYCODE_BACK && 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.
val fromPad = event.device != null && PadBridge.isFromController(event.device)
val fromPad = fromController
if (CompositorHost.isStarted && event.keyCode != KeyEvent.KEYCODE_BACK && !fromPad) {
val down = event.action == KeyEvent.ACTION_DOWN
if (down || event.action == KeyEvent.ACTION_UP) {
@@ -127,6 +127,29 @@ public final class PadBridge {
|| (sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK;
}
/** A Bluetooth keyboard can share a device with a joystick. Classify the key, not just
* the device, so its letters and modifiers still reach the desktop keyboard. */
public static boolean isControllerKey(KeyEvent event) {
return isFromController(event.getDevice())
&& isPadKey(event.getKeyCode(), event.getDevice().getKeyboardType());
}
public static boolean isPadKey(int keyCode, int keyboardType) {
if ((keyCode >= KeyEvent.KEYCODE_BUTTON_A && keyCode <= KeyEvent.KEYCODE_BUTTON_MODE)
|| (keyCode >= KeyEvent.KEYCODE_BUTTON_1 && keyCode <= KeyEvent.KEYCODE_BUTTON_16)) return true;
if (keyboardType == InputDevice.KEYBOARD_TYPE_ALPHABETIC) return false;
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_UP:
case KeyEvent.KEYCODE_DPAD_DOWN:
case KeyEvent.KEYCODE_DPAD_LEFT:
case KeyEvent.KEYCODE_DPAD_RIGHT:
case KeyEvent.KEYCODE_BACK:
case KeyEvent.KEYCODE_HOME:
case KeyEvent.KEYCODE_MENU: return true;
default: return false;
}
}
/** Whether any real controller is attached right now. */
public static boolean anyControllerConnected() {
for (int id : InputDevice.getDeviceIds()) {
@@ -155,7 +178,7 @@ public final class PadBridge {
/** @return true when the event was a pad button and has been consumed. */
public synchronized boolean onKeyEvent(KeyEvent event) {
if (!isFromController(event.getDevice())) return false;
if (!isControllerKey(event)) return false;
noteDevice(event.getDevice());
boolean pressed = event.getAction() == KeyEvent.ACTION_DOWN;
switch (event.getKeyCode()) {
@@ -95,12 +95,14 @@ object DesktopCatalog {
// The desktop package installed to the end: KWin is there and the marker install() writes once
// the whole package is extracted. An install cut short (the app killed, storage full) leaves
// KWin without the marker, and the next desktop installs it again. The launcher is staged by
// KWin without the marker, and the next desktop installs it again. A newer pinned package also
// replaces the installed one, keeping the user's home and settings. The launcher is staged by
// the app at every session, so it cannot tell. SessionFiles uses the same test.
fun desktopInstalled(context: Context): Boolean = desktopInstalled(LinuxRuntime.rootDir(context))
fun desktopInstalled(root: File): Boolean =
File(root, "usr/bin/kwin_wayland").isFile && File(root, ".droiddeck-pkg-$DESKTOP_ID").isFile
File(root, "usr/bin/kwin_wayland").isFile &&
FileUtils.readString(File(root, ".droiddeck-pkg-$DESKTOP_ID"))?.trim() == BuildConfig.DESKTOP_KDE_TAG
/** Downloads, verifies and installs one package. Returns null on success, else a message. */
fun install(context: Context, entry: Entry, listener: LinuxRuntimeInstaller.ProgressListener?): String? {
@@ -48,9 +48,12 @@ object SessionFiles {
"usr/local/bin/droiddeck-agent" to "usr/local/bin/droiddeck-agent",
"usr/local/bin/steam-compatibility" to "usr/local/bin/steam-compatibility",
"usr/local/bin/droiddeck-clipboard" to "usr/local/bin/droiddeck-clipboard",
"usr/local/bin/droiddeck-desktop-clipboard" to "usr/local/bin/droiddeck-desktop-clipboard",
"usr/local/bin/droiddeck-gpu-window" to "usr/local/bin/droiddeck-gpu-window",
"usr/local/bin/droiddeck-steam-install" to "usr/local/bin/droiddeck-steam-install",
"usr/local/bin/droiddeck-steam-ui-scale" to "usr/local/bin/droiddeck-steam-ui-scale",
"usr/local/bin/droiddeck-steam-language" to "usr/local/bin/droiddeck-steam-language",
"usr/local/bin/droiddeck-steam-desktop-ui" to "usr/local/bin/droiddeck-steam-desktop-ui",
"usr/local/bin/droiddeck-steam-library" to "usr/local/bin/droiddeck-steam-library",
"usr/local/bin/droiddeck-seed-redists" to "usr/local/bin/droiddeck-seed-redists",
"usr/local/bin/droiddeck-proton-extra" to "usr/local/bin/droiddeck-proton-extra",
@@ -98,9 +101,11 @@ object SessionFiles {
// Games and emulators from the menu, full screen in a gamescope of their own.
"usr/local/bin/droiddeck-gpu" to "usr/local/bin/droiddeck-gpu",
"usr/local/bin/droiddeck-desktop-gpu" to "usr/local/bin/droiddeck-desktop-gpu",
"usr/local/bin/droiddeck-desktop-window-rules" to "usr/local/bin/droiddeck-desktop-window-rules",
// KWin at the app's surface size, for Plasma's session (it starts KWin through this name).
"usr/local/bin/kwin_wayland_wrapper" to "usr/local/bin/kwin_wayland_wrapper",
"usr/lib/firefox/defaults/pref/droiddeck.js" to "usr/lib/firefox/defaults/pref/droiddeck.js",
"etc/xdg/autostart/droiddeck-clipboard.desktop" to "etc/xdg/autostart/droiddeck-clipboard.desktop",
)
// The patched gamescope (tools/gamescope): the runtime's own version rebuilt with the ARM64
// client fixes, over /usr/local/bin so it comes first in the session's PATH. Only when the
@@ -734,6 +734,7 @@ class SessionService : Service() {
// Decided only once its sysfs is in place: without it the client would find no Deck, and
// with the Deck asked for the pad's own nodes are withdrawn - no controller at all.
val wantsDeck = uinput && SessionState.mode == MODE_STEAM &&
SessionState.steamUi != "desktop" &&
SessionPrefs.steamController(this) == SessionPrefs.CONTROLLER_DECK &&
!File(Environment.getExternalStorageDirectory(), NO_DECK_PAD_SWITCH).exists()
deckBinds = if (wantsDeck) SteamDeckPad.prepare(this, fakeInputDir.parentFile!!.parentFile!!) else emptyList()
@@ -0,0 +1,28 @@
package com.droiddeck.launcher.input
import android.view.InputDevice
import android.view.KeyEvent
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
class PadKeyTest {
@Test fun keyboardLettersAndModifiersAreNotPadEvents() {
for (type in listOf(InputDevice.KEYBOARD_TYPE_ALPHABETIC, InputDevice.KEYBOARD_TYPE_NON_ALPHABETIC)) {
for (key in listOf(KeyEvent.KEYCODE_A, KeyEvent.KEYCODE_K, KeyEvent.KEYCODE_SHIFT_LEFT,
KeyEvent.KEYCODE_CTRL_LEFT, KeyEvent.KEYCODE_ESCAPE, KeyEvent.KEYCODE_ENTER)) {
assertFalse(PadBridge.isPadKey(key, type))
}
}
}
@Test fun keyboardArrowsStayWithKeyboardAndPadArrowsStayWithPad() {
assertFalse(PadBridge.isPadKey(KeyEvent.KEYCODE_DPAD_LEFT, InputDevice.KEYBOARD_TYPE_ALPHABETIC))
assertTrue(PadBridge.isPadKey(KeyEvent.KEYCODE_DPAD_LEFT, InputDevice.KEYBOARD_TYPE_NON_ALPHABETIC))
}
@Test fun gamepadButtonsRemainPadEventsOnHybridDevices() {
assertTrue(PadBridge.isPadKey(KeyEvent.KEYCODE_BUTTON_A, InputDevice.KEYBOARD_TYPE_ALPHABETIC))
assertTrue(PadBridge.isPadKey(KeyEvent.KEYCODE_BUTTON_START, InputDevice.KEYBOARD_TYPE_ALPHABETIC))
}
}
@@ -0,0 +1,29 @@
package com.droiddeck.launcher.runtime
import com.droiddeck.launcher.BuildConfig
import java.io.File
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
class DesktopCatalogTest {
@get:Rule val temporary = TemporaryFolder()
@Test fun desktopNeedsTheCompleteCurrentPinnedPackage() {
val root = temporary.root
val kwin = File(root, "usr/bin/kwin_wayland").apply {
parentFile.mkdirs()
writeText("fixture")
}
val marker = File(root, ".droiddeck-pkg-${DesktopCatalog.DESKTOP_ID}")
assertFalse(DesktopCatalog.desktopInstalled(root))
marker.writeText("older-package")
assertFalse(DesktopCatalog.desktopInstalled(root))
marker.writeText("${BuildConfig.DESKTOP_KDE_TAG}\n")
assertTrue(DesktopCatalog.desktopInstalled(root))
kwin.delete()
assertFalse(DesktopCatalog.desktopInstalled(root))
}
}