From 6568bf667d6343d3558a8269a31deec91c8c014d Mon Sep 17 00:00:00 2001 From: The412Banner Date: Sun, 20 Sep 2026 03:51:59 -0400 Subject: [PATCH] Touchpad on the desktop, and the guest's resolver from the live network MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Touch on the desktop now works the way Bannerlator's desktop containers do: the arrow stays where it is and a finger dragged anywhere moves it from there, tap clicks, a second finger tapping while one holds (or a two-finger tap) right-clicks, two fingers scroll, hold-then-drag and double-tap-hold drag. Steam keeps the direct pointer; the drawer pins either. The runtime's resolv.conf is written from the active network's DNS servers on every link change — IPv4 first, never Android's link-local IPv6 ones, the public pair as fallback — which is what glibc, and so Firefox, resolve with. Routing needs nothing: proot makes no network namespace. --- README.md | 15 ++ .../com/steamdeck/launcher/SessionActivity.kt | 43 +++++ .../launcher/input/TouchpadGestures.kt | 151 ++++++++++++++++++ .../runtime/LinuxNetworkLinkComponent.kt | 36 +++++ .../launcher/session/SessionPrefs.kt | 12 ++ .../steamdeck/launcher/ui/SessionOverlay.kt | 5 + 6 files changed, 262 insertions(+) create mode 100644 app/src/main/java/com/steamdeck/launcher/input/TouchpadGestures.kt diff --git a/README.md b/README.md index f6437a72d7..09539f4c29 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,21 @@ 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. +## Pointer + +The app draws the arrow. On the desktop, touch is a **touchpad** (Bannerlator's desktop-container +feel): drag anywhere and the pointer moves from where it is; tap to click; a second finger tapping +while one holds, or a two-finger tap, right-clicks; two fingers scroll; hold still then drag, or +double-tap-and-hold, drags. In Steam, touch is **direct**: the pointer jumps under the finger. The +drawer's *Touch* switch pins either. A USB or Bluetooth mouse works as itself. + +## Networking + +The desktop's programs use the phone's network directly — proot makes no network namespace, so +IPv4 and IPv6 both pass through — and the app writes the runtime's `/etc/resolv.conf` from the +active network's own DNS servers whenever the link changes (IPv4 first, never a link-local IPv6 one, +public servers as fallback), which is what Firefox and everything else in the desktop resolve with. + ## Keyboard **Keyboard** in the drawer opens the soft keyboard over the session. Steam's UI and the games diff --git a/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt b/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt index 049455a8bc..52b0eedb62 100644 --- a/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt @@ -30,6 +30,7 @@ import com.steamdeck.launcher.input.KeyboardHost import com.steamdeck.launcher.input.OnScreenControls import com.steamdeck.launcher.input.PadBridge import com.steamdeck.launcher.input.PointerGestures +import com.steamdeck.launcher.input.TouchpadGestures import com.steamdeck.launcher.runtime.LinuxRuntime import com.steamdeck.launcher.session.LoadingState import com.steamdeck.launcher.session.PerfHud @@ -70,6 +71,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { private var keyboard: KeyboardHost? = null private var watching = true private lateinit var gestures: PointerGestures + private lateinit var touchpad: TouchpadGestures + private var touchMode by mutableStateOf(SessionPrefs.TOUCH_AUTO) private var cursorPos by mutableStateOf(androidx.compose.ui.geometry.Offset(-100f, -100f)) private var cursorVisible by mutableStateOf(false) private val cursorHide = Runnable { cursorVisible = false } @@ -117,6 +120,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { onScreenControls = OnScreenControls(this, bridge).also { root.addView(it) } keyboard = KeyboardHost(this).also { root.addView(it) } gestures = PointerGestures(PointerGestures.slop(this), pointerListener) + touchpad = TouchpadGestures(PointerGestures.slop(this), pointerListener) // One arrow, ours: Android draws a system pointer for a mouse over any window, and the // session already draws the pointer it is sent. val noCursor = android.view.PointerIcon.getSystemIcon(this, android.view.PointerIcon.TYPE_NULL) @@ -160,6 +164,15 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { readPrefs() updateOnScreenControls() }, + onTouch = { + val next = when (SessionPrefs.touchMode(this@SessionActivity)) { + SessionPrefs.TOUCH_AUTO -> SessionPrefs.TOUCH_PAD + SessionPrefs.TOUCH_PAD -> SessionPrefs.TOUCH_DIRECT + else -> SessionPrefs.TOUCH_AUTO + } + SessionPrefs.setTouchMode(this@SessionActivity, next) + readPrefs() + }, onShape = { val next = if (SessionPrefs.shapeMode(this@SessionActivity) == SessionPrefs.SHAPE_WIDE) SessionPrefs.SHAPE_AUTO else SessionPrefs.SHAPE_WIDE @@ -226,6 +239,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { private fun readPrefs() { hudOn = SessionPrefs.hudEnabled(this) + touchMode = SessionPrefs.touchMode(this) frameGenLabel = FrameGen.label(this) oscMode = SessionPrefs.oscMode(this) shapeMode = SessionPrefs.shapeMode(this) @@ -462,8 +476,37 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { if (SessionState.mode != SessionService.MODE_DESKTOP) uiHandler.postDelayed(cursorHide, 2500) } + /** Touchpad on the desktop, direct in Steam, unless the drawer says otherwise. */ + private fun usingTouchpad(): Boolean = when (SessionPrefs.touchMode(this)) { + SessionPrefs.TOUCH_PAD -> true + SessionPrefs.TOUCH_DIRECT -> false + else -> SessionState.mode == SessionService.MODE_DESKTOP + } + + /** The picture's rectangle inside the view: where the pointer may go. */ + private fun drawnRect(): android.graphics.RectF? { + val width = surfaceView.width.takeIf { it > 0 } ?: return null + val height = surfaceView.height.takeIf { it > 0 } ?: return null + val out = SessionState.outputSize + val scale = minOf(width / out.first.toFloat(), height / out.second.toFloat()) + val drawnW = out.first * scale + val drawnH = out.second * scale + val left = (width - drawnW) / 2f + val top = (height - drawnH) / 2f + return android.graphics.RectF(left, top, left + drawnW, top + drawnH) + } + override fun onTouchEvent(event: MotionEvent): Boolean { if (event.isFromSource(android.view.InputDevice.SOURCE_MOUSE)) return onMouse(event) + if (usingTouchpad()) { + val rect = drawnRect() ?: return false + if (touchpad.bounds != rect) { + val fresh = touchpad.bounds.width() <= 1f + touchpad.bounds = rect + if (fresh) touchpad.place(rect.centerX(), rect.centerY()) + } + return touchpad.onTouch(event) + } return gestures.onTouch(event) } diff --git a/app/src/main/java/com/steamdeck/launcher/input/TouchpadGestures.kt b/app/src/main/java/com/steamdeck/launcher/input/TouchpadGestures.kt new file mode 100644 index 0000000000..2279366d4f --- /dev/null +++ b/app/src/main/java/com/steamdeck/launcher/input/TouchpadGestures.kt @@ -0,0 +1,151 @@ +package com.steamdeck.launcher.input + +import android.os.Handler +import android.os.Looper +import android.view.MotionEvent +import kotlin.math.abs + +/** + * The screen as a touchpad, the way Bannerlator's desktop containers work: the arrow is where it + * was, and a finger dragged anywhere moves it from there. + * + * - drag one finger .................. moves the pointer (relative, with a little acceleration) + * - tap .............................. left click, where the pointer is + * - second finger taps while one holds right click + * - two-finger tap ................... right click + * - two fingers up / down ............ scroll wheel + * - hold still, then drag ............ left-button drag + * - double-tap, hold, drag ........... left-button drag as well + * + * Positions handed to the listener are the pointer's, in the view's pixels; the caller keeps them + * inside the picture. + */ +class TouchpadGestures( + private val slopPx: Float, + private val listener: PointerGestures.Listener, +) { + /** The pointer, tracked here since every move is relative. */ + var x = 0f + private set + var y = 0f + private set + var bounds: android.graphics.RectF = android.graphics.RectF(0f, 0f, 1f, 1f) + var sensitivity = 1.15f + + private val handler = Handler(Looper.getMainLooper()) + private var lastX = 0f + private var lastY = 0f + private var downAt = 0L + private var lastTapAt = 0L + private var travelled = 0f + private var dragging = false + private var held = false + private var secondDownAt = 0L + private var secondWasTap = false + private var twoFingers = false + private var scrollAnchorY = 0f + private var scrolled = false + private val longPress = Runnable { + held = true + dragging = true + listener.onLongPress() + listener.onButton(PointerGestures.BTN_LEFT, true, x, y) + } + + fun place(px: Float, py: Float) { + x = px.coerceIn(bounds.left, bounds.right) + y = py.coerceIn(bounds.top, bounds.bottom) + } + + fun onTouch(event: MotionEvent): Boolean { + when (event.actionMasked) { + MotionEvent.ACTION_DOWN -> { + lastX = event.x; lastY = event.y + downAt = event.eventTime + travelled = 0f; held = false; twoFingers = false; scrolled = false; secondWasTap = false + // A tap shortly before this touch: holding now drags (double-tap-and-hold). + if (event.eventTime - lastTapAt < DOUBLE_TAP_MS) { + dragging = true + listener.onButton(PointerGestures.BTN_LEFT, true, x, y) + } else { + dragging = false + handler.postDelayed(longPress, HOLD_MS) + } + return true + } + MotionEvent.ACTION_POINTER_DOWN -> { + handler.removeCallbacks(longPress) + twoFingers = true + secondDownAt = event.eventTime + secondWasTap = true + scrollAnchorY = (event.getY(0) + event.getY(1)) / 2f + return true + } + MotionEvent.ACTION_MOVE -> { + if (twoFingers && event.pointerCount >= 2) { + val mid = (event.getY(0) + event.getY(1)) / 2f + val dy = mid - scrollAnchorY + val steps = (dy / SCROLL_STEP_PX).toInt() + if (steps != 0) { + listener.onWheel(-steps) + scrollAnchorY += steps * SCROLL_STEP_PX + scrolled = true + secondWasTap = false + } + return true + } + val dx = event.x - lastX + val dy = event.y - lastY + lastX = event.x; lastY = event.y + travelled += abs(dx) + abs(dy) + if (travelled > slopPx) { + handler.removeCallbacks(longPress) + // A little acceleration: a slow finger is precise, a fast one crosses the screen. + val speed = (abs(dx) + abs(dy)) + val gain = sensitivity * (1f + minOf(speed / 40f, 1.5f)) + place(x + dx * gain, y + dy * gain) + listener.onMove(x, y) + } + return true + } + MotionEvent.ACTION_POINTER_UP -> { + // The second finger lifting quickly, with nothing scrolled: a right click. + if (twoFingers && secondWasTap && event.eventTime - secondDownAt < TAP_MS && !scrolled) { + listener.onButton(PointerGestures.BTN_RIGHT, true, x, y) + listener.onButton(PointerGestures.BTN_RIGHT, false, x, y) + secondWasTap = false + } + return true + } + MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { + handler.removeCallbacks(longPress) + val cancelled = event.actionMasked == MotionEvent.ACTION_CANCEL + when { + dragging -> listener.onButton(PointerGestures.BTN_LEFT, false, x, y) + twoFingers -> { + // Both fingers down and up together, no scroll: a right click. + if (secondWasTap && !scrolled && !cancelled && event.eventTime - downAt < TAP_MS * 2) { + listener.onButton(PointerGestures.BTN_RIGHT, true, x, y) + listener.onButton(PointerGestures.BTN_RIGHT, false, x, y) + } + } + !cancelled && travelled <= slopPx && event.eventTime - downAt < TAP_MS -> { + listener.onButton(PointerGestures.BTN_LEFT, true, x, y) + listener.onButton(PointerGestures.BTN_LEFT, false, x, y) + lastTapAt = event.eventTime + } + } + dragging = false; held = false; twoFingers = false + return true + } + } + return false + } + + companion object { + private const val HOLD_MS = 500L + private const val TAP_MS = 300L + private const val DOUBLE_TAP_MS = 300L + private const val SCROLL_STEP_PX = 36f + } +} diff --git a/app/src/main/java/com/steamdeck/launcher/runtime/LinuxNetworkLinkComponent.kt b/app/src/main/java/com/steamdeck/launcher/runtime/LinuxNetworkLinkComponent.kt index 4d13ca9110..b59738306e 100644 --- a/app/src/main/java/com/steamdeck/launcher/runtime/LinuxNetworkLinkComponent.kt +++ b/app/src/main/java/com/steamdeck/launcher/runtime/LinuxNetworkLinkComponent.kt @@ -67,6 +67,42 @@ class LinuxNetworkLinkComponent( } catch (e: IOException) { Log.w(TAG, "Could not publish the network link", e) } + writeResolver(properties) + } + } + + /** + * The guest's resolver, from the network it is actually on. glibc reads /etc/resolv.conf, + * and the image ships two public servers there, which is why Steam resolves at all — but a + * captive portal, a private-DNS network or a v6-only carrier wants the network's own + * servers. Those come first, IPv4 before IPv6 and never a link-local one (Android lists + * fe80:: resolvers a guest cannot reach; handing Bannerlator's Wine guests exactly that was + * the Pale Moon "no internet"). The public ones stay as fallback so nothing is ever worse + * than the image was. + */ + private fun writeResolver(properties: LinkProperties?) { + val own = properties?.dnsServers.orEmpty() + .filter { !it.isLinkLocalAddress && !it.isLoopbackAddress && !it.isAnyLocalAddress } + .sortedBy { if (it is Inet4Address) 0 else 1 } + .mapNotNull { it.hostAddress?.substringBefore('%') } + val servers = (own + listOf("8.8.8.8", "1.1.1.1", "2001:4860:4860::8888")).distinct().take(6) + val text = buildString { + append("# Written by the app from the device's active network; edits are overwritten.\n") + for (server in servers) append("nameserver $server\n") + append("options timeout:2 attempts:2\n") + } + try { + val etc = File(rootDir, "etc") + val staged = File(etc, "resolv.conf.staged") + staged.writeText(text) + if (!staged.renameTo(File(etc, "resolv.conf"))) throw IOException("Could not replace resolv.conf") + val hosts = File(etc, "hosts") + if (!hosts.isFile || !hosts.readText().contains("localhost")) { + hosts.writeText("127.0.0.1 localhost\n::1 localhost\n") + } + Log.i(TAG, "resolver: " + servers.joinToString(" ")) + } catch (e: IOException) { + Log.w(TAG, "Could not write the resolver", e) } } diff --git a/app/src/main/java/com/steamdeck/launcher/session/SessionPrefs.kt b/app/src/main/java/com/steamdeck/launcher/session/SessionPrefs.kt index 1aabacdc11..50970b1a72 100644 --- a/app/src/main/java/com/steamdeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/steamdeck/launcher/session/SessionPrefs.kt @@ -16,6 +16,18 @@ object SessionPrefs { prefs(context).edit().putBoolean("hud", on).apply() } + const val TOUCH_AUTO = "auto" + const val TOUCH_PAD = "touchpad" + const val TOUCH_DIRECT = "direct" + + /** How touch drives the pointer: a touchpad (drag moves it from where it is) or direct + * (it jumps under the finger). Auto = touchpad on the desktop, direct in Steam. */ + fun touchMode(context: Context): String = prefs(context).getString("touch", TOUCH_AUTO) ?: TOUCH_AUTO + + fun setTouchMode(context: Context, mode: String) { + prefs(context).edit().putString("touch", mode).apply() + } + const val SHAPE_AUTO = "auto" const val SHAPE_WIDE = "16:9" 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 d6f8fb1068..2eccc35e1f 100644 --- a/app/src/main/java/com/steamdeck/launcher/ui/SessionOverlay.kt +++ b/app/src/main/java/com/steamdeck/launcher/ui/SessionOverlay.kt @@ -89,12 +89,14 @@ class DrawerActions( val hudOn: Boolean, val frameGenLabel: String, val oscMode: String, + val touchMode: String, val shapeMode: String, val onHud: (Boolean) -> Unit, val onFrameGen: () -> Unit, val onKeyboard: () -> Unit, val onProtons: () -> Unit, val onOsc: () -> Unit, + val onTouch: () -> Unit, val onShape: () -> Unit, val onBackground: () -> Unit, val onStop: () -> Unit, @@ -143,6 +145,9 @@ fun SessionDrawer(a: DrawerActions) { OutlinedButton(onClick = a.onOsc, modifier = Modifier.fillMaxWidth().padding(top = 6.dp)) { Text("On-screen controls: ${a.oscMode}", fontSize = 13.sp) } + OutlinedButton(onClick = a.onTouch, modifier = Modifier.fillMaxWidth().padding(top = 6.dp)) { + Text("Touch: ${a.touchMode}", fontSize = 13.sp) + } OutlinedButton(onClick = a.onShape, modifier = Modifier.fillMaxWidth().padding(top = 6.dp)) { Text("Display shape: ${a.shapeMode} · next session", fontSize = 13.sp) }