From e72b41e2e40fdfa28a4f237355627b00923f73b8 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Sat, 5 Dec 2026 22:37:57 -0500 Subject: [PATCH] Keep Android shortcut touch and system Back on separate displays --- .github/workflows/build-ubuntu-runtime.yml | 26 ++++++++++++-- .../com/droiddeck/launcher/SessionActivity.kt | 1 + .../launcher/frontend/AndroidSteamApps.kt | 5 ++- docs/android-apps-in-steam.md | 4 +-- .../usr/local/bin/droiddeck-android-app | 5 +-- .../overlay/usr/local/bin/droiddeck-session | 8 +++++ tools/ubuntu/README.md | 2 ++ tools/ubuntu/build-scrcpy-server.sh | 34 +++++++++++++++++++ tools/ubuntu/build.sh | 6 ++++ .../ubuntu/patches/scrcpy-display-focus.patch | 21 ++++++++++++ 10 files changed, 105 insertions(+), 7 deletions(-) create mode 100755 tools/ubuntu/build-scrcpy-server.sh create mode 100644 tools/ubuntu/patches/scrcpy-display-focus.patch diff --git a/.github/workflows/build-ubuntu-runtime.yml b/.github/workflows/build-ubuntu-runtime.yml index f104e9cd7f..b7dfe864a4 100644 --- a/.github/workflows/build-ubuntu-runtime.yml +++ b/.github/workflows/build-ubuntu-runtime.yml @@ -34,8 +34,26 @@ jobs: retention-days: 7 compression-level: 0 path: out/debs/ + scrcpy-server: + runs-on: ubuntu-24.04 + timeout-minutes: 10 + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '17' + - run: | + sdkmanager 'platforms;android-36' 'build-tools;35.0.0' + tools/ubuntu/build-scrcpy-server.sh out/scrcpy-server.jar + - uses: actions/upload-artifact@v4 + with: + name: droiddeck-scrcpy-server + path: out/scrcpy-server.jar rootfs: - needs: debs + needs: [debs, scrcpy-server] runs-on: ubuntu-24.04-arm timeout-minutes: 120 steps: @@ -46,6 +64,10 @@ jobs: with: name: ubuntu-runtime-debs path: out/debs + - uses: actions/download-artifact@v4 + with: + name: droiddeck-scrcpy-server + path: out/server - uses: actions/create-github-app-token@v2 id: components-token if: github.event_name == 'workflow_dispatch' && inputs.tag != '' @@ -68,7 +90,7 @@ jobs: set -euo pipefail sudo apt-get update -qq && sudo apt-get install -y -qq zstd gpgv ubuntu-keyring >/dev/null tag='${{ inputs.tag }}' - tools/ubuntu/build.sh out/debs out "${tag:-ubuntu-dev}" + tools/ubuntu/build.sh out/debs out "${tag:-ubuntu-dev}" out/server/scrcpy-server.jar - uses: actions/upload-artifact@v4 with: name: ubuntu-runtime diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 3b5166bf5a..ce339c0ae3 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -877,6 +877,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private var runtimeRemovalBlocked = false override fun onCreate(savedInstanceState: Bundle?) { + setTheme(R.style.SessionTheme) super.onCreate(savedInstanceState) com.droiddeck.launcher.session.xr.XrPanels.setMenuHost(this) AgentGuest.readyListener = agentReadyListener diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/AndroidSteamApps.kt b/app/src/main/java/com/droiddeck/launcher/frontend/AndroidSteamApps.kt index 2009731e9c..ac22758c21 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/AndroidSteamApps.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/AndroidSteamApps.kt @@ -32,6 +32,7 @@ internal object AndroidSteamApps { if (Build.VERSION.SDK_INT < MIN_ANDROID) return emptyList() val packages = prefs(context).all.keys.sorted() val apps = JSONArray() + val appIds = mutableListOf() for (pkg in packages) { if (!supports(pkg)) continue val pm = context.packageManager @@ -41,12 +42,14 @@ internal object AndroidSteamApps { pm.getActivityInfo(component, 0).loadLabel(pm).toString() }.getOrDefault(pkg).ifBlank { pkg } val id = CRC32().apply { update("droiddeck-android-app:$pkg".toByteArray()) }.value or 0x80000000L + appIds.add(id) apps.put(JSONObject().put("name", label).put("appid", id) .put("exe", LAUNCHER).put("dir", "/usr/local/bin").put("launch", pkg).put("native", true)) } if (apps.length() == 0) return emptyList() val listing = File(sessionDir, "android-apps.json").apply { writeText(apps.toString()) } - val env = mutableListOf("DD_ANDROID_APPS=${listing.absolutePath}") + val env = mutableListOf("DD_ANDROID_APPS=${listing.absolutePath}", + "DD_ANDROID_APP_IDS=${appIds.joinToString(" ")}") if (WirelessAdbFix.hasSavedPairing(context)) { val link = AgentAdb.prepare(context) if (link.paired) { diff --git a/docs/android-apps-in-steam.md b/docs/android-apps-in-steam.md index c90bd5b72a..54474d43a1 100644 --- a/docs/android-apps-in-steam.md +++ b/docs/android-apps-in-steam.md @@ -1,8 +1,8 @@ # Android apps in Steam -On Android 15 or newer, set DroidDeck as your Android Home app. In DroidDeck's **Apps** tab, open an app's menu and select **Add to Steam**. Pair Wireless debugging in DroidDeck's **Settings → Diagnostics** and keep Wireless debugging enabled. Restart Steam from DroidDeck. The app appears as a non-Steam shortcut in your library. To remove it, select **Remove from Steam** in the same app menu and restart Steam. +On Android 15 or newer, open DroidDeck’s **Apps** tab. If it’s hidden, show it using **Arrange tabs**. Then open an app’s menu and select **Add to Steam**. Pair Wireless debugging in DroidDeck's **Settings → Diagnostics** and keep Wireless debugging enabled. Restart Steam from DroidDeck. The app appears as a non-Steam shortcut in your library. To remove it, select **Remove from Steam** in the same app menu and restart Steam. -The app runs on a separate Android display. Steam shows that display and forwards touch and gamepad input. Apps with controller support see an Xbox 360 pad. The app plays sound through Android, so use the handheld's media volume. +The app runs on a separate Android display. Steam shows that display and forwards touch gestures and gamepad input. Android’s system Back stays with the handheld display, so it can open DroidDeck’s menu. Apps with controller support see an Xbox 360 pad. The app plays sound through Android, so use the handheld's media volume. - Use the DroidDeck menu button for session controls and **Exit Game** in Steam to close the shortcut. - To go back inside the Android app with a keyboard, press **Alt+B**. DroidDeck's Back and the session menu are separate controls. diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-android-app b/tools/linuxfs/overlay/usr/local/bin/droiddeck-android-app index e96742f726..11e85265a1 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-android-app +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-android-app @@ -13,7 +13,8 @@ case "${1:-}" in ''|*[!a-zA-Z0-9_.]*) fail "This shortcut has no valid Android app." ;; esac package=$1 -command -v scrcpy >/dev/null && command -v adb >/dev/null || +export SCRCPY_SERVER_PATH=/usr/share/droiddeck/scrcpy-server.jar +command -v scrcpy >/dev/null && command -v adb >/dev/null && [ -r "$SCRCPY_SERVER_PATH" ] || fail "Update the DroidDeck Linux runtime to launch Android apps." serial=${DD_ANDROID_ADB_SERIAL:-} @@ -43,6 +44,6 @@ connected || connected || export SDL_VIDEODRIVER=x11 # Android plays audio on the handheld. Capturing it here would feed it back into Android again. scrcpy --serial "$serial" --new-display=1280x720/240 --start-app="$package" \ - --window-title="Android app" --no-vd-system-decorations --no-clipboard-autosync \ + --window-title="Android app" --no-vd-system-decorations --no-clipboard-autosync --no-mouse-hover \ --mouse-bind=----:---- --gamepad=uhid --no-audio --max-fps=60 9>&- || fail "The Android app window closed unexpectedly. Try launching it again." diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session index 10d522084d..474caf35a1 100644 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session @@ -1359,6 +1359,12 @@ case $mode in && echo "== scaling: applied the client's saved scaling filter $filter" return 0 } + android_touch_mode() { + [ -n "$app" ] || return 0 + case " ${DD_ANDROID_APP_IDS:-} " in + *" $app "*) xprop -root -f STEAM_TOUCH_CLICK_MODE 32c -set STEAM_TOUCH_CLICK_MODE 4 ;; + esac + } tmode= app= prev= while read -r line; do case $line in @@ -1367,12 +1373,14 @@ case $mode in [ "$pv" = "$tmode" ] && continue tmode=$pv echo "== touch mode: $tmode (focused app ${app:-?}) at $(date +%T)" + [ "$tmode" = 4 ] || android_touch_mode ;; GAMESCOPE_FOCUSED_APP*) prop_value "$line" none if [ "$pv" != "$app" ]; then app=$pv echo "== focused app: $app (touch mode ${tmode:-unset}) at $(date +%T)" + [ "$tmode" = 4 ] || android_touch_mode if [ -n "${DD_LAUNCH_DIR:-}" ]; then printf '%s\n' "$app" > "$DD_LAUNCH_DIR/steam-focused-app.tmp" && mv -f "$DD_LAUNCH_DIR/steam-focused-app.tmp" "$DD_LAUNCH_DIR/steam-focused-app" fi diff --git a/tools/ubuntu/README.md b/tools/ubuntu/README.md index 751ce585c0..b42f25bf04 100644 --- a/tools/ubuntu/README.md +++ b/tools/ubuntu/README.md @@ -50,3 +50,5 @@ At run time: `.github/workflows/build-ubuntu-runtime.yml` builds it and, run with a new tag (`ubuntu-rN`), publishes the runtime and its desktop pack in Droid-Deck/DroidDeck-Components; `linuxfs-ubuntu.json` there names the release the app installs. + +Build the scrcpy server with `tools/ubuntu/build-scrcpy-server.sh out/scrcpy-server.jar`. It requires JDK 17, Android platform 36 and build-tools 35.0.0. Pass the resulting jar as the fourth argument to `tools/ubuntu/build.sh` when building a runtime locally. diff --git a/tools/ubuntu/build-scrcpy-server.sh b/tools/ubuntu/build-scrcpy-server.sh new file mode 100755 index 0000000000..7f5e20c3bd --- /dev/null +++ b/tools/ubuntu/build-scrcpy-server.sh @@ -0,0 +1,34 @@ +#!/bin/bash +set -euo pipefail + +here=$(cd "$(dirname "$0")" && pwd) +sdk=${ANDROID_HOME:?Android SDK required} +out=$(realpath -m "${1:?output server jar}") +tools=$sdk/build-tools/35.0.0 +platform=$sdk/platforms/android-36 +version=3.3.4 +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT + +curl -fsSL --retry 3 --proto '=https' -o "$work/source.tar.gz" \ + "https://codeload.github.com/Genymobile/scrcpy/tar.gz/refs/tags/v$version" +echo "03b72d1f71ca7783cff2995ca7cd8c67b9b75038a3cc35e443a1913e951b49dd $work/source.tar.gz" | sha256sum -c - +tar xzf "$work/source.tar.gz" -C "$work" --strip-components=1 +git -C "$work" apply "$here/patches/scrcpy-display-focus.patch" +src=$work/server/src/main +mkdir -p "$work/generated/com/genymobile/scrcpy" "$work/classes" "$(dirname "$out")" +for file in "$src"/aidl/android/*/*.aidl; do + "${DROIDDECK_AIDL:-$tools/aidl}" -I"$src/aidl" -p"$platform/framework.aidl" -o"$work/generated" "$file" +done +cat > "$work/generated/com/genymobile/scrcpy/BuildConfig.java" < "$work/sources" +javac --release 8 -classpath "$platform/android.jar" -d "$work/classes" @"$work/sources" +jar cf "$work/server.jar" -C "$work/classes" . +java -cp "$tools/lib/d8.jar" com.android.tools.r8.D8 --release --min-api 21 \ + --lib "$platform/android.jar" --output "$out" "$work/server.jar" diff --git a/tools/ubuntu/build.sh b/tools/ubuntu/build.sh index 23b8a835ef..47f75c4030 100755 --- a/tools/ubuntu/build.sh +++ b/tools/ubuntu/build.sh @@ -4,6 +4,7 @@ here=$(cd "$(dirname "$0")" && pwd) debs=$(realpath "${1:?directory with the DroidDeck-built .deb files}") out=$(realpath -m "${2:?out dir}") runtime_id=${3:?runtime id, e.g. ubuntu-r1} +scrcpy_server=$(realpath "${4:?patched scrcpy server jar}") [ "$(uname -m)" = aarch64 ] || { echo 'the Ubuntu runtime needs a native arm64 runner' >&2; exit 1; } source "$here/base.env" fetch() { curl -fsSL --proto '=https' --proto-redir '=https' --retry 6 --retry-delay 5 --retry-all-errors -o "$1" "$2"; } @@ -47,6 +48,11 @@ unseal() { } stage runtime +case $(sudo chroot "$root" dpkg-query -W -f='${Version}' scrcpy) in + 3.3.4-*) ;; + *) echo "The scrcpy client must match the patched 3.3.4 server" >&2; exit 1 ;; +esac +sudo install -D -m 644 "$scrcpy_server" "$root/usr/share/droiddeck/scrcpy-server.jar" seal sudo mv "$root/tmp/droiddeck" "$work/src-keep" sudo chroot "$root" dpkg-query -W -f '${Package} ${Version}\n' > "$out/$runtime_id.packages.txt" diff --git a/tools/ubuntu/patches/scrcpy-display-focus.patch b/tools/ubuntu/patches/scrcpy-display-focus.patch new file mode 100644 index 0000000000..3d5b9f2b5b --- /dev/null +++ b/tools/ubuntu/patches/scrcpy-display-focus.patch @@ -0,0 +1,21 @@ +--- a/server/src/main/java/com/genymobile/scrcpy/video/NewDisplayCapture.java ++++ b/server/src/main/java/com/genymobile/scrcpy/video/NewDisplayCapture.java +@@ -38,6 +38,8 @@ + private static final int VIRTUAL_DISPLAY_FLAG_OWN_FOCUS = 1 << 14; + private static final int VIRTUAL_DISPLAY_FLAG_DEVICE_DISPLAY_GROUP = 1 << 15; + ++ private static final int VIRTUAL_DISPLAY_FLAG_STEAL_TOP_FOCUS_DISABLED = 1 << 16; ++ + private final VirtualDisplayListener vdListener; + private final NewDisplay newDisplay; + +@@ -187,7 +189,8 @@ + | VIRTUAL_DISPLAY_FLAG_TOUCH_FEEDBACK_DISABLED; + if (Build.VERSION.SDK_INT >= AndroidVersions.API_34_ANDROID_14) { + flags |= VIRTUAL_DISPLAY_FLAG_OWN_FOCUS +- | VIRTUAL_DISPLAY_FLAG_DEVICE_DISPLAY_GROUP; ++ | VIRTUAL_DISPLAY_FLAG_DEVICE_DISPLAY_GROUP ++ | VIRTUAL_DISPLAY_FLAG_STEAL_TOP_FOCUS_DISABLED; + } + } + virtualDisplay = ServiceManager.getDisplayManager()