Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f5b08ba3bb | ||
|
|
4cc258ef1f | ||
|
|
6b93742e4d | ||
|
|
b9cab09dd4 |
No files matched your search
@@ -450,22 +450,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
return true
|
||||
}
|
||||
private val uiHandler = Handler(Looper.getMainLooper())
|
||||
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 var pendingBackAction: Runnable? = null
|
||||
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) },
|
||||
@@ -913,8 +904,6 @@ 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
|
||||
@@ -1138,11 +1127,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
when {
|
||||
::loading.isInitialized && loading.ended -> finish()
|
||||
inputSettingsOpen -> inputSettingsOpen = false
|
||||
dockedTouchOnly || backTaps.pending -> backTaps.tap()
|
||||
dockedTouchOnly -> routeBackAction()
|
||||
drawerOpen -> drawerOpen = false
|
||||
achievementsOpen -> closeAchievements()
|
||||
pcKeyboardOpen -> pcKeyboardOpen = false
|
||||
else -> backTaps.tap()
|
||||
else -> routeBackAction()
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -1339,15 +1328,8 @@ 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 && 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)
|
||||
if (drawerOpen || pcKeyboardOpen || achievementsOpen || gestureSettingsOpen || inputSettingsOpen || pipUi || appTextFocus || SessionState.suspended) {
|
||||
backQamInput.cancel()
|
||||
com.droiddeck.launcher.input.HomeButtonShortcuts.cancel(this@SessionActivity)
|
||||
cancelTouchGestures()
|
||||
}
|
||||
@@ -1401,7 +1383,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
if (drawerOpen) {
|
||||
syncLossless()
|
||||
if (menuOwnsController) {
|
||||
releasePads(keepBackTap = backTapOpenedDrawer)
|
||||
releasePads()
|
||||
androidx.compose.runtime.withFrameNanos { }
|
||||
val requested = focusDrawer()
|
||||
Log.i(TAG, "drawer root focus requested=$requested docked=$drawerDocked")
|
||||
@@ -1440,8 +1422,6 @@ 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() },
|
||||
@@ -2136,13 +2116,25 @@ 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
|
||||
backTapOpenedDrawer = drawerOpen && !double
|
||||
}
|
||||
if (opensQam) triggerSteamQam() else if (!dockedTouchOnly) drawerOpen = !drawerOpen
|
||||
}
|
||||
|
||||
private fun handleHomeGuideIntent(incoming: Intent?) {
|
||||
@@ -2627,13 +2619,6 @@ 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)
|
||||
@@ -3502,11 +3487,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
focusEndedScreen()
|
||||
}
|
||||
|
||||
private fun releasePads(keepBackTap: Boolean = false) {
|
||||
private fun releasePads() {
|
||||
inputMotion.stop()
|
||||
physicalInputBindings?.release()
|
||||
com.droiddeck.launcher.input.HomeButtonShortcuts.cancel(this)
|
||||
backQamInput.cancel(keepTap = keepBackTap)
|
||||
backQamInput.cancel()
|
||||
padBridge?.releaseAll()
|
||||
joyConVr?.releaseButtons()
|
||||
}
|
||||
@@ -3666,7 +3651,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
!pcKeyboardOpen && !achievementsOpen && !gestureSettingsOpen && !inputSettingsOpen,
|
||||
steam = SessionState.mode == SessionService.MODE_STEAM,
|
||||
) { action ->
|
||||
backTaps.cancel()
|
||||
pendingBackAction?.let(uiHandler::removeCallbacks)
|
||||
pendingBackAction = null
|
||||
if (!dockedMenuIdle) drawerControllerActive = true
|
||||
Log.i(TAG, "physical shortcut ${action.name} device=${event.deviceId} key=${event.keyCode} scan=${event.scanCode}")
|
||||
when (action) {
|
||||
@@ -3698,23 +3684,16 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
}
|
||||
if (mouseBackHandled) return true
|
||||
val backToQam = !pipUi && !appTextFocus && (!menuOwnsController || backQamInput.awaitingTap) && !pcKeyboardOpen && !achievementsOpen &&
|
||||
val backToQam = !pipUi && !appTextFocus && !menuOwnsController && !pcKeyboardOpen && !achievementsOpen &&
|
||||
!inputSettingsOpen && !gestureSettingsOpen &&
|
||||
SessionState.mode == SessionService.MODE_STEAM && SessionState.running && SessionState.firstFrameSeen &&
|
||||
!SessionState.suspended && padBridge?.canHoldQam() == true
|
||||
if (backQamInput.onKeyEvent(event, backToQam)) {
|
||||
backTaps.cancel()
|
||||
pendingBackAction?.let(uiHandler::removeCallbacks)
|
||||
pendingBackAction = null
|
||||
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)
|
||||
@@ -3857,8 +3836,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
else -> return super.dispatchGenericMotionEvent(event)
|
||||
}
|
||||
if ((event.isFromSource(android.view.InputDevice.SOURCE_MOUSE) ||
|
||||
event.isFromSource(android.view.InputDevice.SOURCE_TOUCHPAD)) && !drawerOpen) {
|
||||
if (event.isFromSource(android.view.InputDevice.SOURCE_MOUSE) && !drawerOpen) {
|
||||
if (appUiOwnsPointer()) {
|
||||
if (super.dispatchGenericMotionEvent(event)) return true
|
||||
if (touchEditorOpen) return false
|
||||
@@ -4042,7 +4020,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, pointerAttached(), touchpadRoute)
|
||||
val mode = com.droiddeck.launcher.input.TouchGestureConfig.gamescopeRelativeMouse(wanted, mouseAttached(), 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)
|
||||
@@ -4173,27 +4151,6 @@ 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
|
||||
@@ -5370,8 +5327,7 @@ 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) ||
|
||||
event.isFromSource(android.view.InputDevice.SOURCE_TOUCHPAD))) return onMouse(event)
|
||||
if (penRouted == null && event.isFromSource(android.view.InputDevice.SOURCE_MOUSE)) return onMouse(event)
|
||||
when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
sessionTouchDown = true
|
||||
@@ -5617,11 +5573,7 @@ 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_TOUCHPAD))
|
||||
|
||||
private fun isTouchpad(d: InputDevice?): Boolean =
|
||||
d?.supportsSource(InputDevice.SOURCE_TOUCHPAD) == true
|
||||
(d.supportsSource(InputDevice.SOURCE_MOUSE) || d.supportsSource(InputDevice.SOURCE_MOUSE_RELATIVE))
|
||||
|
||||
/** 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) {
|
||||
@@ -5631,13 +5583,9 @@ 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) && !isTouchpad(d)
|
||||
isHardwareMouse(d) && d?.supportsSource(InputDevice.SOURCE_TOUCHPAD) != true
|
||||
}
|
||||
|
||||
private fun externalMouseAttached(): Boolean {
|
||||
@@ -5655,7 +5603,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() && pointerAttached()
|
||||
val want = (pointerLocked || relativeMouseAttached()) && sessionOwnsInput() && hasWindowFocus() && mouseAttached()
|
||||
releaseDesktopMouseGrab()
|
||||
updateUsbMouse(want)
|
||||
if (want == view.hasPointerCapture()) return
|
||||
@@ -5708,7 +5656,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
|
||||
private fun dropMouseCursor() {
|
||||
if (!mouseOwnsCursor || pointerAttached()) return
|
||||
if (!mouseOwnsCursor || mouseAttached()) return
|
||||
mouseOwnsCursor = false
|
||||
uiHandler.removeCallbacks(cursorResync)
|
||||
cursorVisible = false
|
||||
@@ -5759,22 +5707,20 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
|
||||
private fun onCapturedPointer(event: MotionEvent): Boolean {
|
||||
if (!com.droiddeck.launcher.input.PointerCapture.accepts(event)) return false
|
||||
if (!event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE)) 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 -> {
|
||||
val delta = com.droiddeck.launcher.input.PointerCapture.delta(event)
|
||||
onRelativeMouse(delta[0], delta[1])
|
||||
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)
|
||||
}
|
||||
MotionEvent.ACTION_BUTTON_PRESS, MotionEvent.ACTION_BUTTON_RELEASE -> {}
|
||||
MotionEvent.ACTION_BUTTON_PRESS, MotionEvent.ACTION_BUTTON_RELEASE ->
|
||||
guestMouseButton(event.actionButton)?.let { heldButtons.set(8, it, event.actionMasked == MotionEvent.ACTION_BUTTON_PRESS) }
|
||||
MotionEvent.ACTION_SCROLL -> {
|
||||
val v = event.getAxisValue(MotionEvent.AXIS_VSCROLL)
|
||||
if (v != 0f) sendSceneWheel(-Math.round(v))
|
||||
@@ -5785,21 +5731,6 @@ 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
|
||||
@@ -6196,7 +6127,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
drawerOpen = false
|
||||
pcKeyboardOpen = false
|
||||
achievementsOpen = false
|
||||
backTaps.cancel()
|
||||
pendingBackAction?.let(uiHandler::removeCallbacks)
|
||||
pendingBackAction = null
|
||||
releaseDrawerDirection()
|
||||
onScreenControls?.releaseAll()
|
||||
bottomInputControls?.releaseAll()
|
||||
@@ -6359,7 +6291,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
onScreenControls?.reload()
|
||||
controllerSettings = ControllerPrefs.read(this)
|
||||
resumed = true
|
||||
boostGpuClock(panelOverGame)
|
||||
updateKeyboardRoute()
|
||||
retryFieldKeyboard(hasWindowFocus())
|
||||
updateDesktopKeyboardButton()
|
||||
@@ -6410,7 +6341,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
if (runtimeRemovalBlocked) return
|
||||
physicalShortcuts.clear()
|
||||
backQamInput.cancel()
|
||||
backTaps.cancel()
|
||||
mouseBackInput.cancel()
|
||||
capturePausedFrame()
|
||||
padBridge?.setInputEnabled(false)
|
||||
@@ -6444,7 +6374,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
if (::scrollTouch.isInitialized) scrollTouch.cancel()
|
||||
if (::padMouse.isInitialized) padMouse.reset()
|
||||
resumed = false
|
||||
boostGpuClock(false)
|
||||
updateKeyboardRoute()
|
||||
updatePointerCapture()
|
||||
updatePadMotion()
|
||||
@@ -7027,7 +6956,6 @@ 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
|
||||
@@ -7101,7 +7029,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
if (runtimeRemovalBlocked) { super.onDestroy(); return }
|
||||
watching = false
|
||||
releaseDrawerDirection()
|
||||
backTaps.cancel()
|
||||
pendingBackAction?.let(uiHandler::removeCallbacks)
|
||||
pendingBackAction = null
|
||||
if (::pip.isInitialized) pip.destroyed()
|
||||
closeSecondScreen(reset = false)
|
||||
glassesScope.cancel()
|
||||
@@ -7233,7 +7162,6 @@ 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,15 +6,18 @@ 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 }, atOnce: () -> Boolean = { false }, sameAction: () -> Boolean = { false }) {
|
||||
private val holds: () -> Boolean = { true }) {
|
||||
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 val taps = BackTaps(doubleTapMs, atOnce, onTap, sameAction)
|
||||
val awaitingTap: Boolean get() = taps.pending
|
||||
private var tapPending = false
|
||||
private val singleTap = Runnable { tapPending = false; onTap(false) }
|
||||
|
||||
fun cancelTap() = taps.cancel()
|
||||
private fun cancelTap() {
|
||||
handler.removeCallbacks(singleTap)
|
||||
tapPending = false
|
||||
}
|
||||
|
||||
fun onChordInput() {
|
||||
if (presses.isEmpty()) return
|
||||
@@ -43,7 +46,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
|
||||
taps.hold()
|
||||
handler.removeCallbacks(singleTap)
|
||||
val hold = Runnable {
|
||||
val press = presses[device] ?: return@Runnable
|
||||
if (!holds()) { press.used = true; cancelTap(); return@Runnable }
|
||||
@@ -63,8 +66,10 @@ 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) taps.tap()
|
||||
else if (event.isCanceled) cancelTap()
|
||||
if (!press.used && !event.isCanceled) {
|
||||
if (tapPending) { cancelTap(); onTap(true) }
|
||||
else { tapPending = true; handler.postDelayed(singleTap, doubleTapMs()) }
|
||||
} else if (event.isCanceled) cancelTap()
|
||||
}
|
||||
press != null || wasCancelled || enabled
|
||||
}
|
||||
@@ -72,8 +77,8 @@ class BackQamInput(private val setPressed: (Boolean) -> Unit, private val onTap:
|
||||
}
|
||||
}
|
||||
|
||||
fun cancel(keepTap: Boolean = false) {
|
||||
if (!keepTap) cancelTap()
|
||||
fun cancel() {
|
||||
cancelTap()
|
||||
val wasHeld = presses.values.any { it.held }
|
||||
presses.values.forEach { handler.removeCallbacks(it.hold) }
|
||||
cancelled.addAll(presses.keys)
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
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,7 +9,6 @@ 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
|
||||
@@ -34,7 +33,6 @@ 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
|
||||
@@ -92,15 +90,6 @@ 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)
|
||||
@@ -126,7 +115,7 @@ class TouchpadGestures(
|
||||
releaseClick()
|
||||
lastX = event.x; lastY = event.y
|
||||
downAt = event.eventTime
|
||||
travelled = 0f; held = false; twoFingers = false; scrolled = false; secondWasTap = false; pressed = false
|
||||
travelled = 0f; held = false; twoFingers = false; scrolled = false; secondWasTap = false
|
||||
fingers = 1; pinching = false
|
||||
anchorId = event.getPointerId(0); moverId = -1; holdDrag = false; scrollLocked = false
|
||||
if (clicks && event.eventTime - lastTapAt < TouchTiming.DOUBLE_TAP_MS) {
|
||||
@@ -134,7 +123,7 @@ class TouchpadGestures(
|
||||
press(PointerGestures.BTN_LEFT)
|
||||
} else {
|
||||
dragging = false
|
||||
if (clicks && holdDrags) handler.postDelayed(longPress, TouchTiming.HOLD_MS)
|
||||
if (clicks) handler.postDelayed(longPress, TouchTiming.HOLD_MS)
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -153,7 +142,7 @@ class TouchpadGestures(
|
||||
if (holdDrag) return true
|
||||
twoFingers = true
|
||||
secondDownAt = event.eventTime
|
||||
secondWasTap = !pressed
|
||||
secondWasTap = true
|
||||
scrollAnchorX = (event.getX(0) + event.getX(1)) / 2f
|
||||
scrollAnchorY = (event.getY(0) + event.getY(1)) / 2f
|
||||
pinchSpan = span(event)
|
||||
@@ -164,7 +153,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 (holdDrags && !holdDrag && !scrolled && !scrollLocked) {
|
||||
if (!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,24 +18,10 @@ object GpuClockPin {
|
||||
var failed = false
|
||||
private set
|
||||
|
||||
var supported: Boolean = File(KGSL_NODE).exists()
|
||||
internal set
|
||||
|
||||
internal var turbo: (Boolean) -> Unit = { WaylandCompositor.nativeSetGpuTurbo(it) }
|
||||
val supported: Boolean by lazy { File(KGSL_NODE).exists() }
|
||||
|
||||
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
|
||||
@@ -44,11 +30,11 @@ object GpuClockPin {
|
||||
|
||||
private fun hold(context: Context): String {
|
||||
failed = false
|
||||
if (!wanted(context)) return "gpu clock: governed"
|
||||
if (!SessionPrefs.gpuClockPin(context)) return "gpu clock: governed"
|
||||
if (!supported) return "gpu clock: no $KGSL_NODE, left governed"
|
||||
return try {
|
||||
File(context.filesDir, MARKER).createNewFile()
|
||||
turbo(true)
|
||||
WaylandCompositor.nativeSetGpuTurbo(true)
|
||||
pinned = true
|
||||
"gpu clock: held at its top"
|
||||
} catch (t: Throwable) {
|
||||
@@ -62,14 +48,13 @@ object GpuClockPin {
|
||||
@Synchronized
|
||||
fun sync(context: Context): String? {
|
||||
if (!live) return null
|
||||
if (!wanted(context) && pinned) clear(context)
|
||||
if (!SessionPrefs.gpuClockPin(context) && pinned) clear(context)
|
||||
return hold(context)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun stop(context: Context) {
|
||||
live = false
|
||||
boosted = false
|
||||
if (pinned) clear(context)
|
||||
}
|
||||
|
||||
@@ -81,7 +66,7 @@ object GpuClockPin {
|
||||
private fun clear(context: Context) {
|
||||
if (supported) {
|
||||
try {
|
||||
turbo(false)
|
||||
WaylandCompositor.nativeSetGpuTurbo(false)
|
||||
} catch (t: Throwable) {
|
||||
Log.w(TAG, "clear", t)
|
||||
}
|
||||
|
||||
@@ -63,46 +63,6 @@ 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)
|
||||
@@ -231,19 +191,6 @@ 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)
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
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))
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
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,81 +331,6 @@ 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,9 +2,7 @@ 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
|
||||
@@ -16,21 +14,7 @@ import org.robolectric.annotation.Config
|
||||
class GpuClockPinTest {
|
||||
private val context = RuntimeEnvironment.getApplication()
|
||||
|
||||
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 }
|
||||
}
|
||||
@After fun stop() { GpuClockPin.stop(context) }
|
||||
|
||||
@Test fun aToggleOutsideASessionSaysNothing() {
|
||||
SessionPrefs.setGpuClockPin(context, true)
|
||||
@@ -47,52 +31,4 @@ 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())
|
||||
}
|
||||
}
|
||||
@@ -444,33 +444,3 @@ 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.
|
||||
@@ -1,75 +0,0 @@
|
||||
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 )
|
||||
{
|
||||
@@ -1,28 +0,0 @@
|
||||
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
|
||||
{
|
||||
@@ -1,73 +0,0 @@
|
||||
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;
|
||||
@@ -1,102 +0,0 @@
|
||||
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()
|
||||
@@ -1,109 +0,0 @@
|
||||
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()
|
||||
@@ -1,121 +0,0 @@
|
||||
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()
|
||||
Reference in new issue
Block a user