Compare commits

..
Author SHA1 Message Date
measlesbagel b09e2f9ba7 fix(bionic): pack GStreamer's debug plugin, so game videos play (#3294)
winegstreamer puts a capssetter, from the debug plugin, at the front of
every video stream's conversion chain. Wine creates it by name at run
time, so check-needed.py, which follows linked libraries, could not
catch the missing plugin, and those videos played nothing on Bionic.
2026-11-28 18:07:50 -05:00
The412Banner 1a22d2a1be feat(bionic): build DroidDeck-Bionic on the DroidDeck-Proton 11-14.1 Wine layer (#3389)
The tool still packed the 12.8 layer (v16-unwind). The v18 layer is the build
of DroidDeck-Proton 11-14.1 Bannerlator ships: Valve Wine a47c73f52fd7, the
GE-Proton11-14 picks, and the ARM64EC code-map and unwind fixes 12.8 carried.
Same layout as 12.8 (three more files), so only the pin changes. Tools are
named DroidDeck-Bionic-14.1-rN; the app's version compare offers 14.1 over 12.8.
2026-11-28 18:01:15 -05:00
xlulx ecaec5da01 fix(bionic): run games from a DroidDeck-Proton prefix that start through a launcher (#3336)
* fix(bionic): run games from a DroidDeck-Proton prefix that start through a launcher

Europa Universalis IV, moved from DroidDeck-Proton to DroidDeck-Bionic, never got past its launcher:

- The network adapter list (GetAdaptersAddresses) never answered with the layer's default if_nameindex code, so the
  Paradox Launcher waited forever. launch.sh sets WINE_NEW_NDIS=1 (the layer's getifaddrs code); a game's
  environment can still set 0.
- The game reported "Steam not detected": the prefix still named Proton's steam.exe (PID 0x20) as Steam's running
  client, and here that PID is the program Steam started, which quits after starting the game. launch.sh writes
  the PID this tool's own prefixes carry (0xfffe) before Wine starts.
- Its Workshop mod was missing: DroidDeck-Proton's s: drive names the guest path of the Steam library, which this
  Wine cannot follow. proton gives the prefix's guest drive links their Android paths for the launch; a session's
  start gives them their guest paths back.

* fix(bionic): give each launch its own temporary file for the registry and drive rewrites
2026-11-28 17:40:46 -05:00
MaxsTechReview a8aafad145 fix(session): the in-game menu opens on the first back tap and scrolls smoothly over a game (#3353)
* Open the session menu on the first back tap instead of after the double-tap window

* Hold the GPU clock up while a session panel is open over the game

* Keep the double back tap working after the first tap opens the menu

The first tap opens the menu at once, and opening the menu cleared the
pending tap, so a second tap closed the menu instead of opening Steam's
quick menu. The tap that opened the menu now keeps its window, and a
second back press inside it goes to the double-tap action.

Outside Steam both taps toggle the menu, so a double tap no longer opens
and then closes it.

* fix(session): drop pending back taps on focus loss and departure

* fix(session): drop pending back taps when the drawer closes or another panel opens

* fix(session): drop the quick-menu input's pending tap when the drawer closes

* fix(session): keep a back press already down when the drawer closes
2026-11-28 17:33:36 -05:00
ReVanTisandmaxjivi05 1d4eb2446e fix(input): a captured touchpad drives the pointer (#2802)
* fix(input): a captured touchpad drives the pointer

Android reports a captured touchpad's events as SOURCE_TOUCHPAD with the
finger positions on the pad and the movement in AXIS_RELATIVE_X/Y. The
capture handler only accepted SOURCE_MOUSE_RELATIVE, so every captured
touchpad event was dropped and the touchpad stopped working in a session.

Read the relative axes for a captured touchpad, and count a touchpad as
an attached pointer for the Auto relative mouse choice and for pointer
capture. A touchpad that declares SOURCE_TOUCHPAD is not captured for the
whole session, so Android keeps its cursor and gestures until a game holds
the pointer.

* fix(input): keep captured touchpad motion without relative axes

Some builds do not provide AXIS_RELATIVE_X/Y for a captured touchpad
(the AOSP include_relative_axis_values_for_captured_touchpads flag can
leave them out). Fall back to the movement between the pointer's
successive absolute positions, tracked per pointer id, and clear the
positions when capture changes or the pointer ends.

* fix(input): key captured touchpad positions by device too

A pointer id is only unique within its device, so the fallback positions
could collide between two touchpads or a replaced device. Key them by
device id and pointer id, and cover it with a test.

* fix(input): end only the touchpad that lifted

ACTION_UP and ACTION_CANCEL cleared every device's fallback positions.
Forget only the device that ended, so a second touchpad keeps its
baseline; a capture change still resets all of them.

* Give a captured touchpad taps, two-finger scroll and clickpad presses

* Keep captured touchpad clicks apart from mouse buttons

A tap's synthetic release shared the mouse's held-button owner, so it
could release a mouse button that was still held. Captured touchpad
presses now use their own owner, released when capture ends. A physical
pad press also keeps a later second finger from turning into a
right-click tap.

* Keep physical touchpad buttons on the mouse owner

A press made before capture was released under the captured owner and
stayed held. Physical buttons now always use the mouse owner, and only
gesture clicks use the touchpad owner. A physical press also releases a
pending tap click first, so the two never merge.

---------

Co-authored-by: maxjivi05 <maxjividen@gmail.com>
2026-11-28 16:42:01 -05:00
MaxsTechReview 5d276ab461 fix(gamescope): direct touch keeps the pointer under the first finger (#3382)
* fix(gamescope): only the first finger drives the emulated mouse

In the click touch modes every finger warped the X pointer and any
finger lifting released the click, so a second finger made the pointer
jump between both contacts and dropped whatever the first was dragging.
The first finger of a gesture now owns the emulated mouse until it lifts,
and later fingers are ignored until every finger is up.

* fix(gamescope): motion into the screen edge does not decide the pointer hold

A drawn-cursor game whose X pointer sat at the screen edge looked like it
held the pointer whenever motion pushed outward, which kept the hold on
and turned touch drags into relative motion. The sent motion is clamped
to what the pointer can reach before the comparison.

* fix(gamescope): touch warps do not decide the pointer hold

* fix(gamescope): only touch-down warps are left out of the pointer hold

Touch drags are real pointer motion, so they count toward releasing the
hold again. Only the jump a touch-down makes is skipped.
2026-11-28 16:09:17 -05:00
18 changed files with 1179 additions and 74 deletions

No files matched your search

@@ -450,13 +450,22 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
return true
}
private val uiHandler = Handler(Looper.getMainLooper())
private var pendingBackAction: Runnable? = null
private var backTapOpenedDrawer = false
private val backTapsAtOnce: Boolean get() = SessionState.mode != SessionService.MODE_STEAM || !backActionsInverted
private val backTaps = com.droiddeck.launcher.input.BackTaps(
windowMs = { backDoubleTapMs.toLong() },
atOnce = { backTapsAtOnce },
onTap = { performBackAction(double = it) },
sameAction = { SessionState.mode != SessionService.MODE_STEAM },
)
private val backQamInput = com.droiddeck.launcher.input.BackQamInput(
setPressed = { padBridge?.setBackQamPressed(it) },
onTap = { performBackAction(double = it) },
doubleTapMs = { backDoubleTapMs.toLong() },
onCancel = { padBridge?.cancelBackQam() },
holds = { backHold },
atOnce = { backTapsAtOnce },
sameAction = { SessionState.mode != SessionService.MODE_STEAM },
)
private val mouseBackInput = com.droiddeck.launcher.input.MouseBackInput(
sendRight = { down -> heldButtons.set(32, PointerGestures.BTN_RIGHT, down) },
@@ -904,6 +913,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
onCapturedPointer(event) || super.dispatchCapturedPointerEvent(event)
override fun dispatchPointerCaptureChanged(hasCapture: Boolean) {
super.dispatchPointerCaptureChanged(hasCapture)
capturedTouchpad.cancel()
heldButtons.release(64)
Log.i(TAG, "pointer capture " + if (hasCapture) "on" else "off")
if (hasCapture) {
pointerCaptureRefused = false
@@ -1127,11 +1138,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
when {
::loading.isInitialized && loading.ended -> finish()
inputSettingsOpen -> inputSettingsOpen = false
dockedTouchOnly -> routeBackAction()
dockedTouchOnly || backTaps.pending -> backTaps.tap()
drawerOpen -> drawerOpen = false
achievementsOpen -> closeAchievements()
pcKeyboardOpen -> pcKeyboardOpen = false
else -> routeBackAction()
else -> backTaps.tap()
}
}
})
@@ -1328,8 +1339,15 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
LaunchedEffect(drawerOpen, menuOwnsController, pcKeyboardOpen, achievementsOpen, gestureSettingsOpen, inputSettingsOpen, pipUi, SessionState.suspended, resumed, appTextFocus) {
updateOnScreenControls()
padBridge?.setInputEnabled(resumed && !menuOwnsController && !pcKeyboardOpen && !achievementsOpen && !gestureSettingsOpen && !inputSettingsOpen && !pipUi && !appTextFocus && !SessionState.suspended)
if (drawerOpen || pcKeyboardOpen || achievementsOpen || gestureSettingsOpen || inputSettingsOpen || pipUi || appTextFocus || SessionState.suspended) {
backQamInput.cancel()
if (!drawerOpen && backTapOpenedDrawer) {
backTaps.cancel()
backQamInput.cancelTap()
backTapOpenedDrawer = false
}
val otherPanel = pcKeyboardOpen || achievementsOpen || gestureSettingsOpen || inputSettingsOpen || pipUi || appTextFocus || SessionState.suspended
if (drawerOpen || otherPanel) {
if (otherPanel || !backTapOpenedDrawer) backTaps.cancel()
backQamInput.cancel(keepTap = backTapOpenedDrawer && !otherPanel)
com.droiddeck.launcher.input.HomeButtonShortcuts.cancel(this@SessionActivity)
cancelTouchGestures()
}
@@ -1383,7 +1401,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
if (drawerOpen) {
syncLossless()
if (menuOwnsController) {
releasePads()
releasePads(keepBackTap = backTapOpenedDrawer)
androidx.compose.runtime.withFrameNanos { }
val requested = focusDrawer()
Log.i(TAG, "drawer root focus requested=$requested docked=$drawerDocked")
@@ -1422,6 +1440,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
LaunchedEffect(pcKeyboardOpen, drawerOpen, achievementsOpen) {
if (pcKeyboardOpen || drawerOpen || achievementsOpen) padMouse.reset()
}
val panelShown = panelOverGame
LaunchedEffect(panelShown) { boostGpuClock(panelShown && resumed) }
if (pcKeyboardOpen) com.droiddeck.launcher.ui.PcKeyboard(
sendKey = { code, down -> if (CompositorHost.isStarted) sendGuestKey(code, down, 32) },
onAndroidKeyboard = { pcKeyboardOpen = false; togglePrimaryKeyboard() },
@@ -2116,25 +2136,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
unfoldedPanel?.reload()
}
private fun routeBackAction() {
pendingBackAction?.let { pending ->
uiHandler.removeCallbacks(pending)
pendingBackAction = null
performBackAction(double = true)
return
}
val pending = Runnable {
pendingBackAction = null
performBackAction(double = false)
}
pendingBackAction = pending
uiHandler.postDelayed(pending, backDoubleTapMs.toLong())
}
private fun performBackAction(double: Boolean) {
val isSteam = SessionState.mode == SessionService.MODE_STEAM
val opensQam = isSteam && (double xor backActionsInverted)
if (opensQam) triggerSteamQam() else if (!dockedTouchOnly) drawerOpen = !drawerOpen
if (opensQam) triggerSteamQam() else if (!dockedTouchOnly) {
drawerOpen = !drawerOpen
backTapOpenedDrawer = drawerOpen && !double
}
}
private fun handleHomeGuideIntent(incoming: Intent?) {
@@ -2619,6 +2627,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
private fun gpuClockHeld() = SessionPrefs.gpuClockPin(this) && !GpuClockPin.failed
private val panelOverGame: Boolean get() = ((drawerOpen && !drawerDocked) || achievementsOpen || gestureSettingsOpen || inputSettingsOpen) && !pipUi
private fun boostGpuClock(on: Boolean) {
if (!GpuClockPin.boost(on)) return
Thread { GpuClockPin.sync(applicationContext)?.let { Log.i(TAG, it) } }.start()
}
private fun readPrefs() {
pipAutoEnter = SessionPrefs.pipAutoEnter(this)
unfoldedControls = SessionPrefs.unfoldedControls(this)
@@ -3487,11 +3502,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
focusEndedScreen()
}
private fun releasePads() {
private fun releasePads(keepBackTap: Boolean = false) {
inputMotion.stop()
physicalInputBindings?.release()
com.droiddeck.launcher.input.HomeButtonShortcuts.cancel(this)
backQamInput.cancel()
backQamInput.cancel(keepTap = keepBackTap)
padBridge?.releaseAll()
joyConVr?.releaseButtons()
}
@@ -3651,8 +3666,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
!pcKeyboardOpen && !achievementsOpen && !gestureSettingsOpen && !inputSettingsOpen,
steam = SessionState.mode == SessionService.MODE_STEAM,
) { action ->
pendingBackAction?.let(uiHandler::removeCallbacks)
pendingBackAction = null
backTaps.cancel()
if (!dockedMenuIdle) drawerControllerActive = true
Log.i(TAG, "physical shortcut ${action.name} device=${event.deviceId} key=${event.keyCode} scan=${event.scanCode}")
when (action) {
@@ -3684,16 +3698,23 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
}
}
if (mouseBackHandled) return true
val backToQam = !pipUi && !appTextFocus && !menuOwnsController && !pcKeyboardOpen && !achievementsOpen &&
val backToQam = !pipUi && !appTextFocus && (!menuOwnsController || backQamInput.awaitingTap) && !pcKeyboardOpen && !achievementsOpen &&
!inputSettingsOpen && !gestureSettingsOpen &&
SessionState.mode == SessionService.MODE_STEAM && SessionState.running && SessionState.firstFrameSeen &&
!SessionState.suspended && padBridge?.canHoldQam() == true
if (backQamInput.onKeyEvent(event, backToQam)) {
pendingBackAction?.let(uiHandler::removeCallbacks)
pendingBackAction = null
backTaps.cancel()
return true
}
if (pipUi) return true
if (event.keyCode == KeyEvent.KEYCODE_BACK && backTapOpenedDrawer && backTaps.pending) {
when {
event.action == KeyEvent.ACTION_DOWN -> backTaps.hold()
event.action == KeyEvent.ACTION_UP && !event.isCanceled -> backTaps.tap()
event.action == KeyEvent.ACTION_UP -> backTaps.cancel()
}
return true
}
val pad = com.droiddeck.launcher.input.JoyCon.normalize(event)
if (pad !== event) return dispatchKeyEvent(pad)
val fromController = PadBridge.isControllerKeyEvent(event)
@@ -3836,7 +3857,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
}
else -> return super.dispatchGenericMotionEvent(event)
}
if (event.isFromSource(android.view.InputDevice.SOURCE_MOUSE) && !drawerOpen) {
if ((event.isFromSource(android.view.InputDevice.SOURCE_MOUSE) ||
event.isFromSource(android.view.InputDevice.SOURCE_TOUCHPAD)) && !drawerOpen) {
if (appUiOwnsPointer()) {
if (super.dispatchGenericMotionEvent(event)) return true
if (touchEditorOpen) return false
@@ -4020,7 +4042,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
steamSession = SessionState.mode == SessionService.MODE_STEAM,
steamDesktopUi = SessionState.steamUi == "desktop",
)) == com.droiddeck.launcher.input.TouchRouter.Route.TOUCHPAD
val mode = com.droiddeck.launcher.input.TouchGestureConfig.gamescopeRelativeMouse(wanted, mouseAttached(), touchpadRoute)
val mode = com.droiddeck.launcher.input.TouchGestureConfig.gamescopeRelativeMouse(wanted, pointerAttached(), touchpadRoute)
if (appliedRelativeMouseMode == mode) return
if (AgentGuest.setGamescopeConvar(this, "relative_mouse", mode)) appliedRelativeMouseMode = mode
else if (relativeMouseRetries++ < RELATIVE_MOUSE_MAX_RETRIES) uiHandler.postDelayed({ requestRelativeMouse() }, 2_000)
@@ -4151,6 +4173,27 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
}
}
private val capturedTouchpadListener: PointerGestures.Listener = object : PointerGestures.Listener by pointerListener {
override fun onMove(x: Float, y: Float) {
val rect = drawnRect() ?: return
val scale = sceneScale(rect)
capturedTouchpad.place(CAPTURED_PAD_CENTRE, CAPTURED_PAD_CENTRE)
onRelativeMouse((x - CAPTURED_PAD_CENTRE) * scale, (y - CAPTURED_PAD_CENTRE) * scale)
}
override fun onButton(button: Int, pressed: Boolean, x: Float, y: Float) {
heldButtons.set(64, button, pressed)
}
override fun onThreeFingerTap(): Boolean = false
}
private val capturedTouchpad: TouchpadGestures by lazy {
TouchpadGestures(PointerGestures.slop(this), capturedTouchpadListener, holdDrags = false).apply {
bounds = android.graphics.RectF(0f, 0f, CAPTURED_PAD_CENTRE * 2f, CAPTURED_PAD_CENTRE * 2f)
place(CAPTURED_PAD_CENTRE, CAPTURED_PAD_CENTRE)
}
}
private val capturedPadMatrix = android.graphics.Matrix()
private val scrollListener = object : ScrollTouchGestures.Listener {
override fun onMove(x: Float, y: Float) {
val rect = pointerSurfaceRect() ?: return
@@ -5327,7 +5370,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
private fun handleTouch(event: MotionEvent): Boolean {
val pen = PenStream.penIndex(event)
val penRouted = if (pen >= 0) routePen(event, pen).takeIf { it != PenRouter.Route.TOUCH } else null
if (penRouted == null && event.isFromSource(android.view.InputDevice.SOURCE_MOUSE)) return onMouse(event)
if (penRouted == null && (event.isFromSource(android.view.InputDevice.SOURCE_MOUSE) ||
event.isFromSource(android.view.InputDevice.SOURCE_TOUCHPAD))) return onMouse(event)
when (event.actionMasked) {
MotionEvent.ACTION_DOWN -> {
sessionTouchDown = true
@@ -5573,7 +5617,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
private fun isHardwareMouse(d: InputDevice?): Boolean =
d != null && !d.isVirtual && !d.supportsSource(InputDevice.SOURCE_STYLUS) &&
(d.supportsSource(InputDevice.SOURCE_MOUSE) || d.supportsSource(InputDevice.SOURCE_MOUSE_RELATIVE))
(d.supportsSource(InputDevice.SOURCE_MOUSE) || d.supportsSource(InputDevice.SOURCE_MOUSE_RELATIVE) ||
d.supportsSource(InputDevice.SOURCE_TOUCHPAD))
private fun isTouchpad(d: InputDevice?): Boolean =
d?.supportsSource(InputDevice.SOURCE_TOUCHPAD) == true
/** Android also sends the Back and Forward buttons as key events, so they are handled as keys. */
private fun guestMouseButton(actionButton: Int): Int? = when (actionButton) {
@@ -5583,9 +5631,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
else -> PointerGestures.BTN_LEFT
}
private fun pointerAttached(): Boolean = usbMouse.active || InputDevice.getDeviceIds().any { id ->
isHardwareMouse(InputDevice.getDevice(id))
}
private fun mouseAttached(): Boolean = usbMouse.active || InputDevice.getDeviceIds().any { id ->
val d = InputDevice.getDevice(id)
isHardwareMouse(d) && d?.supportsSource(InputDevice.SOURCE_TOUCHPAD) != true
isHardwareMouse(d) && !isTouchpad(d)
}
private fun externalMouseAttached(): Boolean {
@@ -5603,7 +5655,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
private fun updatePointerCapture() {
if (!::surfaceView.isInitialized) return
val view = window.decorView
val want = (pointerLocked || relativeMouseAttached()) && sessionOwnsInput() && hasWindowFocus() && mouseAttached()
val want = (pointerLocked || relativeMouseAttached()) && sessionOwnsInput() && hasWindowFocus() && pointerAttached()
releaseDesktopMouseGrab()
updateUsbMouse(want)
if (want == view.hasPointerCapture()) return
@@ -5656,7 +5708,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
}
private fun dropMouseCursor() {
if (!mouseOwnsCursor || mouseAttached()) return
if (!mouseOwnsCursor || pointerAttached()) return
mouseOwnsCursor = false
uiHandler.removeCallbacks(cursorResync)
cursorVisible = false
@@ -5707,20 +5759,22 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
}
private fun onCapturedPointer(event: MotionEvent): Boolean {
if (!event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE)) return false
if (!com.droiddeck.launcher.input.PointerCapture.accepts(event)) return false
notePress(event)
val pad = com.droiddeck.launcher.input.PointerCapture.isTouchpad(event)
when (event.actionMasked) {
MotionEvent.ACTION_BUTTON_PRESS, MotionEvent.ACTION_BUTTON_RELEASE -> {
if (pad && event.actionMasked == MotionEvent.ACTION_BUTTON_PRESS) capturedTouchpad.buttonPressed()
guestMouseButton(event.actionButton)?.let { heldButtons.set(8, it, event.actionMasked == MotionEvent.ACTION_BUTTON_PRESS) }
}
else -> if (pad) return onCapturedTouchpad(event)
}
when (event.actionMasked) {
MotionEvent.ACTION_MOVE -> {
var dx = event.x
var dy = event.y
for (i in 0 until event.historySize) {
dx += event.getHistoricalX(i)
dy += event.getHistoricalY(i)
}
onRelativeMouse(dx, dy)
val delta = com.droiddeck.launcher.input.PointerCapture.delta(event)
onRelativeMouse(delta[0], delta[1])
}
MotionEvent.ACTION_BUTTON_PRESS, MotionEvent.ACTION_BUTTON_RELEASE ->
guestMouseButton(event.actionButton)?.let { heldButtons.set(8, it, event.actionMasked == MotionEvent.ACTION_BUTTON_PRESS) }
MotionEvent.ACTION_BUTTON_PRESS, MotionEvent.ACTION_BUTTON_RELEASE -> {}
MotionEvent.ACTION_SCROLL -> {
val v = event.getAxisValue(MotionEvent.AXIS_VSCROLL)
if (v != 0f) sendSceneWheel(-Math.round(v))
@@ -5731,6 +5785,21 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
return true
}
private fun onCapturedTouchpad(event: MotionEvent): Boolean {
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
val metrics = resources.displayMetrics
val scale = com.droiddeck.launcher.input.PointerCapture.touchpadScale(event, metrics.xdpi / 25.4f, metrics.widthPixels)
capturedPadMatrix.setScale(scale, scale)
capturedTouchpad.desktop = SessionState.mode == SessionService.MODE_DESKTOP
if (::touchpad.isInitialized) capturedTouchpad.sensitivity = touchpad.sensitivity
}
val scaled = MotionEvent.obtain(event)
scaled.transform(capturedPadMatrix)
val handled = capturedTouchpad.onTouch(scaled)
scaled.recycle()
return handled
}
private fun logInputDevice(what: String, deviceId: Int) {
val d = InputDevice.getDevice(deviceId) ?: return
if (!PadBridge.isFromController(d)) return
@@ -6127,8 +6196,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
drawerOpen = false
pcKeyboardOpen = false
achievementsOpen = false
pendingBackAction?.let(uiHandler::removeCallbacks)
pendingBackAction = null
backTaps.cancel()
releaseDrawerDirection()
onScreenControls?.releaseAll()
bottomInputControls?.releaseAll()
@@ -6291,6 +6359,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
onScreenControls?.reload()
controllerSettings = ControllerPrefs.read(this)
resumed = true
boostGpuClock(panelOverGame)
updateKeyboardRoute()
retryFieldKeyboard(hasWindowFocus())
updateDesktopKeyboardButton()
@@ -6341,6 +6410,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
if (runtimeRemovalBlocked) return
physicalShortcuts.clear()
backQamInput.cancel()
backTaps.cancel()
mouseBackInput.cancel()
capturePausedFrame()
padBridge?.setInputEnabled(false)
@@ -6374,6 +6444,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
if (::scrollTouch.isInitialized) scrollTouch.cancel()
if (::padMouse.isInitialized) padMouse.reset()
resumed = false
boostGpuClock(false)
updateKeyboardRoute()
updatePointerCapture()
updatePadMotion()
@@ -6956,6 +7027,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
super.onWindowFocusChanged(hasFocus)
if (!hasFocus) com.droiddeck.launcher.input.HomeButtonShortcuts.cancel(this)
if (!hasFocus) backQamInput.cancel()
if (!hasFocus) backTaps.cancel()
if (!hasFocus) mouseBackInput.cancel()
if (!hasFocus && ::padMouse.isInitialized) padMouse.reset()
if (runtimeRemovalBlocked) return
@@ -7029,8 +7101,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
if (runtimeRemovalBlocked) { super.onDestroy(); return }
watching = false
releaseDrawerDirection()
pendingBackAction?.let(uiHandler::removeCallbacks)
pendingBackAction = null
backTaps.cancel()
if (::pip.isInitialized) pip.destroyed()
closeSecondScreen(reset = false)
glassesScope.cancel()
@@ -7162,6 +7233,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
private const val PAD_SCROLL_POINTER_X = 0.985f
private const val PAD_SCROLL_HEIGHTS_PER_S = 3f
private const val AXIS_UNITS_PER_PIXEL = 3f
private const val CAPTURED_PAD_CENTRE = 1_000_000f
private const val KEY_LEFTCTRL = 29
private const val KEY_RIGHTCTRL = 97
private const val KEY_A = 30
@@ -6,18 +6,15 @@ import android.os.Looper
class BackQamInput(private val setPressed: (Boolean) -> Unit, private val onTap: (Boolean) -> Unit,
private val doubleTapMs: () -> Long = { 500 }, private val onCancel: () -> Unit = {},
private val holds: () -> Boolean = { true }) {
private val holds: () -> Boolean = { true }, atOnce: () -> Boolean = { false }, sameAction: () -> Boolean = { false }) {
private class Press(val hold: Runnable, var held: Boolean = false, var used: Boolean = false)
private val handler = Handler(Looper.getMainLooper())
private val presses = mutableMapOf<Int, Press>()
private val cancelled = mutableSetOf<Int>()
private var tapPending = false
private val singleTap = Runnable { tapPending = false; onTap(false) }
private val taps = BackTaps(doubleTapMs, atOnce, onTap, sameAction)
val awaitingTap: Boolean get() = taps.pending
private fun cancelTap() {
handler.removeCallbacks(singleTap)
tapPending = false
}
fun cancelTap() = taps.cancel()
fun onChordInput() {
if (presses.isEmpty()) return
@@ -46,7 +43,7 @@ class BackQamInput(private val setPressed: (Boolean) -> Unit, private val onTap:
cancelled.remove(device)
if (!enabled || event.isCanceled) return false
if (device in presses) return true
handler.removeCallbacks(singleTap)
taps.hold()
val hold = Runnable {
val press = presses[device] ?: return@Runnable
if (!holds()) { press.used = true; cancelTap(); return@Runnable }
@@ -66,10 +63,8 @@ class BackQamInput(private val setPressed: (Boolean) -> Unit, private val onTap:
if (press != null) {
handler.removeCallbacks(press.hold)
if (press.held && presses.values.none { it.held }) setPressed(false)
if (!press.used && !event.isCanceled) {
if (tapPending) { cancelTap(); onTap(true) }
else { tapPending = true; handler.postDelayed(singleTap, doubleTapMs()) }
} else if (event.isCanceled) cancelTap()
if (!press.used && !event.isCanceled) taps.tap()
else if (event.isCanceled) cancelTap()
}
press != null || wasCancelled || enabled
}
@@ -77,8 +72,8 @@ class BackQamInput(private val setPressed: (Boolean) -> Unit, private val onTap:
}
}
fun cancel() {
cancelTap()
fun cancel(keepTap: Boolean = false) {
if (!keepTap) cancelTap()
val wasHeld = presses.values.any { it.held }
presses.values.forEach { handler.removeCallbacks(it.hold) }
cancelled.addAll(presses.keys)
@@ -0,0 +1,39 @@
package com.droiddeck.launcher.input
import android.os.Handler
import android.os.Looper
class BackTaps(
private val windowMs: () -> Long,
private val atOnce: () -> Boolean,
private val onTap: (Boolean) -> Unit,
private val sameAction: () -> Boolean = { false },
) {
private val handler = Handler(Looper.getMainLooper())
private var deferred = false
var pending = false
private set
private val expire = Runnable {
pending = false
if (deferred) onTap(false)
}
fun tap() {
if (pending) {
cancel()
if (deferred || !sameAction()) onTap(true)
return
}
pending = true
deferred = !atOnce()
handler.postDelayed(expire, windowMs())
if (!deferred) onTap(false)
}
fun hold() = handler.removeCallbacks(expire)
fun cancel() {
handler.removeCallbacks(expire)
pending = false
}
}
@@ -0,0 +1,33 @@
package com.droiddeck.launcher.input
import android.view.InputDevice
import android.view.MotionEvent
object PointerCapture {
fun accepts(event: MotionEvent): Boolean =
event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE) ||
event.isFromSource(InputDevice.SOURCE_TOUCHPAD)
fun isTouchpad(event: MotionEvent): Boolean = event.isFromSource(InputDevice.SOURCE_TOUCHPAD)
fun delta(event: MotionEvent): FloatArray {
var dx = event.x
var dy = event.y
for (i in 0 until event.historySize) {
dx += event.getHistoricalX(i)
dy += event.getHistoricalY(i)
}
return floatArrayOf(dx, dy)
}
fun touchpadScale(unitsPerMm: Float, padWidth: Float, pixelsPerMm: Float, screenWidth: Int): Float = when {
unitsPerMm > 0f && pixelsPerMm > 0f -> pixelsPerMm / unitsPerMm
padWidth > 0f && screenWidth > 0 -> screenWidth / padWidth
else -> 1f
}
fun touchpadScale(event: MotionEvent, pixelsPerMm: Float, screenWidth: Int): Float {
val range = event.device?.getMotionRange(MotionEvent.AXIS_X, InputDevice.SOURCE_TOUCHPAD)
return touchpadScale(range?.resolution ?: 0f, range?.range ?: 0f, pixelsPerMm, screenWidth)
}
}
@@ -9,6 +9,7 @@ import kotlin.math.hypot
class TouchpadGestures(
private val slopPx: Float,
private val listener: PointerGestures.Listener,
private val holdDrags: Boolean = true,
) {
var x = 0f
private set
@@ -33,6 +34,7 @@ class TouchpadGestures(
private var held = false
private var secondDownAt = 0L
private var secondWasTap = false
private var pressed = false
private var twoFingers = false
private var scrollAnchorX = 0f
private var scrollAnchorY = 0f
@@ -90,6 +92,15 @@ class TouchpadGestures(
lastTapAt = 0L
}
fun buttonPressed() {
pressed = true
handler.removeCallbacks(longPress)
releaseClick()
travelled = slopPx + 1f
secondWasTap = false
lastTapAt = 0L
}
fun place(px: Float, py: Float) {
x = px.coerceIn(bounds.left, bounds.right)
y = py.coerceIn(bounds.top, bounds.bottom)
@@ -115,7 +126,7 @@ class TouchpadGestures(
releaseClick()
lastX = event.x; lastY = event.y
downAt = event.eventTime
travelled = 0f; held = false; twoFingers = false; scrolled = false; secondWasTap = false
travelled = 0f; held = false; twoFingers = false; scrolled = false; secondWasTap = false; pressed = false
fingers = 1; pinching = false
anchorId = event.getPointerId(0); moverId = -1; holdDrag = false; scrollLocked = false
if (clicks && event.eventTime - lastTapAt < TouchTiming.DOUBLE_TAP_MS) {
@@ -123,7 +134,7 @@ class TouchpadGestures(
press(PointerGestures.BTN_LEFT)
} else {
dragging = false
if (clicks) handler.postDelayed(longPress, TouchTiming.HOLD_MS)
if (clicks && holdDrags) handler.postDelayed(longPress, TouchTiming.HOLD_MS)
}
return true
}
@@ -142,7 +153,7 @@ class TouchpadGestures(
if (holdDrag) return true
twoFingers = true
secondDownAt = event.eventTime
secondWasTap = true
secondWasTap = !pressed
scrollAnchorX = (event.getX(0) + event.getX(1)) / 2f
scrollAnchorY = (event.getY(0) + event.getY(1)) / 2f
pinchSpan = span(event)
@@ -153,7 +164,7 @@ class TouchpadGestures(
val mi = if (moverId == -1) -1 else event.findPointerIndex(moverId)
if (ai >= 0 && mi >= 0) {
val mx = event.getX(mi); val my = event.getY(mi)
if (!holdDrag && !scrolled && !scrollLocked) {
if (holdDrags && !holdDrag && !scrolled && !scrollLocked) {
val anchorMoved = abs(event.getX(ai) - anchorStartX) + abs(event.getY(ai) - anchorStartY)
val moverMoved = abs(mx - moverStartX) + abs(my - moverStartY)
if (anchorMoved >= slopPx) {
@@ -18,10 +18,24 @@ object GpuClockPin {
var failed = false
private set
val supported: Boolean by lazy { File(KGSL_NODE).exists() }
var supported: Boolean = File(KGSL_NODE).exists()
internal set
internal var turbo: (Boolean) -> Unit = { WaylandCompositor.nativeSetGpuTurbo(it) }
private var live = false
@Volatile
private var boosted = false
private fun wanted(context: Context) = boosted || SessionPrefs.gpuClockPin(context)
fun boost(on: Boolean): Boolean {
if (boosted == on) return false
boosted = on
return true
}
@Synchronized
fun start(context: Context): String {
live = true
@@ -30,11 +44,11 @@ object GpuClockPin {
private fun hold(context: Context): String {
failed = false
if (!SessionPrefs.gpuClockPin(context)) return "gpu clock: governed"
if (!wanted(context)) return "gpu clock: governed"
if (!supported) return "gpu clock: no $KGSL_NODE, left governed"
return try {
File(context.filesDir, MARKER).createNewFile()
WaylandCompositor.nativeSetGpuTurbo(true)
turbo(true)
pinned = true
"gpu clock: held at its top"
} catch (t: Throwable) {
@@ -48,13 +62,14 @@ object GpuClockPin {
@Synchronized
fun sync(context: Context): String? {
if (!live) return null
if (!SessionPrefs.gpuClockPin(context) && pinned) clear(context)
if (!wanted(context) && pinned) clear(context)
return hold(context)
}
@Synchronized
fun stop(context: Context) {
live = false
boosted = false
if (pinned) clear(context)
}
@@ -66,7 +81,7 @@ object GpuClockPin {
private fun clear(context: Context) {
if (supported) {
try {
WaylandCompositor.nativeSetGpuTurbo(false)
turbo(false)
} catch (t: Throwable) {
Log.w(TAG, "clear", t)
}
@@ -63,6 +63,46 @@ class BackQamInputTest {
}
}
@Test fun anAtOnceSingleTapActsOnReleaseAndADoubleTapStillFollows() {
val direct = BackQamInput(changes::add, taps::add, atOnce = { true })
fun press(action: Int) = direct.onKeyEvent(KeyEvent(action, KeyEvent.KEYCODE_BACK), true)
press(KeyEvent.ACTION_DOWN)
assertTrue(taps.isEmpty())
press(KeyEvent.ACTION_UP)
assertEquals(listOf(false), taps)
assertTrue(direct.awaitingTap)
advance(300)
press(KeyEvent.ACTION_DOWN)
advance(400)
assertTrue(direct.awaitingTap)
press(KeyEvent.ACTION_UP)
assertEquals(listOf(false, true), taps)
assertFalse(direct.awaitingTap)
assertTrue(changes.isEmpty())
}
@Test fun cancellingOnlyTheTapKeepsAPressThatIsAlreadyDown() {
val direct = BackQamInput(changes::add, taps::add, atOnce = { true })
fun press(action: Int) = direct.onKeyEvent(KeyEvent(action, KeyEvent.KEYCODE_BACK), true)
press(KeyEvent.ACTION_DOWN)
press(KeyEvent.ACTION_UP)
advance(100)
press(KeyEvent.ACTION_DOWN)
direct.cancelTap()
assertFalse(direct.awaitingTap)
press(KeyEvent.ACTION_UP)
assertEquals(listOf(false, false), taps)
}
@Test fun anAtOnceTapStopsAwaitingWhenTheWindowEnds() {
val direct = BackQamInput(changes::add, taps::add, atOnce = { true })
direct.onKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK), true)
direct.onKeyEvent(KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK), true)
advance(500)
assertFalse(direct.awaitingTap)
assertEquals(listOf(false), taps)
}
@Test fun aHoldStartsAt700msAndNeverProducesATap() {
assertTrue(send(KeyEvent.ACTION_DOWN))
advance(699)
@@ -191,6 +231,19 @@ class BackQamInputTest {
assertTrue(taps.isEmpty())
}
@Test fun cancellingHeldInputCanKeepThePendingTapForTheDoubleAction() {
val direct = BackQamInput(changes::add, taps::add, atOnce = { true })
fun press(action: Int) = direct.onKeyEvent(KeyEvent(action, KeyEvent.KEYCODE_BACK), true)
press(KeyEvent.ACTION_DOWN)
press(KeyEvent.ACTION_UP)
direct.cancel(keepTap = true)
assertTrue(direct.awaitingTap)
press(KeyEvent.ACTION_DOWN)
press(KeyEvent.ACTION_UP)
assertEquals(listOf(false, true), taps)
assertFalse(direct.awaitingTap)
}
@Test fun cancellationAlsoDiscardsAPendingSingleTap() {
send(KeyEvent.ACTION_DOWN)
send(KeyEvent.ACTION_UP)
@@ -0,0 +1,133 @@
package com.droiddeck.launcher.input
import android.os.Looper
import java.time.Duration
import org.junit.Assert.*
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.Shadows.shadowOf
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34], manifest = Config.NONE)
class BackTapsTest {
private val seen = mutableListOf<Boolean>()
private var atOnce = true
private var window = 500L
private val taps = BackTaps({ window }, { atOnce }, seen::add)
@Test fun aSingleTapActsWithoutWaitingForTheWindow() {
taps.tap()
assertEquals(listOf(false), seen)
assertTrue(taps.pending)
advance(500)
assertEquals(listOf(false), seen)
assertFalse(taps.pending)
}
@Test fun aSecondTapInsideTheWindowAddsTheDoubleAction() {
taps.tap()
advance(499)
taps.tap()
assertEquals(listOf(false, true), seen)
assertFalse(taps.pending)
advance(1000)
assertEquals(listOf(false, true), seen)
}
@Test fun aTapAfterTheWindowIsANewSingleTap() {
taps.tap()
advance(500)
taps.tap()
assertEquals(listOf(false, false), seen)
}
@Test fun aDeferredSingleTapWaitsForTheWindow() {
atOnce = false
taps.tap()
advance(499)
assertTrue(seen.isEmpty())
advance(1)
assertEquals(listOf(false), seen)
}
@Test fun aDeferredDoubleTapProducesOnlyTheDoubleAction() {
atOnce = false
taps.tap()
advance(100)
taps.tap()
advance(1000)
assertEquals(listOf(true), seen)
}
@Test fun theConfiguredWindowAppliesInBothModes() {
for (mode in listOf(true, false)) for (ms in listOf(100L, 800L)) {
seen.clear()
atOnce = mode
window = ms
taps.tap()
advance(ms - 1)
taps.tap()
assertEquals(true, seen.last())
advance(ms)
assertFalse(taps.pending)
}
}
@Test fun holdKeepsTheWindowOpenUntilTheNextTap() {
taps.tap()
advance(400)
taps.hold()
advance(5000)
assertTrue(taps.pending)
taps.tap()
assertEquals(listOf(false, true), seen)
}
@Test fun cancelDropsADeferredTapAndClosesTheWindow() {
atOnce = false
taps.tap()
taps.cancel()
advance(1000)
assertTrue(seen.isEmpty())
assertFalse(taps.pending)
taps.tap()
advance(500)
assertEquals(listOf(false), seen)
}
@Test fun aDoubleTapWhoseActionMatchesTheImmediateSingleTapIsNotRepeated() {
var same = true
val coalesced = BackTaps({ window }, { atOnce }, seen::add, { same })
coalesced.tap()
coalesced.tap()
assertEquals(listOf(false), seen)
assertFalse(coalesced.pending)
same = false
coalesced.tap()
coalesced.tap()
assertEquals(listOf(false, false, true), seen)
}
@Test fun aDeferredDoubleTapStillActsWhenBothActionsMatch() {
atOnce = false
val coalesced = BackTaps({ window }, { atOnce }, seen::add, { true })
coalesced.tap()
coalesced.tap()
advance(1000)
assertEquals(listOf(true), seen)
}
@Test fun aHeldTapCancelledBeforeItsReleaseLeavesTheNextTapASingleTap() {
val coalesced = BackTaps({ window }, { atOnce }, seen::add, { true })
coalesced.tap()
coalesced.hold()
coalesced.cancel()
advance(5000)
coalesced.tap()
assertEquals(listOf(false, false), seen)
}
private fun advance(ms: Long) = shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(ms))
}
@@ -0,0 +1,77 @@
package com.droiddeck.launcher.input
import android.view.InputDevice
import android.view.MotionEvent
import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34], manifest = Config.NONE)
class PointerCaptureTest {
@Test fun aCapturedMouseReportsItsPositionAsMovement() {
val event = event(MotionEvent.ACTION_MOVE, InputDevice.SOURCE_MOUSE_RELATIVE, x = 12f, y = -7f)
try {
assertTrue(PointerCapture.accepts(event))
assertFalse(PointerCapture.isTouchpad(event))
assertArrayEquals(floatArrayOf(12f, -7f), PointerCapture.delta(event), 0.001f)
} finally {
event.recycle()
}
}
@Test fun batchedMouseSamplesAddUp() {
val event = event(MotionEvent.ACTION_MOVE, InputDevice.SOURCE_MOUSE_RELATIVE, x = 3f, y = -5f)
try {
event.addBatch(1L, arrayOf(MotionEvent.PointerCoords().apply { x = 2f; y = 4f }), 0)
assertArrayEquals(floatArrayOf(5f, -1f), PointerCapture.delta(event), 0.001f)
} finally {
event.recycle()
}
}
@Test fun aCapturedTouchpadIsACapturedPointer() {
val event = event(MotionEvent.ACTION_DOWN, InputDevice.SOURCE_TOUCHPAD, x = 800f, y = 400f)
try {
assertTrue(PointerCapture.accepts(event))
assertTrue(PointerCapture.isTouchpad(event))
} finally {
event.recycle()
}
}
@Test fun anUncapturedMouseIsNotACapturedPointer() {
val event = event(MotionEvent.ACTION_HOVER_MOVE, InputDevice.SOURCE_MOUSE, x = 12f, y = -7f)
try {
assertFalse(PointerCapture.accepts(event))
} finally {
event.recycle()
}
}
@Test fun touchpadTravelMatchesTheSameDistanceOnScreen() {
assertEquals(0.5f, PointerCapture.touchpadScale(unitsPerMm = 20f, padWidth = 2000f, pixelsPerMm = 10f, screenWidth = 1920), 0.001f)
}
@Test fun aTouchpadWithoutAResolutionSpansTheScreen() {
assertEquals(1.92f, PointerCapture.touchpadScale(unitsPerMm = 0f, padWidth = 1000f, pixelsPerMm = 10f, screenWidth = 1920), 0.001f)
}
@Test fun aTouchpadWithoutARangeKeepsItsUnits() {
assertEquals(1f, PointerCapture.touchpadScale(unitsPerMm = 0f, padWidth = 0f, pixelsPerMm = 10f, screenWidth = 1920), 0.001f)
}
private fun event(action: Int, source: Int, x: Float, y: Float): MotionEvent {
val properties = arrayOf(MotionEvent.PointerProperties().apply {
id = 0
toolType = MotionEvent.TOOL_TYPE_FINGER
})
val coords = arrayOf(MotionEvent.PointerCoords().apply { this.x = x; this.y = y })
return MotionEvent.obtain(0L, 0L, action, 1, properties, coords, 0, 0, 1f, 1f, 0, 0, source, 0)
}
}
@@ -331,6 +331,81 @@ class TouchpadGesturesTest {
assertEquals(listOf("left down", "left up", "left down"), events)
}
@Test fun aRestingFingerNeverDragsWhenHoldDragsAreOff() {
touchpad = TouchpadGestures(SLOP, listener, holdDrags = false)
touchpad.bounds = RectF(0f, 0f, 1920f, 1080f)
touchpad.place(960f, 540f)
touch(MotionEvent.ACTION_DOWN, 0, 1 to (400f to 300f))
advance(TouchTiming.HOLD_MS + 100)
touch(MotionEvent.ACTION_POINTER_DOWN, 1, 1 to (400f to 300f), 2 to (600f to 300f))
advance(10)
touch(MotionEvent.ACTION_MOVE, 0, 1 to (400f to 300f), 2 to (620f to 300f))
advance(10)
touch(MotionEvent.ACTION_MOVE, 0, 1 to (400f to 300f), 2 to (640f to 300f))
assertFalse(events.any { it.startsWith("left") || it == "long press" })
}
@Test fun tapsStillClickWhenHoldDragsAreOff() {
touchpad = TouchpadGestures(SLOP, listener, holdDrags = false)
tap()
assertEquals(listOf("left down"), events)
}
@Test fun aPhysicalButtonPressIsNotAlsoATap() {
touch(MotionEvent.ACTION_DOWN, 0, 1 to (400f to 300f))
touchpad.buttonPressed()
advance(80)
touch(MotionEvent.ACTION_UP, 0, 1 to (400f to 300f))
advance(TouchTiming.HOLD_MS + 100)
assertTrue(events.isEmpty())
}
@Test fun aPhysicalButtonPressDuringTwoFingersIsNotARightClick() {
touch(MotionEvent.ACTION_DOWN, 0, 1 to (400f to 300f))
advance(10)
touch(MotionEvent.ACTION_POINTER_DOWN, 1, 1 to (400f to 300f), 2 to (600f to 300f))
touchpad.buttonPressed()
advance(40)
touch(MotionEvent.ACTION_POINTER_UP, 1, 1 to (400f to 300f), 2 to (600f to 300f))
touch(MotionEvent.ACTION_UP, 0, 1 to (400f to 300f))
assertTrue(events.isEmpty())
}
@Test fun aSecondFingerAfterAPhysicalButtonPressIsNotARightClick() {
touch(MotionEvent.ACTION_DOWN, 0, 1 to (400f to 300f))
touchpad.buttonPressed()
advance(10)
touch(MotionEvent.ACTION_POINTER_DOWN, 1, 1 to (400f to 300f), 2 to (600f to 300f))
advance(40)
touch(MotionEvent.ACTION_POINTER_UP, 1, 1 to (400f to 300f), 2 to (600f to 300f))
touch(MotionEvent.ACTION_UP, 0, 1 to (400f to 300f))
advance(TouchTiming.HOLD_MS + 100)
assertTrue(events.isEmpty())
twoFingerTapStillRightClicks()
}
@Test fun aPhysicalButtonPressReleasesAPendingTapClickFirst() {
tap()
assertEquals(listOf("left down"), events)
touchpad.buttonPressed()
assertEquals(listOf("left down", "left up"), events)
advance(TouchTiming.CLICK_MS + 100)
assertEquals(listOf("left down", "left up"), events)
}
private fun twoFingerTapStillRightClicks() {
advance(1000)
events.clear()
touch(MotionEvent.ACTION_DOWN, 0, 1 to (400f to 300f))
advance(10)
touch(MotionEvent.ACTION_POINTER_DOWN, 1, 1 to (400f to 300f), 2 to (600f to 300f))
advance(40)
touch(MotionEvent.ACTION_POINTER_UP, 1, 1 to (400f to 300f), 2 to (600f to 300f))
touch(MotionEvent.ACTION_UP, 0, 1 to (400f to 300f))
advance(TouchTiming.HOLD_MS + 100)
assertTrue("right down" in events)
}
private fun tap() {
touch(MotionEvent.ACTION_DOWN, 0, 1 to (400f to 300f))
advance(80)
@@ -2,7 +2,9 @@ package com.droiddeck.launcher.session
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
@@ -14,7 +16,21 @@ import org.robolectric.annotation.Config
class GpuClockPinTest {
private val context = RuntimeEnvironment.getApplication()
@After fun stop() { GpuClockPin.stop(context) }
private val calls = mutableListOf<Boolean>()
private val node = GpuClockPin.supported
private val turbo = GpuClockPin.turbo
@After fun stop() {
GpuClockPin.stop(context)
GpuClockPin.supported = node
GpuClockPin.turbo = turbo
SessionPrefs.setGpuClockPin(context, false)
}
private fun fakeGpu() {
GpuClockPin.supported = true
GpuClockPin.turbo = { calls += it }
}
@Test fun aToggleOutsideASessionSaysNothing() {
SessionPrefs.setGpuClockPin(context, true)
@@ -31,4 +47,52 @@ class GpuClockPinTest {
SessionPrefs.setGpuClockPin(context, false)
assertEquals(started, GpuClockPin.sync(context))
}
@Test fun aBoostHoldsTheClockOnlyWhileItLasts() {
fakeGpu()
assertEquals("gpu clock: governed", GpuClockPin.start(context))
assertTrue(GpuClockPin.boost(true))
assertEquals("gpu clock: held at its top", GpuClockPin.sync(context))
assertFalse(GpuClockPin.boost(true))
assertTrue(GpuClockPin.boost(false))
assertEquals("gpu clock: governed", GpuClockPin.sync(context))
assertEquals(listOf(true, false), calls)
}
@Test fun endingABoostKeepsTheHoldTheUserTurnedOn() {
fakeGpu()
SessionPrefs.setGpuClockPin(context, true)
GpuClockPin.start(context)
GpuClockPin.boost(true)
GpuClockPin.sync(context)
GpuClockPin.boost(false)
assertEquals("gpu clock: held at its top", GpuClockPin.sync(context))
assertFalse(false in calls)
}
@Test fun aBoostOutsideASessionDoesNothing() {
fakeGpu()
GpuClockPin.boost(true)
assertNull(GpuClockPin.sync(context))
assertTrue(calls.isEmpty())
}
@Test fun aBoostDoesNotOutliveItsSession() {
fakeGpu()
GpuClockPin.start(context)
GpuClockPin.boost(true)
GpuClockPin.sync(context)
GpuClockPin.stop(context)
assertEquals("gpu clock: governed", GpuClockPin.start(context))
assertEquals(listOf(true, false), calls)
}
@Test fun aBoostWithoutTheGpuNodeLeavesTheClockGoverned() {
GpuClockPin.supported = false
GpuClockPin.turbo = { calls += it }
GpuClockPin.start(context)
GpuClockPin.boost(true)
assertEquals("gpu clock: no /dev/kgsl-3d0, left governed", GpuClockPin.sync(context))
assertTrue(calls.isEmpty())
}
}
+30
View File
@@ -444,3 +444,33 @@ starts there as before, but no motion is sent for it. The fake pointer position
With the patch, the Duo starts with only the bottom bar under the parked pointer hovered and controller focus on the
first tile (4 of 4 starts), and returns from a game the same way (3 of 3). Making 0100 ignore the X server's initial
pointer instead was tried and rejected: the centre motion still arrived, and the header or search bar ended up hovered.
## 0143 wlserver: only the first finger drives the emulated mouse
In the Hover, Left, Right, Middle and Trackpad touch click modes every finger warped the X pointer and any finger lifting
released the click. With a second finger down the pointer jumped between both fingers on every frame while the button
stayed held, so a dragged item followed whichever finger moved last, and lifting the second finger dropped it under the
first. The first finger of a gesture now owns the emulated mouse: only it moves the pointer and only its lift releases the
click. Fingers that land while it is down are ignored, and so are the others once it lifts, until every finger is up.
Touches the click modes never claimed (Passthrough, Disabled, no focused surface) still release a held click when they
lift, and the nested pointer (`bAlwaysWarpCursor`) moves the pointer as before. `tools/tests/test_gamescope_touch_click_owner.py`
compiles the rule from this patch.
## 0144 steamcompmgr: motion into the screen edge does not decide the pointer hold
0133 compares the motion gamescope sends with how the X pointer moves. At the edge of the X screen the pointer cannot move
further, so a drawn-cursor game whose pointer sat at an edge while touch or mouse motion pushed outward counted as
holding the pointer: the hold stayed on, every such frame restarted the 30 frames needed to release it, and touch drags
kept turning into relative motion with no button held. The sent motion is now clamped to what the pointer can reach
inside the X screen before it is compared, so motion into an edge counts as no motion. A recentring game is detected as
before, since its pointer stays away from the edges. `tools/tests/test_gamescope_pointer_hold_edge.py` compiles the rule
from this patch with the 0133 rule.
## 0145 steamcompmgr: touch-down warps do not decide the pointer hold
In click mode every touch-down warps the X pointer to the finger. 0133 read that jump as the pointer not following the
sent motion, so each new stroke on a drawn-cursor game restarted the 30 following frames needed to release the hold.
Short strokes never released it, and taps kept landing at the relative pointer instead of under the finger. wlserver now
counts its touch-down warps, and a frame that contains one is left out of the hold decision. Touch drags, mouse motion
and mouse warps still count, so a drag on a game that follows the pointer releases the hold and a recentring game is
still held. `tools/tests/test_gamescope_pointer_hold_touch_down.py` compiles the rule with the 0133 rule.
@@ -0,0 +1,75 @@
diff --git a/src/wlserver.cpp b/src/wlserver.cpp
index 9740875..cb72051 100644
--- a/src/wlserver.cpp
+++ b/src/wlserver.cpp
@@ -3283,6 +3283,38 @@ static void apply_touchscreen_orientation(GamescopePanelOrientation orientation,
*y = ty;
}
+struct TouchClickState
+{
+ std::set<int> ids;
+ int nOwner = -1;
+};
+
+static TouchClickState s_TouchClick;
+
+static bool touch_click_claim( TouchClickState &state, int nTouchId )
+{
+ if ( state.ids.empty() )
+ state.nOwner = nTouchId;
+ state.ids.insert( nTouchId );
+ return state.nOwner == nTouchId;
+}
+
+static bool touch_click_drives( const TouchClickState &state, int nTouchId )
+{
+ return state.nOwner == nTouchId;
+}
+
+static bool touch_click_lift( TouchClickState &state, int nTouchId )
+{
+ const bool bTracked = state.ids.erase( nTouchId ) > 0;
+ if ( state.nOwner == nTouchId )
+ {
+ state.nOwner = -1;
+ return true;
+ }
+ return !bTracked && state.nOwner < 0;
+}
+
void wlserver_touchmotion( double x, double y, int touch_id, uint32_t time, bool bAlwaysWarpCursor, gamescope::IBackendConnector* connector )
{
assert( wlserver_is_lock_held() );
@@ -3333,9 +3365,10 @@ void wlserver_touchmotion( double x, double y, int touch_id, uint32_t time, bool
}
else if ( eMode == gamescope::TouchClickModes::Trackpad )
{
- wlserver_mousemotion( trackpad_dx, trackpad_dy, time );
+ if ( touch_click_drives( s_TouchClick, touch_id ) )
+ wlserver_mousemotion( trackpad_dx, trackpad_dy, time );
}
- else
+ else if ( bAlwaysWarpCursor || touch_click_drives( s_TouchClick, touch_id ) )
{
g_bPendingTouchMovement = true;
@@ -3389,7 +3422,7 @@ void wlserver_touchdown( double x, double y, int touch_id, uint32_t time, gamesc
{
return;
}
- else
+ else if ( touch_click_claim( s_TouchClick, touch_id ) )
{
g_bPendingTouchMovement = true;
@@ -3417,7 +3450,8 @@ void wlserver_touchup( int touch_id, uint32_t time )
// Release whatever the touch pressed even if its surface is gone, or the seat keeps the button down.
bool bReleasedAny = false;
- for ( int i = 0; i < WLSERVER_BUTTON_COUNT; i++ )
+ const bool bClickTouch = touch_click_lift( s_TouchClick, touch_id );
+ for ( int i = 0; bClickTouch && i < WLSERVER_BUTTON_COUNT; i++ )
{
if ( wlserver.button_held[ i ] == true )
{
@@ -0,0 +1,28 @@
diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp
index e98d320..85af598 100644
--- a/src/steamcompmgr.cpp
+++ b/src/steamcompmgr.cpp
@@ -3245,6 +3245,11 @@ static bool pointer_hold_step( PointerHold &state, bool bConstrained, double flS
return state.bHeld;
}
+static double pointer_reach( int nFrom, double flDelta, int nSize )
+{
+ return std::clamp( nFrom + flDelta, 0.0, double( std::max( nSize - 1, 0 ) ) ) - nFrom;
+}
+
static bool s_bPointerHeld = false;
static void update_pointer_hold( global_focus_t *pFocus, bool bConstrained, bool bHinted )
@@ -3311,7 +3316,10 @@ static void update_pointer_hold( global_focus_t *pFocus, bool bConstrained, bool
if ( s_bTracking )
{
- s_bPointerHeld = pointer_hold_step( s_Hold, true, flDX, flDY, nRootX - s_nRootX, nRootY - s_nRootY, get_time_in_nanos() );
+ const xwayland_ctx_t *pCtx = pFocus->cursor->getCtx();
+ const double flReachX = pointer_reach( s_nRootX, flDX, pCtx->root_width );
+ const double flReachY = pointer_reach( s_nRootY, flDY, pCtx->root_height );
+ s_bPointerHeld = pointer_hold_step( s_Hold, true, flReachX, flReachY, nRootX - s_nRootX, nRootY - s_nRootY, get_time_in_nanos() );
}
else
{
@@ -0,0 +1,73 @@
diff --git a/src/wlserver.hpp b/src/wlserver.hpp
--- a/src/wlserver.hpp
+++ b/src/wlserver.hpp
@@ -173,6 +173,7 @@
double flFollowDY = 0.0;
double flSentDX = 0.0;
double flSentDY = 0.0;
+ uint64_t ulTouchDownWarps = 0;
bool button_held[ WLSERVER_BUTTON_COUNT ];
std::set <uint32_t> touch_down_ids;
diff --git a/src/wlserver.cpp b/src/wlserver.cpp
--- a/src/wlserver.cpp
+++ b/src/wlserver.cpp
@@ -3429,6 +3429,7 @@
if ( eMode != gamescope::TouchClickModes::Trackpad )
{
wlserver_mousewarp( tx, ty, time, false, true );
+ wlserver.ulTouchDownWarps++;
}
uint32_t button = TouchClickModeToLinuxButton( eMode );
diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp
--- a/src/steamcompmgr.cpp
+++ b/src/steamcompmgr.cpp
@@ -3263,6 +3263,7 @@
static bool s_bHinted = false;
static const steamcompmgr_win_t *s_pWindow = nullptr;
static const struct wlr_pointer_constraint_v1 *s_pConstraint = nullptr;
+ static uint64_t s_ulTouchDownWarps = 0;
wlserver_lock();
const double flX = wlserver.mouse_surface_cursorx;
@@ -3272,8 +3273,12 @@
const struct wlr_pointer_constraint_v1 *pConstraint = wlserver.GetCursorConstraint();
wlserver.flSentDX = 0.0;
wlserver.flSentDY = 0.0;
+ const uint64_t ulTouchDownWarps = wlserver.ulTouchDownWarps;
wlserver_unlock();
+ const bool bTouchDown = ulTouchDownWarps != s_ulTouchDownWarps;
+ s_ulTouchDownWarps = ulTouchDownWarps;
+
if ( !bConstrained || !pFocus->cursor )
{
s_bTracking = false;
@@ -3314,19 +3319,19 @@
int nRootY = 0;
pFocus->cursor->QueryRootPosition( &nRootX, &nRootY );
- if ( s_bTracking )
+ if ( !s_bTracking )
+ {
+ s_Hold = PointerHold{};
+ s_Hold.bHeld = bHinted;
+ s_bPointerHeld = bHinted;
+ }
+ else if ( !bTouchDown )
{
const xwayland_ctx_t *pCtx = pFocus->cursor->getCtx();
const double flReachX = pointer_reach( s_nRootX, flDX, pCtx->root_width );
const double flReachY = pointer_reach( s_nRootY, flDY, pCtx->root_height );
s_bPointerHeld = pointer_hold_step( s_Hold, true, flReachX, flReachY, nRootX - s_nRootX, nRootY - s_nRootY, get_time_in_nanos() );
}
- else
- {
- s_Hold = PointerHold{};
- s_Hold.bHeld = bHinted;
- s_bPointerHeld = bHinted;
- }
s_bTracking = true;
s_flSeatX = flX;
@@ -0,0 +1,102 @@
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[2]
HOLD = ROOT / "tools/gamescope/patches/0133-constraint-relative-when-held.patch"
EDGE = ROOT / "tools/gamescope/patches/0144-pointer-hold-ignores-motion-into-the-edge.patch"
def added_source(patch):
return "\n".join(line[1:] for line in patch.read_text().splitlines() if line.startswith("+") and not line.startswith("+++"))
def block(text, start):
begin = text.index(start)
return text[begin:text.index("\n}", begin) + 3]
PREAMBLE = r'''
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
'''
MAIN = r'''
static const uint64_t FRAME = 16'666'667ul;
struct Pointer {
PointerHold hold;
int x;
int width;
uint64_t now = 1'000'000'000ul;
bool step(double seatDX, int pointerDX) {
now += FRAME;
const double reach = pointer_reach(x, seatDX, width);
x += pointerDX;
return pointer_hold_step(hold, true, reach, 0.0, pointerDX, 0.0, now);
}
};
int main() {
assert(pointer_reach(1279, 26.0, 1280) == 0.0);
assert(pointer_reach(1270, 26.0, 1280) == 9.0);
assert(pointer_reach(0, -13.0, 1280) == 0.0);
assert(pointer_reach(640, -13.0, 1280) == -13.0);
assert(pointer_reach(5, 3.0, 0) == -5.0);
Pointer pinned{{}, 1279, 1280};
for (int i = 0; i < 20; i++) assert(!pinned.step(26.0, 0));
Pointer release{{}, 1279, 1280};
release.hold.bHeld = true;
for (int i = 0; i < 20; i++) assert(release.step(26.0, 0));
for (int i = 0; i < 10; i++) assert(release.step(-13.0, -13));
for (int i = 0; i < 10; i++) assert(release.step(13.0, 13));
assert(release.x == 1279);
for (int i = 0; i < 20; i++) assert(release.step(26.0, 0));
for (int i = 0; i < 9; i++) assert(release.step(-13.0, -13));
assert(!release.step(-13.0, -13));
bool held = false;
Pointer recentre{{}, 640, 1280};
held = false;
for (int i = 0; i < 3; i++) held = recentre.step(26.0, 0);
assert(held);
return 0;
}
'''
class GamescopePointerHoldEdgeTest(unittest.TestCase):
def test_motion_into_the_screen_edge_neither_holds_nor_resets_the_release(self):
compiler = shutil.which("c++") or shutil.which("g++") or shutil.which("clang++")
if not compiler:
self.skipTest("no C++ compiler")
hold = added_source(HOLD)
edge = added_source(EDGE)
source = PREAMBLE + "\n".join([
block(hold, "struct PointerHold"),
block(hold, "static bool pointer_hold_step"),
block(edge, "static double pointer_reach"),
]) + MAIN
with tempfile.TemporaryDirectory() as tmp:
src = Path(tmp) / "pointer_hold_edge.cpp"
exe = Path(tmp) / "pointer_hold_edge"
src.write_text(source)
subprocess.run([compiler, "-std=c++17", "-Wall", "-Werror", "-UNDEBUG", str(src), "-o", str(exe)], check=True)
subprocess.run([str(exe)], check=True)
def test_the_hold_rule_compares_against_the_reachable_motion(self):
edge = added_source(EDGE)
self.assertIn("pointer_reach( s_nRootX, flDX, pCtx->root_width )", edge)
self.assertIn("pointer_reach( s_nRootY, flDY, pCtx->root_height )", edge)
self.assertIn("pointer_hold_step( s_Hold, true, flReachX, flReachY,", edge)
if __name__ == "__main__":
unittest.main()
@@ -0,0 +1,109 @@
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[2]
HOLD = ROOT / "tools/gamescope/patches/0133-constraint-relative-when-held.patch"
DOWN = ROOT / "tools/gamescope/patches/0145-pointer-hold-skips-touch-down-warps.patch"
def added_source(patch):
return "\n".join(line[1:] for line in patch.read_text().splitlines() if line.startswith("+") and not line.startswith("+++"))
def block(text, start):
begin = text.index(start)
return text[begin:text.index("\n}", begin) + 3]
PREAMBLE = r'''
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
'''
MAIN = r'''
static const uint64_t FRAME = 16'666'667ul;
struct Session {
PointerHold hold;
uint64_t now = 1'000'000'000ul;
bool skipTouchDown;
bool frame(double seatDX, double pointerDX, bool touchDown) {
now += FRAME;
if (touchDown && skipTouchDown) return hold.bHeld;
return pointer_hold_step(hold, true, seatDX, 0.0, pointerDX, 0.0, now);
}
void held() {
hold = PointerHold{};
hold.bHeld = true;
}
bool strokes() {
held();
bool result = true;
for (int i = 0; i < 17; i++) result = frame(80.0, 80.0, false);
result = frame(41.0, -1106.0, true);
for (int i = 0; i < 15; i++) result = frame(73.3, 73.0, false);
return result;
}
};
int main() {
Session counted{{}, 1'000'000'000ul, false};
assert(counted.strokes());
Session skipped{{}, 1'000'000'000ul, true};
assert(!skipped.strokes());
Session drag{{}, 1'000'000'000ul, true};
drag.held();
bool result = drag.frame(41.0, -1106.0, true);
assert(result);
for (int i = 0; i < 29; i++) result = drag.frame(12.0, 12.0, false);
assert(result);
result = drag.frame(12.0, 12.0, false);
assert(!result);
Session recentre{{}, 1'000'000'000ul, true};
for (int i = 0; i < 3; i++) result = recentre.frame(26.0, 0.0, false);
assert(result);
result = recentre.frame(-400.0, 300.0, true);
assert(result);
for (int i = 0; i < 40; i++) result = recentre.frame(12.0, 0.0, false);
assert(result);
return 0;
}
'''
class GamescopePointerHoldTouchDownTest(unittest.TestCase):
def test_touch_down_is_skipped_and_touch_drags_release_the_hold(self):
compiler = shutil.which("c++") or shutil.which("g++") or shutil.which("clang++")
if not compiler:
self.skipTest("no C++ compiler")
hold = added_source(HOLD)
source = PREAMBLE + "\n".join([
block(hold, "struct PointerHold"),
block(hold, "static bool pointer_hold_step"),
]) + MAIN
with tempfile.TemporaryDirectory() as tmp:
src = Path(tmp) / "pointer_hold_touch_down.cpp"
exe = Path(tmp) / "pointer_hold_touch_down"
src.write_text(source)
subprocess.run([compiler, "-std=c++17", "-Wall", "-Werror", "-UNDEBUG", str(src), "-o", str(exe)], check=True)
subprocess.run([str(exe)], check=True)
def test_only_touch_down_warps_are_skipped(self):
added = added_source(DOWN)
self.assertIn(" \t\t\t\twlserver_mousewarp( tx, ty, time, false, true );\n+\t\t\t\twlserver.ulTouchDownWarps++;", DOWN.read_text())
self.assertEqual(1, added.count("wlserver.ulTouchDownWarps++"))
self.assertIn("const bool bTouchDown = ulTouchDownWarps != s_ulTouchDownWarps;", added)
self.assertIn("else if ( !bTouchDown )", added)
self.assertNotIn("bFromTouch )\n\t\twlserver.ulTouchDownWarps++", added)
if __name__ == "__main__":
unittest.main()
@@ -0,0 +1,121 @@
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[2]
PATCH = ROOT / "tools/gamescope/patches/0143-touch-click-first-finger-drives.patch"
def added_source():
return "\n".join(line[1:] for line in PATCH.read_text().splitlines() if line.startswith("+") and not line.startswith("+++"))
def block(text, start):
begin = text.index(start)
return text[begin:text.index("\n}", begin) + 3]
PREAMBLE = r'''
#include <cassert>
#include <set>
'''
MAIN = r'''
struct Pointer {
TouchClickState state;
int warps = 0;
int presses = 0;
int releases = 0;
void down(int id) { if (touch_click_claim(state, id)) { warps++; presses++; } }
void move(int id, bool nested = false) { if (nested || touch_click_drives(state, id)) warps++; }
void up(int id) { if (touch_click_lift(state, id)) releases++; }
};
int main() {
Pointer tap;
tap.down(1);
tap.move(1);
tap.up(1);
assert(tap.presses == 1 && tap.releases == 1 && tap.warps == 2);
Pointer drag;
drag.down(1);
drag.move(1);
drag.down(2);
drag.move(2);
drag.move(1);
drag.up(2);
assert(drag.presses == 1 && drag.releases == 0 && drag.warps == 3);
drag.move(1);
drag.up(1);
assert(drag.releases == 1 && drag.warps == 4);
Pointer handover;
handover.down(1);
handover.down(2);
handover.up(1);
assert(handover.releases == 1);
handover.move(2);
handover.down(3);
handover.move(3);
assert(handover.warps == 1 && handover.presses == 1);
handover.up(3);
handover.up(2);
assert(handover.releases == 1);
handover.down(4);
handover.move(4);
handover.up(4);
assert(handover.presses == 2 && handover.releases == 2 && handover.warps == 3);
Pointer nested;
nested.move(0, true);
nested.down(1);
nested.move(0, true);
assert(nested.warps == 3);
Pointer stray;
stray.up(7);
assert(stray.releases == 1);
stray.down(1);
stray.up(7);
assert(stray.releases == 1);
stray.up(1);
assert(stray.releases == 2);
return 0;
}
'''
class GamescopeTouchClickOwnerTest(unittest.TestCase):
def test_only_the_first_finger_drives_the_emulated_mouse(self):
compiler = shutil.which("c++") or shutil.which("g++") or shutil.which("clang++")
if not compiler:
self.skipTest("no C++ compiler")
added = added_source()
helpers = "\n".join(block(added, start) for start in (
"struct TouchClickState",
"static bool touch_click_claim",
"static bool touch_click_drives",
"static bool touch_click_lift",
))
source = PREAMBLE + helpers + MAIN
with tempfile.TemporaryDirectory() as tmp:
src = Path(tmp) / "touch_click_owner.cpp"
exe = Path(tmp) / "touch_click_owner"
src.write_text(source)
subprocess.run([compiler, "-std=c++17", "-Wall", "-Werror", "-UNDEBUG", str(src), "-o", str(exe)], check=True)
subprocess.run([str(exe)], check=True)
def test_the_patch_gates_every_finger_path(self):
added = added_source()
self.assertIn("else if ( bAlwaysWarpCursor || touch_click_drives( s_TouchClick, touch_id ) )", added)
self.assertIn("if ( touch_click_drives( s_TouchClick, touch_id ) )", added)
self.assertIn("else if ( touch_click_claim( s_TouchClick, touch_id ) )", added)
self.assertIn("bClickTouch && i < WLSERVER_BUTTON_COUNT", added)
if __name__ == "__main__":
unittest.main()