fix(input): make a hardware mouse and keyboard work like a PC (#2053)

* feat(gamescope): a three way switch for relative mouse motion

Games that confine the cursor and warp it back to read movement never
reach the nested hints rule, so their aim stays bounded by the screen.
The convar defaults to 0 and leaves that rule alone; 1 forces relative
motion for the focused game, 2 keeps the pointer absolute even when the
rule would apply.

(cherry picked from commit db3d7555e0)

* feat(input): the session carries a relative mouse mode per game

Reads the mode from the game's gesture config, hands it to gamescope as
gamescope_relative_mouse, and pushes a change to the running session
through gamescopectl.

(cherry picked from commit e350d88464)

* feat(drawer): the relative mouse switch is a three way choice

Auto leaves it to the game, on forces relative motion, off keeps the
pointer absolute. Named in all 32 locales so none of the three falls
back to English.

(cherry picked from commit e96a187e02)

* fix(input): follow the focused game's relative mouse mode

Switching to a game whose saved mode differs left the session on the
previous game's mode, since only the drawer state was refreshed. The
requests also ran on a thread per selection, so two quick picks could
reach gamescope out of order.

(cherry picked from commit 7ff8c5d568)

* fix(input): retry the relative mouse mode gamescope did not take

The drawer state moved before the request ran, so a failed request left
the two out of step and the next focus change skipped the resend.

(cherry picked from commit cf0f82d8cd)

* fix(input): the relative mouse mode tracks the latest choice

The guest agent answers ok when it handled the exec, so a failing
gamescopectl was recorded as applied. Reconcile the newest desired mode
on the worker thread after each request, and only mark applied when the
command really exited zero.

(cherry picked from commit 5f5e3bd52e)

* gamescope: a hidden cursor under any pointer constraint is relative

Games that hide the cursor and confine the pointer had no lock hint, so the
nested pointer stayed absolute and the camera froze.

* Treat a hardware mouse as a real mouse in sessions

A mouse now moves the guest pointer by relative motion for the whole session
through pointer capture, so it no longer stops at screen edges or reaches
system gestures. Its cursor stays visible in every touch mode, follows the
game showing or hiding it, and clicks no longer press on-screen controls.

* gamescope: use the mouse test release

* Direct touch turns the camera while a game holds the pointer

A swipe in direct touch now sends relative motion when a game has the pointer
locked, including when the lock starts during the swipe, as when a game
hides the cursor while a button is held.

* Address review findings on mouse and touch input

Keep touchpad taps on on-screen controls, cancel a pending long press during a
locked swipe, let the three-finger gesture cancel a locked swipe, refresh
capture when the output changes, and use the menu's key for the relative
mouse setting.

* Keep locked touches inside the game picture and free the mouse in touch editors

* End touch editor ownership when the editor goes away

* Bring the mouse cursor back when a touch editor closes

* Release a pointer lock at the game's pointer

* gamescope: use the pointer position test release

* Fit the X screen to a fullscreen window larger than it

* gamescope: use the X screen fit test release

* Return the X screen when no game window has focus

* gamescope: use the X screen return test release

* ci: avoid redundant gamescope builds

* fix: hardware mouse in Desktop and pointer warping games

KWin nested on the host only reads relative motion while its own pointer lock is on, so a program that locked the pointer in Desktop (Blender orbit and pan) stopped receiving motion. A captured hardware mouse now turns that lock on, and a real Right Ctrl no longer toggles it.

Gamescope follows a game's pointer warps instead of overriding them, and absolute motion also sends raw motion. Also retries relative mouse requests, tidies the unplug path, passes side buttons and fits a second oversized window correctly.

* chore: use the gamescope build with patch 0131

* fix: Desktop mouse lock keeps retrying after early attempts fail

* fix: hold the key that turns on the Desktop mouse lock

KWin ignores a press and release delivered together.

* fix: gamescope enters warp following sooner and keeps steady motion

* chore: use gamescope p26

* Capture system keys in a focused session and keep the first Desktop mouse motion in place

* Use the p27 gamescope build

* Update the system keys row test

* Recognise a captured mouse so the Desktop grab can start

* Keep touch warps out of relative motion

* Send Esc from keyboards that report it as Back

* Use the p28 gamescope build

* Release captured keys on pause, forward motion during a grab and wait for a pending screen fit

* Use the p29 gamescope build

* fix(input): keep held system keys consumed until they are released

Copy each captured key event, since the service owns the original only for the callback, and consume the physical release of a key already released to the guest.

Use the published gamescope p20.

* fix(input): capture a system key only from its first press

---------

Co-authored-by: kingokksa <kingokksa@qq.com>
Co-authored-by: maxjivi05 <6025299+maxjivi05@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-11-04 13:27:08 -05:00
1 parent eed9edaa1c
commit 5cf69732ef
56 files changed
+1210 -212

No files matched your search

@@ -324,11 +324,8 @@ class FrontEndActivity : ComponentActivity() {
SteamIntegration.Feature.HOME -> if (HomeApp.isDefault(this)) HomeApp.openSystemHomeSettings(this) else offerHomeScreen()
SteamIntegration.Feature.SHORTCUTS -> {
if (!integrationState.shortcuts) shortcutsTried = true
if (!HomeApp.isDefault(this)) configureIntegration(SteamIntegration.Feature.HOME)
else {
SteamIntegration.setShortcutsListed(this, true)
integrationSettings(SteamIntegration.shortcutSettings(this), android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS)
}
SteamIntegration.setShortcutsListed(this, true)
integrationSettings(SteamIntegration.shortcutSettings(this), android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS)
}
}
}
@@ -224,6 +224,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
private var steamImportAsk by mutableStateOf<com.droiddeck.launcher.session.SteamImportPrompt.Ask?>(null)
private var steamImportAnswered: String? = null
private var directHoldBehavior by mutableStateOf(com.droiddeck.launcher.input.TouchGestureConfig.MOUSE_BEHAVIOR_CLICK)
private var relativeMouseMode by mutableIntStateOf(0)
@Volatile private var appliedRelativeMouseMode: Int? = null
private var screenKeyPickerOpen by mutableStateOf(false)
private var screenKeyBind: List<Int>? = null
private var screenKeyDir: Int? = null
@@ -257,20 +259,29 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
private val cursorPosBuf = IntArray(2)
private var cursorSerial = 0
private var clientHidesCursor = false
private var mouseOwnsCursor = false
private var pointerLocked = false
private var desktopGrabTapAt = 0L
private var desktopGrabTaps = 0
private var desktopMousePlaced = false
private val pointerLockListener = WaylandCompositor.PointerLockListener { locked, _, _ ->
uiHandler.post {
if (pointerLocked == locked) return@post
gesturePointerReady = false
pointerLocked = locked
Log.i(TAG, "pointer lock " + if (locked) "taken by a program" else "released")
if (locked) openEvdevMouse() else closeEvdevMouse()
if (locked) desktopGrabTaps = 0
if (programLocksPointer()) openEvdevMouse() else closeEvdevMouse()
padMouseCheckedAt = 0L
if (::padMouse.isInitialized) padMouseMode()
if (locked && ::touchpad.isInitialized) {
drawnRect()?.let { touchpad.place(it.centerX(), it.centerY()) }
cursorVisible = false
}
if (!locked && mouseOwnsCursor) {
uiHandler.removeCallbacks(cursorResync)
uiHandler.post(cursorResync)
}
updatePointerCapture()
}
}
@@ -283,6 +294,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
override fun run() {
if (syncClientCursor() && clientHidesCursor) {
cursorVisible = false
if (!mouseOwnsCursor) return
}
if (mouseOwnsCursor) {
if (pointerLocked) return
alignCursorToGuest()
if (!clientHidesCursor) cursorVisible = true
uiHandler.postDelayed(this, 60)
return
}
if (touchDrivesPointer()) return
@@ -564,6 +582,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
override fun onInputDeviceRemoved(deviceId: Int) {
physicalShortcuts.onDeviceRemoved(deviceId)
Log.i(TAG, "input device $deviceId disconnected")
dropMouseCursor()
backQamInput.onDeviceRemoved(deviceId)
joyConVr?.refresh()
padBridge?.onDeviceRemoved(deviceId)
@@ -644,6 +663,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
override fun dispatchPointerCaptureChanged(hasCapture: Boolean) {
super.dispatchPointerCaptureChanged(hasCapture)
Log.i(TAG, "pointer capture " + if (hasCapture) "on" else "off")
if (!hasCapture) uiHandler.postDelayed(::updatePointerCapture, 250)
}
}
sessionRoot = root
@@ -681,6 +701,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
bridge.setOnPlayerInput {
lastPadInputMs = android.os.SystemClock.uptimeMillis()
uiHandler.removeCallbacks(cursorHide)
mouseOwnsCursor = false
cursorVisible = false
}
onScreenControls = OnScreenControls(this, bridge, onKeyboard = ::togglePcKeyboard).also { controls ->
@@ -700,7 +721,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
}
keys.onAdd = { screenKeyPickerOpen = true }
keys.onSelect = { codes -> screenKeyEdit = screenKeys?.stateOf(codes) }
keys.onEditingChanged = { if (!it) screenKeyEdit = null }
keys.onEditingChanged = { touchEditorChanged(); if (!it) screenKeyEdit = null }
keys.steamStyle = { steamTouchControls?.style }
keys.visibility = if (screenKeysShown) View.VISIBLE else View.GONE
root.addView(keys)
@@ -1316,7 +1337,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
onEvdevMouse = { on ->
SessionPrefs.setEvdevMouse(this@SessionActivity, on)
evdevMouseOn = on
if (on) { if (pointerLocked) openEvdevMouse() } else releaseEvdevMouse()
if (on) { if (programLocksPointer()) openEvdevMouse() } else releaseEvdevMouse()
},
directCursor = directCursorOn,
onDirectCursor = { on ->
@@ -1354,7 +1375,14 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
com.droiddeck.launcher.input.GesturePrefs.save(this@SessionActivity, gestureGame, base.copy(directHoldBehavior = value))
refreshGestureConfig()
},
onScreenKeys = { drawerOpen = false; screenKeys?.startEditing() },
relativeMouseMode = relativeMouseMode,
onRelativeMouseMode = { mode ->
val base = com.droiddeck.launcher.input.GesturePrefs.read(this@SessionActivity, gestureGame)
com.droiddeck.launcher.input.GesturePrefs.save(this@SessionActivity, gestureGame, base.copy(relativeMouseMode = mode))
relativeMouseMode = mode
setRelativeMouse(mode)
},
onScreenKeys = { if (screenKeysShown) { drawerOpen = false; screenKeys?.startEditing() } },
screenKeysShown = screenKeysShown,
onScreenKeysShown = { shown ->
screenKeysShown = shown
@@ -2647,7 +2675,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
if (joyConVr?.onKeyEvent(event) == true) return true
if (fromController && event.keyCode != KeyEvent.KEYCODE_BACK && padMouseMode() && padMouse.onKey(event)) return true
if (event.keyCode != KeyEvent.KEYCODE_BACK && padBridge?.onKeyEvent(event) == true) return true
if (CompositorHost.isStarted && event.keyCode != KeyEvent.KEYCODE_BACK && !fromController) {
val keyboardKey = event.keyCode != KeyEvent.KEYCODE_BACK ||
com.droiddeck.launcher.input.GuestKeys.isKeyboardEscape(event.keyCode, event.scanCode)
if (CompositorHost.isStarted && keyboardKey && !fromController) {
val down = event.action == KeyEvent.ACTION_DOWN
if (down && event.repeatCount > 0) return true
if (com.droiddeck.launcher.input.GuestKeys.send(event, ::sendGuestKey)) return true
@@ -2694,6 +2724,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
if (event.isFromSource(android.view.InputDevice.SOURCE_MOUSE) && !drawerOpen) {
if (appUiOwnsPointer()) {
if (super.dispatchGenericMotionEvent(event)) return true
if (touchEditorOpen) return false
if (onMouse(event)) return true
return false
}
@@ -2847,9 +2878,48 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
private fun layoutNames(): List<String> =
com.droiddeck.launcher.input.ControllerPrefs.screenLayouts(this).keys.sorted()
private val relativeMouseRequests = java.util.concurrent.Executors.newSingleThreadExecutor { runnable ->
Thread(runnable, "relative-mouse").apply { isDaemon = true }
}
@Volatile private var desiredRelativeMouseMode = 0
@Volatile private var relativeMouseRetries = 0
private fun setRelativeMouse(mode: Int) {
desiredRelativeMouseMode = mode
relativeMouseRetries = 0
requestRelativeMouse()
}
private fun requestRelativeMouse() {
runCatching { relativeMouseRequests.execute { applyRelativeMouse() } }
}
private fun applyRelativeMouse() {
val mode = desiredRelativeMouseMode
if (appliedRelativeMouseMode == mode) return
val request = org.json.JSONObject()
.put("kind", "exec")
.put("argv", org.json.JSONArray(listOf("gamescopectl", "relative_mouse", mode.toString())))
.put("timeout", 5.0)
val result = runCatching { AgentGuest.call(this, request, 8_000, trusted = true) }
val answer = result.getOrNull()
val applied = answer?.optBoolean("ok") == true
&& answer.optInt("exitCode", -1) == 0
&& !answer.optBoolean("timedOut")
if (applied) appliedRelativeMouseMode = mode
else {
Log.w(TAG, "gamescope did not take relative mouse $mode: ${result.exceptionOrNull() ?: answer}")
if (relativeMouseRetries++ < RELATIVE_MOUSE_MAX_RETRIES) uiHandler.postDelayed({ requestRelativeMouse() }, 2_000)
}
if (desiredRelativeMouseMode != mode) requestRelativeMouse()
}
private fun refreshGestureConfig() {
gestureConfig = com.droiddeck.launcher.input.GesturePrefs.read(this, gestureGame)
directHoldBehavior = gestureConfig.directHoldBehavior
relativeMouseMode = gestureConfig.relativeMouseMode
setRelativeMouse(relativeMouseMode)
gestureTouchStreamGate.reset()
if (::touchscreenGestures.isInitialized) touchscreenGestures.configure(gestureConfig)
if (::directTouchHold.isInitialized) directTouchHold.configure(gestureConfig)
@@ -3018,26 +3088,38 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
cursorVisible = false
}
private fun movePointer(x: Float, y: Float) {
private fun movePointer(x: Float, y: Float, fromMouse: Boolean = false) {
val rect = drawnRect() ?: return
val cx = x.coerceIn(rect.left, rect.right)
val cy = y.coerceIn(rect.top, rect.bottom)
WaylandCompositor.nativeSendPointer(1, InputSpace.x(cx, outputView().width), InputSpace.y(cy, outputView().height))
showCursor(cx, cy)
showCursor(cx, cy, fromMouse)
}
private fun showCursor(x: Float, y: Float) {
private fun moveCapturedMouse(dx: Float, dy: Float) {
val rect = drawnRect() ?: return
val scale = sceneScale(rect)
WaylandCompositor.sendPointerDelta(dx, dy)
showCursor(
(cursorPos.x + dx / scale).coerceIn(rect.left, rect.right),
(cursorPos.y + dy / scale).coerceIn(rect.top, rect.bottom),
fromMouse = true,
)
}
private fun showCursor(x: Float, y: Float, fromMouse: Boolean = false) {
cursorPos = androidx.compose.ui.geometry.Offset(x, y)
syncClientCursor()
mouseOwnsCursor = fromMouse
uiHandler.removeCallbacks(cursorResync)
cursorResyncIdle = 0
if (!touchDrivesPointer()) uiHandler.postDelayed(cursorResync, 60)
if (fromMouse || !touchDrivesPointer()) uiHandler.postDelayed(cursorResync, 60)
if (clientHidesCursor) { cursorVisible = false; return }
if (directTouchCursorHidden()) { cursorVisible = false; return }
if (!fromMouse && directTouchCursorHidden()) { cursorVisible = false; return }
if (android.os.SystemClock.uptimeMillis() - lastPadInputMs < CURSOR_PAD_HOLD_MS) return
cursorVisible = true
uiHandler.removeCallbacks(cursorHide)
if (SessionState.mode == SessionService.MODE_STEAM && SessionState.steamUi != "desktop") uiHandler.postDelayed(cursorHide, 2500)
if (!fromMouse && SessionState.mode == SessionService.MODE_STEAM && SessionState.steamUi != "desktop") uiHandler.postDelayed(cursorHide, 2500)
}
private fun touchDrivesPointer(): Boolean =
@@ -3562,6 +3644,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
}
private var ignoreGameTouch = false
private var lockedTouchTurns = false
private var touchEditorOpen by mutableStateOf(false)
private var lockedSwipeUsed = false
private var lockedSwipeX = 0f
private var lockedSwipeY = 0f
private var dismissTouch = false
override fun onTouchEvent(event: MotionEvent): Boolean {
@@ -3604,11 +3691,15 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
}
com.droiddeck.launcher.input.TouchRouter.Route.SCROLL -> scrollTouch.onTouch(event)
else -> {
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
val inPicture = drawnRect()?.let { !topPictureMapped || it.contains(event.x, event.y) } ?: false
lockedTouchTurns = programLocksPointer() && inPicture && route != com.droiddeck.launcher.input.TouchRouter.Route.TOUCHPAD
}
if (com.droiddeck.launcher.input.TouchRouter.steamKeyboardZone(snapshot)) {
val wasActive = threeFingerTap.active
if (threeFingerTap.onTouch(event)) padBridge?.triggerSteamKeyboard()
if (threeFingerTap.active && !wasActive) {
if (route == com.droiddeck.launcher.input.TouchRouter.Route.TOUCHPAD) touchpad.cancel()
if (route == com.droiddeck.launcher.input.TouchRouter.Route.TOUCHPAD || lockedTouchTurns) touchpad.cancel()
else {
directTouchHold.cancel()
WaylandCompositor.nativeSendTouch(3, -1, 0, 0)
@@ -3616,7 +3707,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
}
if (threeFingerTap.active || wasActive) return true
}
if (route == com.droiddeck.launcher.input.TouchRouter.Route.TOUCHPAD) {
if (route == com.droiddeck.launcher.input.TouchRouter.Route.TOUCHPAD || lockedTouchTurns) {
val rect = drawnRect() ?: return false
if (touchpad.bounds != rect) {
val fresh = touchpad.bounds.width() <= 1f
@@ -3668,8 +3759,25 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
}
private fun forwardTouch(event: MotionEvent, rect: android.graphics.RectF): Boolean {
val swipeX = lockedSwipeX
val swipeY = lockedSwipeY
lockedSwipeX = event.x
lockedSwipeY = event.y
if ((event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) && lockedSwipeUsed) {
lockedSwipeUsed = false
directTouchHold.cancel()
return true
}
if (event.actionMasked == MotionEvent.ACTION_DOWN) lockedSwipeUsed = false
if (programLocksPointer() && event.actionMasked == MotionEvent.ACTION_MOVE) {
lockedSwipeUsed = true
directTouchHold.cancelPendingHold()
val scale = sceneScale(rect)
sendSceneDelta((event.x - swipeX) * scale, (event.y - swipeY) * scale)
return true
}
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
showCursor(event.x.coerceIn(rect.left, rect.right), event.y.coerceIn(rect.top, rect.bottom))
if (!pointerLocked) showCursor(event.x.coerceIn(rect.left, rect.right), event.y.coerceIn(rect.top, rect.bottom))
if (WaylandCompositor.nativeFocusTakesTouch()) {
listOf(PointerGestures.BTN_LEFT, PointerGestures.BTN_RIGHT, PointerGestures.BTN_MIDDLE).forEach {
WaylandCompositor.nativeSendSceneInput(3, it, 0)
@@ -3683,12 +3791,14 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
private fun onMouse(event: MotionEvent): Boolean {
when (event.actionMasked) {
MotionEvent.ACTION_HOVER_MOVE, MotionEvent.ACTION_MOVE, MotionEvent.ACTION_HOVER_ENTER ->
if (evdevMouseActive) sendMouseDelta(event.x, event.y) else movePointer(event.x, event.y)
if (evdevMouseActive) sendMouseDelta(event.x, event.y) else movePointer(event.x, event.y, fromMouse = true)
MotionEvent.ACTION_BUTTON_PRESS, MotionEvent.ACTION_BUTTON_RELEASE -> {
if (evdevMouseActive) sendMouseDelta(event.x, event.y) else movePointer(event.x, event.y)
if (evdevMouseActive) sendMouseDelta(event.x, event.y) else movePointer(event.x, event.y, fromMouse = true)
val button = when (event.actionButton) {
MotionEvent.BUTTON_SECONDARY -> PointerGestures.BTN_RIGHT
MotionEvent.BUTTON_TERTIARY -> PointerGestures.BTN_MIDDLE
MotionEvent.BUTTON_BACK -> BTN_SIDE
MotionEvent.BUTTON_FORWARD -> BTN_EXTRA
else -> PointerGestures.BTN_LEFT
}
sendSceneButton(button, event.actionMasked == MotionEvent.ACTION_BUTTON_PRESS)
@@ -3703,23 +3813,79 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
return true
}
private fun mouseAttached(): Boolean = InputDevice.getDeviceIds().any { id ->
private fun isHardwareMouse(d: InputDevice?): Boolean =
d != null && !d.isVirtual && (d.supportsSource(InputDevice.SOURCE_MOUSE) || d.supportsSource(InputDevice.SOURCE_MOUSE_RELATIVE))
private fun mouseAttached(): Boolean = InputDevice.getDeviceIds().any { isHardwareMouse(InputDevice.getDevice(it)) }
private fun relativeMouseAttached(): Boolean = !isInMultiWindowMode && !glassesOutputActive && InputDevice.getDeviceIds().any { id ->
val d = InputDevice.getDevice(id)
d != null && !d.isVirtual && d.supportsSource(InputDevice.SOURCE_MOUSE)
isHardwareMouse(d) && d?.supportsSource(InputDevice.SOURCE_TOUCHPAD) != true
}
private fun updatePointerCapture() {
if (!::surfaceView.isInitialized) return
val view = window.decorView
val want = pointerLocked && resumed && hasWindowFocus() && !drawerOpen && !pcKeyboardOpen && !achievementsOpen && !pipUi && !bottomOutputActive && mouseAttached()
val want = (pointerLocked || relativeMouseAttached()) && resumed && hasWindowFocus() && !drawerOpen && !pcKeyboardOpen && !achievementsOpen && !pipUi && !bottomOutputActive && !touchEditorOpen && mouseAttached()
releaseDesktopMouseGrab()
if (want == view.hasPointerCapture()) return
if (want) view.requestPointerCapture() else view.releasePointerCapture()
}
private fun programLocksPointer(): Boolean =
pointerLocked && SessionState.mode != SessionService.MODE_DESKTOP
private fun desktopMouseGrabAllowed(): Boolean =
SessionState.mode == SessionService.MODE_DESKTOP && relativeMouseAttached() && !bottomOutputActive
private fun tapDesktopGrabKey() {
val now = android.os.SystemClock.uptimeMillis()
if (now - desktopGrabTapAt < DESKTOP_GRAB_TAP_MS) return
desktopGrabTapAt = now
desktopGrabTaps++
WaylandCompositor.nativeSendKey(KEY_RIGHTCTRL, 1)
uiHandler.postDelayed({ WaylandCompositor.nativeSendKey(KEY_RIGHTCTRL, 0) }, DESKTOP_GRAB_KEY_HOLD_MS)
}
private fun grabDesktopMouse() {
if (!desktopMouseGrabAllowed()) return
if (desktopGrabTaps >= DESKTOP_GRAB_MAX_TAPS) {
if (android.os.SystemClock.uptimeMillis() - desktopGrabTapAt < DESKTOP_GRAB_RETRY_MS) return
desktopGrabTaps = 0
}
if (!desktopMousePlaced) {
desktopMousePlaced = true
drawnRect()?.let { movePointer(it.centerX(), it.centerY()) }
}
tapDesktopGrabKey()
}
private fun releaseDesktopMouseGrab() {
if (pointerLocked && SessionState.mode == SessionService.MODE_DESKTOP && !desktopMouseGrabAllowed()) tapDesktopGrabKey()
}
private fun dropMouseCursor() {
if (!mouseOwnsCursor || mouseAttached()) return
mouseOwnsCursor = false
uiHandler.removeCallbacks(cursorResync)
cursorVisible = false
}
override fun onMultiWindowModeChanged(isInMultiWindowMode: Boolean, newConfig: android.content.res.Configuration) {
super.onMultiWindowModeChanged(isInMultiWindowMode, newConfig)
updatePointerCapture()
}
private var platformPointerShown: Boolean? = null
private fun touchEditorChanged() {
touchEditorOpen = screenKeys?.isEditing == true || steamTouchControls?.isEditing == true
updatePointerCapture()
applyPlatformPointer(appUiOwnsPointer())
}
private fun appUiOwnsPointer(): Boolean =
drawerOpen || pcKeyboardOpen || achievementsOpen || pipUi || glassesOutputActive || bottomOutputActive
drawerOpen || pcKeyboardOpen || achievementsOpen || pipUi || glassesOutputActive || bottomOutputActive || touchEditorOpen
private fun applyPlatformPointer(shown: Boolean) {
if (!::sessionRoot.isInitialized || !::surfaceView.isInitialized) return
@@ -3732,7 +3898,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
}
private fun onCapturedPointer(event: MotionEvent): Boolean {
if (!pointerLocked || !event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE)) return false
if (!event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE)) return false
notePress(event)
when (event.actionMasked) {
MotionEvent.ACTION_MOVE -> {
@@ -3742,7 +3908,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
dx += event.getHistoricalX(i)
dy += event.getHistoricalY(i)
}
sendSceneDelta(dx, dy)
if (pointerLocked) sendSceneDelta(dx, dy)
else {
grabDesktopMouse()
moveCapturedMouse(dx, dy)
}
}
MotionEvent.ACTION_BUTTON_PRESS, MotionEvent.ACTION_BUTTON_RELEASE -> {
val button = when (event.actionButton) {
@@ -3773,6 +3943,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
val device = com.droiddeck.launcher.input.SteamTouchDevice.current ?: return null
steamTouchControls?.let { view ->
if (view.device === device) return view
view.cancelEditing()
view.releaseAll()
(view.parent as? android.view.ViewGroup)?.removeView(view)
steamTouchControls = null
@@ -3781,6 +3952,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
val view = com.droiddeck.launcher.input.SteamTouchControls(this, device,
onMenu = { drawerOpen = true }, onKeyboard = ::togglePcKeyboard)
view.visibility = View.GONE
view.onEditingChanged = { touchEditorChanged() }
view.onOptions = { options ->
steamTouchOptions = options
applyTouchRouting()
@@ -3827,7 +3999,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
onScreenButtonsVisible = false
controls.releaseAll()
controls.visibility = View.GONE
steamTouchControls?.let { it.releaseAll(); it.visibility = View.GONE }
steamTouchControls?.let { it.cancelEditing(); it.releaseAll(); it.visibility = View.GONE }
com.droiddeck.launcher.input.SteamTouchDevice.current?.plugged = false
screenKeys?.followSteam = false
applyTouchRouting()
@@ -3841,7 +4013,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
uiHandler.postDelayed(steamTouchRetry, 1000)
}
if (steam == null) {
steamTouchControls?.let { it.releaseAll(); it.visibility = View.GONE }
steamTouchControls?.let { it.cancelEditing(); it.releaseAll(); it.visibility = View.GONE }
com.droiddeck.launcher.input.SteamTouchDevice.current?.plugged = false
applyTouchRouting()
}
@@ -3860,7 +4032,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
if (steam != null) {
screenKeys?.followSteam = drawn
if (controls.visibility == View.VISIBLE) { controls.releaseAll(); controls.visibility = View.GONE }
if (!drawn) steam.releaseAll()
if (!drawn) { steam.cancelEditing(); steam.releaseAll() }
steam.visibility = if (drawn) View.VISIBLE else View.GONE
com.droiddeck.launcher.input.SteamTouchDevice.current?.plugged = show
applyTouchRouting()
@@ -3935,8 +4107,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
private fun keyboardCoversPad() =
SessionState.mode == SessionService.MODE_STEAM && AgentGuest.steamKeyboard
private fun sendGuestKey(code: Int, down: Boolean) {
private fun sendGuestKey(key: Int, down: Boolean) {
if (down && pipUi) return
val code = if (key == KEY_RIGHTCTRL && SessionState.mode == SessionService.MODE_DESKTOP) KEY_LEFTCTRL else key
if (down) guestKeysDown.add(code) else guestKeysDown.remove(code)
if (down || code !in gestureKeysDown) WaylandCompositor.nativeSendKey(code, if (down) 1 else 0)
}
@@ -4135,6 +4308,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
override fun onResume() {
super.onResume()
com.droiddeck.launcher.input.SystemKeyCapture.attach(this, { hasWindowFocus() && !appUiOwnsPointer() && CompositorHost.isStarted }) { event ->
com.droiddeck.launcher.input.GuestKeys.send(event, ::sendGuestKey)
}
if (refreshActivityDisplayId() && started) {
SessionService.setActivityDisplay(this, sessionActivityDisplayId)
}
@@ -4178,6 +4354,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
}
override fun onPause() {
com.droiddeck.launcher.input.SystemKeyCapture.detach(this)
com.droiddeck.launcher.input.HomeButtonShortcuts.detach(this)
if (runtimeRemovalBlocked) { super.onPause(); return }
physicalShortcuts.clear()
@@ -4420,6 +4597,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
if (holder !== outputHolder()) return
glassesOutputActive = glassesScreen?.holder === holder
bottomOutputActive = bottomGame?.holder === holder
updatePointerCapture()
if (bottomOutputActive) bottomRecoveries = 0
if (CompositorHost.isStarted) WaylandCompositor.nativeSetCursorComposite(glassesOutputActive || bottomOutputActive)
surfaceView.visibility = if (glassesOutputActive || bottomOutputActive) View.INVISIBLE else View.VISIBLE
@@ -4794,6 +4972,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
override fun onDestroy() {
com.droiddeck.launcher.input.HomeButtonShortcuts.detach(this)
relativeMouseRequests.shutdownNow()
backQamInput.cancel()
steamVrRecovery.close()
uiHandler.removeCallbacks(steamTouchRetry)
@@ -4908,6 +5087,14 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
private const val PAD_SCROLL_HEIGHTS_PER_S = 3f
private const val AXIS_UNITS_PER_PIXEL = 3f
private const val KEY_LEFTCTRL = 29
private const val KEY_RIGHTCTRL = 97
private const val BTN_SIDE = 0x113
private const val BTN_EXTRA = 0x114
private const val DESKTOP_GRAB_TAP_MS = 500L
private const val DESKTOP_GRAB_MAX_TAPS = 8
private const val DESKTOP_GRAB_RETRY_MS = 30_000L
private const val DESKTOP_GRAB_KEY_HOLD_MS = 40L
private const val RELATIVE_MOUSE_MAX_RETRIES = 5
private const val DRAWER_HAT_THRESHOLD = 0.5f
private const val DRAWER_STICK_ENTER_THRESHOLD = 0.55f
private const val DRAWER_STICK_EXIT_THRESHOLD = 0.35f
@@ -66,6 +66,10 @@ class DirectTouchHold(
held = false
}
fun cancelPendingHold() {
handler.removeCallbacks(hold)
}
fun onTouch(event: MotionEvent): Boolean {
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
if (liftPending) {
@@ -7,7 +7,7 @@ object GuestKeys {
fun send(event: KeyEvent, sendKey: (code: Int, down: Boolean) -> Unit): Boolean {
val down = event.action == KeyEvent.ACTION_DOWN
if (!down && event.action != KeyEvent.ACTION_UP) return false
var evdev = EvdevKeys.fromKeyCode(event.keyCode)
var evdev = if (isKeyboardEscape(event.keyCode, event.scanCode)) KEY_ESC else EvdevKeys.fromKeyCode(event.keyCode)
val ch = event.unicodeChar
val plain = if (ch > 0) EvdevKeys.unshiftedChar(ch) else 0
if (evdev <= 0 && ch > 0) {
@@ -27,5 +27,9 @@ object GuestKeys {
return true
}
fun isKeyboardEscape(keyCode: Int, scanCode: Int): Boolean =
keyCode == KeyEvent.KEYCODE_BACK && scanCode == KEY_ESC
private const val KEY_ESC = 1
private const val KEY_LEFTSHIFT = 42
}
@@ -45,6 +45,62 @@ object HomeButtonShortcuts {
fun onDeviceRemoved(device: Int) = input.onDeviceRemoved(device)
}
object SystemKeyCapture {
private var owner: Any? = null
private var active: () -> Boolean = { false }
private var send: (KeyEvent) -> Unit = {}
private val held = HashMap<Pair<Int, Int>, KeyEvent>()
private val releasing = HashSet<Pair<Int, Int>>()
internal var isKeyboard: (KeyEvent) -> Boolean = ::fromKeyboard
fun attach(owner: Any, active: () -> Boolean, send: (KeyEvent) -> Unit) {
this.owner = owner
this.active = active
this.send = send
}
fun detach(owner: Any) {
if (this.owner !== owner) return
held.values.forEach { send(KeyEvent.changeAction(it, KeyEvent.ACTION_UP)) }
releasing += held.keys
held.clear()
this.owner = null
active = { false }
send = {}
}
internal fun captures(keyCode: Int, metaState: Int): Boolean = when {
keyCode == KeyEvent.KEYCODE_META_LEFT || keyCode == KeyEvent.KEYCODE_META_RIGHT -> true
metaState and KeyEvent.META_META_ON != 0 -> true
metaState and KeyEvent.META_ALT_ON != 0 -> keyCode == KeyEvent.KEYCODE_TAB || keyCode == KeyEvent.KEYCODE_ESCAPE
else -> false
}
private fun fromKeyboard(event: KeyEvent): Boolean =
event.device?.let { !it.isVirtual && it.keyboardType == android.view.InputDevice.KEYBOARD_TYPE_ALPHABETIC } == true
fun onKeyEvent(event: KeyEvent): Boolean {
val key = event.deviceId to event.keyCode
if (event.action == KeyEvent.ACTION_DOWN && event.repeatCount == 0) {
releasing -= key
} else if (key in releasing) {
if (event.action == KeyEvent.ACTION_UP) releasing -= key
return true
}
val taken = when (event.action) {
KeyEvent.ACTION_DOWN -> {
val take = key in held || (event.repeatCount == 0 && active() && isKeyboard(event) && captures(event.keyCode, event.metaState))
if (take) held[key] = KeyEvent(event)
take
}
KeyEvent.ACTION_UP -> held.remove(key) != null
else -> false
}
if (taken) send(event)
return taken
}
}
class HomeButtonService : AccessibilityService(), InputManager.InputDeviceListener {
private var bottomScreen: BottomScreenWatch? = null
@@ -58,7 +114,8 @@ class HomeButtonService : AccessibilityService(), InputManager.InputDeviceListen
bottomScreen = null
}
override fun onKeyEvent(event: KeyEvent) = HomeButtonShortcuts.onKeyEvent(this, event)
override fun onKeyEvent(event: KeyEvent) =
SystemKeyCapture.onKeyEvent(event) || HomeButtonShortcuts.onKeyEvent(this, event)
override fun onAccessibilityEvent(event: AccessibilityEvent?) { event?.let { bottomScreen?.onEvent(it) } }
override fun onInterrupt() { HomeButtonShortcuts.release() }
override fun onInputDeviceAdded(deviceId: Int) {}
@@ -519,6 +519,7 @@ class OnScreenControls(
@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent): Boolean {
if (editing) return onEditTouch(event)
if (event.getToolType(event.actionIndex) == MotionEvent.TOOL_TYPE_MOUSE) return false
when (event.actionMasked) {
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_POINTER_DOWN -> {
val index = event.actionIndex
@@ -56,6 +56,7 @@ class ScreenKeys(context: Context, private val sendKey: (Int, Boolean) -> Unit)
private var guideY = -1f
private val addPress = Runnable { addX = pressX; addY = pressY; onAdd?.invoke() }
private var editing = false
val isEditing get() = editing
private var selected: Entry? = null
private var dragX = 0f
private var dragY = 0f
@@ -811,6 +812,7 @@ class ScreenKeys(context: Context, private val sendKey: (Int, Boolean) -> Unit)
override fun onTouchEvent(event: MotionEvent): Boolean = if (editing) editTouch(event) else playTouch(event)
private fun playTouch(event: MotionEvent): Boolean {
if (event.getToolType(event.actionIndex) == MotionEvent.TOOL_TYPE_MOUSE) return false
when (event.actionMasked) {
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_POINTER_DOWN -> {
val index = event.actionIndex
@@ -107,6 +107,7 @@ class SteamTouchControls(
var onTouchMiss: ((MotionEvent) -> Unit)? = null
private var editing = false
var onEditingChanged: ((Boolean) -> Unit)? = null
private var editElements: MutableList<Element> = mutableListOf()
private var hidden: MutableList<Element> = mutableListOf()
private var selected = -1
@@ -617,6 +618,7 @@ class SteamTouchControls(
}
return true
}
if (event.getToolType(event.actionIndex) == MotionEvent.TOOL_TYPE_MOUSE) return false
val index = event.actionIndex
lastTouchMs = android.os.SystemClock.uptimeMillis()
if (faded) { faded = false; invalidate() }
@@ -705,6 +707,7 @@ class SteamTouchControls(
fun startEditing() {
releaseAll()
editing = true
onEditingChanged?.invoke(true)
editSets.clear()
selected = -1
pendingBindings.clear()
@@ -755,8 +758,13 @@ class SteamTouchControls(
actionSet = saved
}
fun cancelEditing() {
if (editing) stopEditing()
}
private fun stopEditing() {
editing = false
onEditingChanged?.invoke(false)
trayOpen = false
trayDrag = null
selected = -1
@@ -39,6 +39,7 @@ data class TouchGestureConfig(
val showGestureDebugOverlay: Boolean = false,
val gestureThreshold: Int = DEFAULT_GESTURE_THRESHOLD,
val mouseDragMovementMode: String = MOUSE_DRAG_MOVEMENT_DIRECT,
val relativeMouseMode: Int = RELATIVE_MOUSE_AUTO,
) {
fun toJson(): String {
@@ -75,6 +76,7 @@ data class TouchGestureConfig(
put(KEY_SHOW_GESTURE_DEBUG_OVERLAY, showGestureDebugOverlay)
put(KEY_GESTURE_THRESHOLD, gestureThreshold)
put(KEY_MOUSE_DRAG_MOVEMENT_MODE, mouseDragMovementMode)
put(KEY_RELATIVE_MOUSE_MODE, relativeMouseMode)
}.toString()
}
@@ -91,6 +93,10 @@ data class TouchGestureConfig(
const val MOUSE_DRAG_MOVEMENT_DIRECT = "direct"
const val MOUSE_DRAG_MOVEMENT_RELATIVE = "relative"
const val RELATIVE_MOUSE_AUTO = 0
const val RELATIVE_MOUSE_ON = 1
const val RELATIVE_MOUSE_OFF = 2
const val ACTION_SHOW_KEYBOARD = "show_keyboard"
const val ACTION_KEY_ESC = "key_ESC"
const val ACTION_KEY_TILDE = "key_TILDE"
@@ -114,6 +120,7 @@ data class TouchGestureConfig(
private const val KEY_LONG_PRESS_MOUSE_BEHAVIOR = "longPressMouseBehavior"
private const val KEY_LONG_PRESS_DELAY = "longPressDelay"
private const val KEY_DIRECT_HOLD_BEHAVIOR = "directHoldBehavior"
private const val KEY_RELATIVE_MOUSE_MODE = "relativeMouseMode"
private const val KEY_DOUBLE_TAP_ENABLED = "doubleTapEnabled"
private const val KEY_DOUBLE_TAP_DELAY = "doubleTapDelay"
private const val KEY_TWO_FINGER_DRAG_ENABLED = "twoFingerDragEnabled"
@@ -191,6 +198,7 @@ data class TouchGestureConfig(
mouseDragMovementMode = normalizeMouseDragMovementMode(
obj.optString(KEY_MOUSE_DRAG_MOVEMENT_MODE, MOUSE_DRAG_MOVEMENT_DIRECT),
),
relativeMouseMode = normalizeRelativeMouseMode(obj.optInt(KEY_RELATIVE_MOUSE_MODE, RELATIVE_MOUSE_AUTO)),
)
} catch (_: Exception) {
fallbackDefaults()
@@ -205,6 +213,10 @@ data class TouchGestureConfig(
return if (value == MOUSE_BEHAVIOR_CLICK) MOUSE_BEHAVIOR_CLICK else MOUSE_BEHAVIOR_HOLD
}
private fun normalizeRelativeMouseMode(mode: Int): Int {
return if (mode in RELATIVE_MOUSE_AUTO..RELATIVE_MOUSE_OFF) mode else RELATIVE_MOUSE_AUTO
}
private fun normalizeMouseDragMovementMode(mode: String?): String {
return if (mode == MOUSE_DRAG_MOVEMENT_RELATIVE) {
MOUSE_DRAG_MOVEMENT_RELATIVE
@@ -775,6 +775,12 @@ class SessionService : Service() {
return sessionDir
}
private fun relativeMouseForSession(): Int {
val game = if (SessionState.mode == MODE_RUN) SessionState.program?.let { "program:$it" }
else SessionState.gameId?.toLongOrNull()?.toString()
return com.droiddeck.launcher.input.GesturePrefs.read(this, game).relativeMouseMode
}
private fun addClientEnvironment(guest: MutableList<String>, steamHere: Boolean, agentEnvironment: List<String>) {
guest.add("/usr/bin/env")
guest.add("-i")
@@ -846,6 +852,7 @@ class SessionService : Service() {
guest.add("BL_FSYNC_FIRST=" + (if (SessionPrefs.fsyncFirst(this)) "1" else "0"))
guest.add("BL_GAMESCOPE_REALTIME=" + (if (SessionPrefs.gamescopeRealtime(this)) "1" else "0"))
if (SessionPrefs.cursorComposite(this)) guest.add("BL_CURSOR_COMPOSITE=1")
relativeMouseForSession().takeIf { it != 0 }?.let { guest.add("gamescope_relative_mouse=$it") }
if (com.droiddeck.launcher.core.ZramSupport.supported()) {
guest.add("BL_ZRAM=1")
if (steamHere) SessionPrefs.ramCapMb(this).takeIf { it > 0 }?.let { guest.add("BL_RAM_CAP_MB=$it") }
@@ -282,6 +282,8 @@ class DrawerActions(
val onLowLatency: (Boolean) -> Unit = {},
val evdevMouse: Boolean = false,
val onEvdevMouse: (Boolean) -> Unit = {},
val relativeMouseMode: Int = 0,
val onRelativeMouseMode: (Int) -> Unit = {},
val directCursor: Boolean = false,
val onDirectCursor: (Boolean) -> Unit = {},
val onTouch: (String) -> Unit,
@@ -599,6 +601,8 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
ChoiceRow(host, "touch", stringResource(R.string.mode_touch), null,
listOf(SessionPrefs.TOUCH_AUTO to stringResource(R.string.drawer_touch_auto, a.touchAuto), SessionPrefs.TOUCH_PAD to stringResource(R.string.mode_touch_touchpad), SessionPrefs.TOUCH_DIRECT to stringResource(R.string.mode_touch_direct), SessionPrefs.TOUCH_GESTURES to stringResource(R.string.mode_touch_gestures), SessionPrefs.TOUCH_OFF to stringResource(R.string.widgets_off)),
a.touchMode, chipModifier = focus.track(page, "touch"), onPick = a.onTouch)
if (a.touchActive == SessionPrefs.TOUCH_PAD)
RelativeMouseRow(host, a, focus.track(page, "relative-mouse"))
if (a.touchActive == SessionPrefs.TOUCH_DIRECT)
ToggleRow(host, "direct-cursor", stringResource(R.string.drawer_direct_cursor),
null, a.directCursor,
@@ -620,7 +624,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(10.dp),
) {
SecondaryButton(stringResource(R.string.ctrl_edit),
SecondaryButton(stringResource(R.string.ctrl_edit), enabled = a.screenKeysShown,
modifier = focus.track(page, "screen-keys"), onClick = a.onScreenKeys)
a.onScreenLayouts?.let { open ->
SecondaryButton(stringResource(R.string.screen_key_layout),
@@ -679,6 +683,8 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
ToggleRow(host, "evdev-mouse", stringResource(R.string.drawer_evdev_mouse),
null, a.evdevMouse,
chipModifier = focus.track(page, "evdev-mouse"), onChange = a.onEvdevMouse)
if (a.touchActive != SessionPrefs.TOUCH_PAD)
RelativeMouseRow(host, a, focus.track(page, "relative-mouse"))
}
SettingsGroup(stringResource(R.string.drawer_keyboard)) {
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth().padding(8.dp)) {
@@ -1197,6 +1203,15 @@ private fun SecondScreenGroup(host: MenuHost, a: DrawerActions, track: (String)
}
}
@Composable
private fun RelativeMouseRow(host: MenuHost, a: DrawerActions, modifier: Modifier) {
ChoiceRow(host, "relative-mouse", stringResource(R.string.drawer_relative_mouse), null,
listOf(com.droiddeck.launcher.input.TouchGestureConfig.RELATIVE_MOUSE_AUTO to stringResource(R.string.drawer_relative_mouse_auto),
com.droiddeck.launcher.input.TouchGestureConfig.RELATIVE_MOUSE_ON to stringResource(R.string.drawer_relative_mouse_on),
com.droiddeck.launcher.input.TouchGestureConfig.RELATIVE_MOUSE_OFF to stringResource(R.string.drawer_relative_mouse_off)),
a.relativeMouseMode, chipModifier = modifier, onPick = a.onRelativeMouseMode)
}
@Composable
private fun DrawerFexPresetRow(host: MenuHost, a: DrawerActions, modifier: Modifier) {
val appId = a.selectedGameProfileId
@@ -60,7 +60,7 @@ internal fun SteamIntegration.State.enabled(feature: Feature) = when (feature) {
Feature.WIFI -> wifi && locationPermission && locationOn
Feature.BRIGHTNESS -> brightness
Feature.HOME -> home
Feature.SHORTCUTS -> home && shortcuts
Feature.SHORTCUTS -> shortcuts
}
internal fun SteamIntegration.State.enabledCount() = Feature.entries.count { enabled(it) }
@@ -105,14 +105,12 @@ private fun IntegrationRow(
val bg by animateColorAsState(if (flash) pal.signal.copy(alpha = 0.12f) else Color.Transparent, Motion.tw(400), label = "integrationFlash")
val wifiLocationOff = feature == Feature.WIFI && state.wifi && state.locationPermission && !state.locationOn
val wifiDenied = feature == Feature.WIFI && !state.locationPermission && state.locationBlocked
val needsHome = feature == Feature.SHORTCUTS && !state.home
val restricted = feature == Feature.SHORTCUTS && !needsHome && !state.shortcuts && state.shortcutsRestricted
val maybeRestricted = feature == Feature.SHORTCUTS && !needsHome && !state.shortcuts && !restricted && state.shortcutsTried &&
val restricted = feature == Feature.SHORTCUTS && !state.shortcuts && state.shortcutsRestricted
val maybeRestricted = feature == Feature.SHORTCUTS && !state.shortcuts && !restricted && state.shortcutsTried &&
android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU
val hint = stringResource(when {
wifiLocationOff -> R.string.integration_wifi_location_off
wifiDenied -> R.string.integration_wifi_denied
needsHome -> R.string.integration_shortcuts_needs_home
restricted -> R.string.integration_shortcuts_restricted
maybeRestricted -> R.string.integration_shortcuts_maybe_restricted
feature == Feature.WIFI -> if (on) R.string.integration_wifi_on else R.string.integration_wifi_hint
@@ -141,7 +139,7 @@ private fun IntegrationRow(
restricted || maybeRestricted -> SecondaryButton(stringResource(R.string.integration_app_info), compact = true, onClick = onAppInfo)
}
val checked = if (feature == Feature.WIFI) state.wifi && state.locationPermission else on
ToggleSwitch(checked, enabled = !needsHome && !restricted, label = stringResource(featureTitle(feature)),
ToggleSwitch(checked, enabled = !restricted, label = stringResource(featureTitle(feature)),
modifier = Modifier.testTag("integration-action-${feature.name.lowercase()}")) { onFeature(feature) }
}
}