diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8d55072a46..a187dc15b0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -69,6 +69,19 @@ + + + + + + + = emptyList() + private val lock = Any() + private val redraw = Runnable { draw() } + private var visible = false + private var surfaceLive = false + private var lastFrame = 0L + private var phase = 0f + private var choreographer: Choreographer? = null + private var lastDrawNanos = 0L + private val tick = object : Choreographer.FrameCallback { + override fun doFrame(frameTimeNanos: Long) { + if (!visible) return + val interval = if (WallPrefs.fps(applicationContext) == WallPrefs.MATCH_SCREEN) 0L else 1_000_000_000L / framesPerSecond() + if (frameTimeNanos - lastDrawNanos >= interval - SLACK_NANOS) { + lastDrawNanos = frameTimeNanos + runCatching { draw() } + } + if (synchronized(lock) { surfaceLive }) choreographer?.postFrameCallback(this) + } + } + + private fun startTicking() { + val c = choreographer ?: Choreographer.getInstance().also { choreographer = it } + c.removeFrameCallback(tick) + c.postFrameCallback(tick) + } + + private fun stopTicking() { + choreographer?.removeFrameCallback(tick) + } + + private fun framesPerSecond(): Int = WallPrefs.fps(applicationContext) + + override fun onCreate(surfaceHolder: SurfaceHolder) { + handler.post { covers = loadCovers() } + } + + private fun loadCovers(): List { + val d = resources.displayMetrics.density + val targetW = (112f * d).toInt() + val files = runCatching { Library.steamLibraryArt(applicationContext).distinctBy { it.first }.shuffled().take(MAX_COVERS) } + .getOrDefault(emptyList()) + return files.mapNotNull { (_, file) -> + runCatching { + val bounds = BitmapFactory.Options().apply { inJustDecodeBounds = true } + BitmapFactory.decodeFile(file.path, bounds) + var sample = 1 + while (bounds.outWidth / (sample * 2) >= targetW) sample *= 2 + BitmapFactory.decodeFile(file.path, BitmapFactory.Options().apply { + inSampleSize = sample + inPreferredConfig = Bitmap.Config.RGB_565 + }) + }.getOrNull() + } + } + + override fun onVisibilityChanged(visible: Boolean) { + handler.post { + this.visible = visible + stopTicking() + if (visible) { + lastFrame = SystemClock.uptimeMillis() + startTicking() + } + } + } + + override fun onSurfaceCreated(holder: SurfaceHolder) { + synchronized(lock) { surfaceLive = true } + handler.post { + stopTicking() + if (visible) startTicking() + } + } + + override fun onSurfaceRedrawNeeded(holder: SurfaceHolder) { + redrawNow() + } + + override fun onSurfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) { + handler.removeCallbacks(redraw) + handler.post(redraw) + } + + override fun onSurfaceDestroyed(holder: SurfaceHolder) { + stopTicking() + handler.removeCallbacks(redraw) + synchronized(lock) { surfaceLive = false } + handler.post { stopTicking() } + } + + override fun onDestroy() { + synchronized(lock) { surfaceLive = false } + handler.post { + visible = false + stopTicking() + handler.removeCallbacks(redraw) + } + thread.quitSafely() + covers = emptyList() + } + + private fun redrawNow() { + val done = CountDownLatch(1) + handler.removeCallbacks(redraw) + handler.post(redraw) + handler.post { done.countDown() } + done.await(REDRAW_WAIT_MS, TimeUnit.MILLISECONDS) + } + + private fun draw() { + synchronized(lock) { + if (!surfaceLive || !surfaceHolder.surface.isValid) return + val canvas = surfaceHolder.surface.lockHardwareCanvas() ?: return + try { + render(canvas, canvas.width.toFloat(), canvas.height.toFloat()) + } finally { + surfaceHolder.surface.unlockCanvasAndPost(canvas) + } + } + } + + private fun render(canvas: Canvas, w: Float, h: Float) { + val pal = Themes.current(applicationContext) + val bg = pal.background.toArgb() + val d = resources.displayMetrics.density + val capW = 112f * d + val capH = 168f * d + val gap = 14f * d + val radius = 10f * d + val tilt = Math.toRadians(TILT.toDouble()) + val cs = cos(tilt).toFloat() + val sn = sin(tilt).toFloat() + val wallW = (w * cs + h * sn) * 1.1f + val wallH = maxOf(h * 2.4f, (w * sn + h * cs) * 1.1f) + val columns = ((wallW + gap) / (capW + gap)).toInt() + 1 + val perRun = ((wallH + gap) / (capH + gap)).toInt() + 1 + val run = (capH + gap) * perRun + val now = SystemClock.uptimeMillis() + if (lastFrame != 0L) phase = (phase + (now - lastFrame) * WallPrefs.speed(applicationContext) / DRIFT_MS) % 1f + lastFrame = now + val shift = run * phase + val px = w / 2f + val py = h / 2f + val left = px - wallW / 2f + val top = py - wallH / 2f + + val deck = covers + canvas.drawColor(bg) + fill.color = pal.surface.toArgb() + stroke.color = pal.line.toArgb() + stroke.strokeWidth = d + canvas.save() + canvas.rotate(-TILT, px, py) + for (c in 0 until columns) { + val x = left + c * (capW + gap) + val dy = if (c % 2 == 0) -shift else shift - run + for (i in 0 until perRun * 2) { + val y = top + i * (capH + gap) + dy + val lx = x + capW / 2 - px + val ly = y + capH / 2 - py + val sx = px + lx * cs + ly * sn + val sy = py - lx * sn + ly * cs + if (sx < -capH || sx > w + capH || sy < -capH || sy > h + capH) continue + rect.set(x, y, x + capW, y + capH) + canvas.drawRoundRect(rect, radius, radius, fill) + if (deck.isNotEmpty()) { + val cover = deck[(c * 5 + (i % perRun) * 3) % deck.size] + clip.rewind() + clip.addRoundRect(rect, radius, radius, Path.Direction.CW) + canvas.save() + canvas.clipPath(clip) + canvas.drawBitmap(cover, null, rect, art) + canvas.restore() + } + canvas.drawRoundRect(rect, radius, radius, stroke) + } + } + canvas.restore() + } + } + + private companion object { + const val MAX_COVERS = 48 + const val TILT = 13f + const val DRIFT_MS = 50_000L + const val REDRAW_WAIT_MS = 200L + const val SLACK_NANOS = 2_000_000L + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/wallpaper/WallPrefs.kt b/app/src/main/java/com/droiddeck/launcher/wallpaper/WallPrefs.kt new file mode 100644 index 0000000000..f92ea57262 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/wallpaper/WallPrefs.kt @@ -0,0 +1,22 @@ +package com.droiddeck.launcher.wallpaper + +import android.content.Context + +object WallPrefs { + val FPS_CHOICES = listOf(15, 30, 60, MATCH_SCREEN) + val SPEED_CHOICES = listOf(0.5f, 1f, 2f) + const val MATCH_SCREEN = 0 + private const val FILE = "wall_wallpaper" + private const val KEY_FPS = "fps" + private const val KEY_SPEED = "speed" + + private fun prefs(context: Context) = context.getSharedPreferences(FILE, Context.MODE_PRIVATE) + + fun fps(context: Context): Int = prefs(context).getInt(KEY_FPS, 30).let { if (it == MATCH_SCREEN) it else it.coerceIn(5, 120) } + + fun speed(context: Context): Float = prefs(context).getFloat(KEY_SPEED, 1f).coerceIn(0.1f, 4f) + + fun setFps(context: Context, value: Int) = prefs(context).edit().putInt(KEY_FPS, value).apply() + + fun setSpeed(context: Context, value: Float) = prefs(context).edit().putFloat(KEY_SPEED, value).apply() +} diff --git a/app/src/main/java/com/droiddeck/launcher/wallpaper/WallpaperSettingsActivity.kt b/app/src/main/java/com/droiddeck/launcher/wallpaper/WallpaperSettingsActivity.kt new file mode 100644 index 0000000000..1afb63805f --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/wallpaper/WallpaperSettingsActivity.kt @@ -0,0 +1,69 @@ +package com.droiddeck.launcher.wallpaper + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.foundation.verticalScroll +import androidx.compose.material3.FilterChip +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableFloatStateOf +import androidx.compose.runtime.mutableIntStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import com.droiddeck.launcher.R +import com.droiddeck.launcher.core.AppUiPrefs +import com.droiddeck.launcher.ui.DroidDeckTheme + +class WallpaperSettingsActivity : ComponentActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContent { + DroidDeckTheme(appScale = AppUiPrefs.scale(this)) { + val ink = MaterialTheme.colorScheme.onBackground + var fps by remember { mutableIntStateOf(WallPrefs.fps(this)) } + var speed by remember { mutableFloatStateOf(WallPrefs.speed(this)) } + Column(Modifier.fillMaxSize().padding(24.dp), verticalArrangement = Arrangement.Bottom) { + Column( + Modifier.background(MaterialTheme.colorScheme.background.copy(alpha = 0.88f), RoundedCornerShape(20.dp)) + .verticalScroll(rememberScrollState()).padding(20.dp), + verticalArrangement = Arrangement.spacedBy(16.dp), + ) { + Text(getString(R.string.steam_wall_label), style = MaterialTheme.typography.titleLarge, color = ink) + Text(getString(R.string.wall_settings_fps), style = MaterialTheme.typography.titleMedium, color = ink) + Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { + WallPrefs.FPS_CHOICES.forEach { choice -> + FilterChip( + selected = fps == choice, + onClick = { fps = choice; WallPrefs.setFps(this@WallpaperSettingsActivity, choice) }, + label = { Text(if (choice == WallPrefs.MATCH_SCREEN) getString(R.string.wall_settings_match) else "$choice") }, + ) + } + } + Text(getString(R.string.wall_settings_speed), style = MaterialTheme.typography.titleMedium, color = ink) + Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { + WallPrefs.SPEED_CHOICES.forEach { choice -> + FilterChip( + selected = speed == choice, + onClick = { speed = choice; WallPrefs.setSpeed(this@WallpaperSettingsActivity, choice) }, + label = { Text(if (choice == 1f) "1x" else "${choice.toString().removeSuffix(".0")}x") }, + ) + } + } + } + } + } + } + } +} diff --git a/app/src/main/res/drawable/steam_wall_thumb.xml b/app/src/main/res/drawable/steam_wall_thumb.xml new file mode 100644 index 0000000000..928e86ee11 --- /dev/null +++ b/app/src/main/res/drawable/steam_wall_thumb.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d6068dc96f..208cc2ad28 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -31,6 +31,10 @@ Resetting graphics and reopening SteamVR… DroidDeck could not restart automatically. Close the app completely, then reopen it. DroidDeck + DroidDeck Wall + Frame rate (fps) + Match screen + Scroll speed First run downloads Steam. This may take a few minutes. By default, leaving the app pauses Steam; it picks up where it left off when you come back. diff --git a/app/src/main/res/xml/steam_wall_wallpaper.xml b/app/src/main/res/xml/steam_wall_wallpaper.xml new file mode 100644 index 0000000000..5a8b782465 --- /dev/null +++ b/app/src/main/res/xml/steam_wall_wallpaper.xml @@ -0,0 +1,4 @@ + + diff --git a/tools/build_local.sh b/tools/build_local.sh index 216b1e0dfd..93ffd51fd6 100755 --- a/tools/build_local.sh +++ b/tools/build_local.sh @@ -115,9 +115,10 @@ image_id=$(docker image inspect --format '{{.Id}}' "${image_name}") rm -rf -- "${linuxfs_dir}" mkdir -p "${linuxfs_dir}" +git_common=$(git -C "${repo_root}" rev-parse --path-format=absolute --git-common-dir) docker run --rm --platform "${docker_platform}" \ --user "$(id -u):$(id -g)" \ - -v "${repo_root}:/src" -w /src "${image_name}" bash -lc ' + -v "${repo_root}:/src" -v "${git_common}:${git_common}" -w /src "${image_name}" bash -lc ' set -euo pipefail d=app/src/main/assets/linuxfs mkdir -p "$d" @@ -163,7 +164,7 @@ x86_key=$(inputs_hash bullseye tools/linuxfs/build-x86-preloads.sh tools/linuxfs x86_stage="${staging_dir}/x86-preloads" if restore_step x86-preloads "${x86_key}" "${linuxfs_dir}"; then :; else docker run --rm --platform linux/amd64 \ - -v "${repo_root}:/src" -w /src public.ecr.aws/docker/library/debian:bullseye bash -c ' + -v "${repo_root}:/src" -v "${git_common}:${git_common}" -w /src public.ecr.aws/docker/library/debian:bullseye bash -c ' set -euo pipefail printf "deb http://archive.debian.org/debian bullseye main\ndeb http://archive.debian.org/debian-security bullseye-security main\n" > /etc/apt/sources.list apt-get -o Acquire::Check-Valid-Until=false update -qq diff --git a/tools/comet/build-local.sh b/tools/comet/build-local.sh index 9adc9549d4..e9487e5635 100644 --- a/tools/comet/build-local.sh +++ b/tools/comet/build-local.sh @@ -6,7 +6,8 @@ image=${DROIDDECK_BUILD_IMAGE} platform=${DROIDDECK_DOCKER_PLATFORM} rust_cache="${HOME}/.cache/droiddeck-comet-rust${platform#linux/amd64}" rust_cache=${rust_cache/\/arm64/-arm64} -docker run --rm --platform "$platform" -v "$repo:/src" \ +git_common=$(git -C "$repo" rev-parse --path-format=absolute --git-common-dir) +docker run --rm --platform "$platform" -v "$repo:/src" -v "$git_common:$git_common" \ -v "${rust_cache}:/rust" -w /src \ -e CARGO_HOME=/rust/cargo -e RUSTUP_HOME=/rust/rustup "$image" bash -lc ' set -euo pipefail diff --git a/tools/quick_deploy.sh b/tools/quick_deploy.sh index 1310a5bcfe..1166feaa6b 100755 --- a/tools/quick_deploy.sh +++ b/tools/quick_deploy.sh @@ -2,6 +2,7 @@ set -euo pipefail repo_root=$(CDPATH= cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd) cd "${repo_root}" +"${repo_root}/tools/seed_worktree.sh" sdk_dir=${ANDROID_HOME:-${ANDROID_SDK_ROOT:-"${HOME}/Library/Android/sdk"}} export ANDROID_HOME=${sdk_dir} ANDROID_SDK_ROOT=${sdk_dir} export JAVA_HOME=${JAVA_HOME:-/opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home} diff --git a/tools/seed_worktree.sh b/tools/seed_worktree.sh new file mode 100755 index 0000000000..e5079e7111 --- /dev/null +++ b/tools/seed_worktree.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +set -euo pipefail +repo_root=$(CDPATH= cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd) +common=$(git -C "${repo_root}" rev-parse --path-format=absolute --git-common-dir) +main_root=$(dirname "${common}") +[[ "${main_root}" != "${repo_root}" && -d "${main_root}/app/build" ]] || exit 0 + +paths=( + app/build/prepared-assets app/build/runtime-inputs.json app/build/runtimeAssets + app/build/packs app/build/localPackAssets app/build/packs-local-aside app/build/quest-inputs + app/build/rustJniLibs app/build/vkbridgeJniLibs + app/src/main/assets/directaudio app/src/main/assets/droiddeck-esync app/src/main/assets/linuxfs + app/src/main/assets/desktop-removal + app/src/main/jniLibs/arm64-v8a + app/src/main/rust/stores/target +) +for path in "${paths[@]}"; do + [[ -e "${main_root}/${path}" ]] || continue + if [[ -d "${main_root}/${path}" ]]; then + [[ -z "$(ls -A "${repo_root}/${path}" 2>/dev/null)" ]] || continue + mkdir -p "$(dirname "${repo_root}/${path}")" + staged=$(mktemp -d "${repo_root}/${path}.seed.XXXXXX") + trap 'rm -rf "${staged}"' EXIT + cp -R "${main_root}/${path}/." "${staged}/" + if [[ -d "${repo_root}/${path}" ]] && ! rmdir "${repo_root}/${path}" 2>/dev/null; then + rm -rf "${staged}"; trap - EXIT; continue + fi + if [[ -e "${repo_root}/${path}" ]]; then + rm -rf "${staged}"; trap - EXIT; continue + fi + mv "${staged}" "${repo_root}/${path}" + trap - EXIT + elif [[ ! -e "${repo_root}/${path}" ]]; then + mkdir -p "$(dirname "${repo_root}/${path}")" + staged=$(mktemp "${repo_root}/${path}.seed.XXXXXX") + trap 'rm -f "${staged}"' EXIT + cp "${main_root}/${path}" "${staged}" + mv "${staged}" "${repo_root}/${path}" + trap - EXIT + fi +done