Compare commits

..
18 changed files with 111 additions and 738 deletions

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() },
@@ -1757,7 +1737,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
onBlackFrameInsertion = { on ->
SessionPrefs.setBlackFrameInsertion(this@SessionActivity, on)
blackFrameInsertion = on
CompositorHost.setBlackFrameInsertion(on, refreshHz(), outputFpsLimit())
CompositorHost.setBlackFrameInsertion(on, refreshHz(), compositorFpsLimit())
},
hdr = hdrWanted,
hdrAvailable = hdrAvailable,
@@ -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)
@@ -2959,7 +2944,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
CompositorHost.startOrAttach(
this, holder.surface, runtimeDir.path,
driverId?.let { turnip.driverPath(it) }, driverId?.let { turnip.libraryName(it) },
applicationInfo.nativeLibraryDir, size.first, size.second, refreshHz(holder), outputFpsLimit(),
applicationInfo.nativeLibraryDir, size.first, size.second, refreshHz(holder), compositorFpsLimit(),
)
onOutputAttached(holder)
if (SessionState.running && size != previous) {
@@ -3150,6 +3135,18 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
private fun outputFpsLimit(): Int = outputFpsLimit(pipUi)
// Android holds the window to the Game Mode override while the panel runs faster; the guest paces to the panel,
// so without this cap every frame past the override is drawn and dropped.
private fun hostFrameCap(): Int {
if (glassesScreen != null || bottomOutputActive) return 0
val display = (if (Build.VERSION.SDK_INT >= 30) display else @Suppress("DEPRECATION") windowManager.defaultDisplay) ?: return 0
return SessionPrefs.hostFrameCap(display.refreshRate, display.mode.refreshRate)
}
private fun compositorFpsLimit(): Int = SessionPrefs.compositorFpsLimit(
mirrorRefreshLimit(), if (noSteamSession()) SessionState.fpsLimit else 0, pipUi, hostFrameCap(),
)
private fun outputFpsLimit(pip: Boolean): Int =
SessionPrefs.compositorFpsLimit(mirrorRefreshLimit(), if (noSteamSession()) SessionState.fpsLimit else 0, pip)
@@ -3187,7 +3184,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
)
val hz = refreshHz()
val changed = kotlin.math.abs(SessionState.refreshHz - hz) > 0.1f
CompositorHost.updatePacing(hz, outputFpsLimit())
CompositorHost.updatePacing(hz, compositorFpsLimit())
pushCardboard(activeCardboard)
if (changed && ::surfaceView.isInitialized) applyFrameGen()
}
@@ -3502,11 +3499,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 +3663,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 +3696,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 +3848,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 +4032,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 +4163,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 +5339,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 +5585,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 +5595,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 +5615,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 +5668,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 +5719,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 +5743,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 +6139,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 +6303,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
onScreenControls?.reload()
controllerSettings = ControllerPrefs.read(this)
resumed = true
boostGpuClock(panelOverGame)
updateKeyboardRoute()
retryFieldKeyboard(hasWindowFocus())
updateDesktopKeyboardButton()
@@ -6410,7 +6353,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 +6386,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 +6968,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 +7041,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 +7174,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)
}
@@ -1800,16 +1800,15 @@ object SessionPrefs {
const val PIP_FPS = 30
fun compositorFpsLimit(mirrorRefreshLimit: Int, sessionLimit: Int = 0, pip: Boolean = false): Int {
val limit = when {
mirrorRefreshLimit <= 0 && sessionLimit <= 0 -> FPS_UNPACED
mirrorRefreshLimit <= 0 -> sessionLimit
sessionLimit <= 0 -> mirrorRefreshLimit
else -> minOf(mirrorRefreshLimit, sessionLimit)
}
fun compositorFpsLimit(mirrorRefreshLimit: Int, sessionLimit: Int = 0, pip: Boolean = false, hostCap: Int = 0): Int {
val limit = listOf(mirrorRefreshLimit, sessionLimit, hostCap).filter { it > 0 }.minOrNull() ?: FPS_UNPACED
return if (pip && mirrorRefreshLimit <= 0 && (limit <= 0 || limit > PIP_FPS)) PIP_FPS else limit
}
/** The per-app rate Android holds this window to (Game Mode's FPS override), or 0 when the panel's rate applies. */
fun hostFrameCap(overrideHz: Float, panelHz: Float): Int =
if (overrideHz > 1f && panelHz - overrideHz > 1f) Math.round(overrideHz) else 0
val upscalerChoices = listOf(
2 to "Nearest", 0 to "Linear", 4 to "AMD FSR 1", 3 to "Snapdragon GSR",
8 to "Snapdragon GSR (quality)", 7 to "NVIDIA NIS", 6 to "Sharpen only",
@@ -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())
}
}
@@ -30,4 +30,16 @@ class OutputPacingTest {
@Test fun mirroringKeepsTheGlassesRate() {
assertEquals(60, SessionPrefs.compositorFpsLimit(60))
}
@Test fun gameModeOverrideCapsAPanelThatRunsFaster() {
assertEquals(60, SessionPrefs.hostFrameCap(60.000004f, 120.00001f))
assertEquals(0, SessionPrefs.hostFrameCap(120.00001f, 120.00001f))
assertEquals(0, SessionPrefs.hostFrameCap(0f, 120f))
}
@Test fun hostCapPacesSteamSessionsAndYieldsToLowerLimits() {
assertEquals(60, SessionPrefs.compositorFpsLimit(0, 0, hostCap = 60))
assertEquals(45, SessionPrefs.compositorFpsLimit(0, 45, hostCap = 60))
assertEquals(SessionPrefs.PIP_FPS, SessionPrefs.compositorFpsLimit(0, 0, pip = true, hostCap = 60))
}
}
+4 -5
View File
@@ -35,11 +35,10 @@ GAMESCOPE_COMMIT=8f212644c46460549035971ab914421180f61a7c
GAMESCOPE_PATCHES="0117-wsi-cache-present-bypass-check.patch 0119-wsi-default-images-under-limiter.patch"
VULKAN_HEADERS_TAG=v1.4.341
# The bionic DroidDeck-Proton layer the pack is made for: linked against (libwayland-client) and checked against, not packed.
# Layer v18: DroidDeck-Proton 11-14.1 (Valve Wine a47c73f52fd7, as GE-Proton11-14), the build Bannerlator ships; it
# carries the ARM64EC code-map and unwind fixes the 12.8 layer had (5ebfaa6f, 2515a989, e88fab40).
LAYER_URL=https://github.com/The412Banner/proton-wine/releases/download/build-bionic-layers-20261124-v18/DroidDeck-proton-11.0-14.1-arm64ec.wcp
LAYER_SHA256=bf94176180e96584185835f9e80b168666f9fa752aa9583cfedb8fe493134ff6 # proton-wine 1a5735e7 (run 45926928349)
LAYER_VERSION=14.1
# Layer v16 (067c719d) plus the ARM64EC code-map fix for 39-bit hosts (d4c9ffa7, run 44291095238).
LAYER_URL=https://github.com/The412Banner/proton-wine/releases/download/build-bionic-layers-20261118-v16-unwind/DroidDeck-Proton-11.0-12.8-arm64ec.wcp
LAYER_SHA256=3cc74b877bc8707d75aa2cc22e335373b6a6c0b6b1937c7b3c2cd98e55de2e89 # proton-wine d48e30a1 (a188791d + fecf7376 on d4c9ffa7)
LAYER_VERSION=12.8
# Packed into the DroidDeck-Bionic tool next to the layer: FEX with Android-built unix libraries, and default
# DXVK / VKD3D-Proton (DroidDeck components can swap these in files/lib/wine/{dxvk,vkd3d-proton} later).
FEX_URL=https://github.com/The412Banner/Nightlies/releases/download/FEXCore-2611.1/FEXCore-2611.1-unix.wcp
-1
View File
@@ -1,7 +1,6 @@
# GStreamer plugins packed for winegstreamer (game video/audio), from the imagefs's lib/gstreamer-1.0 by name
# (libgst<name>.so): Proton's usual set as far as this imagefs has it (no vpx; videoconvert+videoscale are videoconvertscale).
coreelements
debug
app
audioconvert
audiorate
-18
View File
@@ -109,9 +109,6 @@ export NTSYNC_SHM=$COMPAT/ntsync-shm
# DroidDeck's Force SSBS (its glibc libssbs.so preload) is bionic Wine's own WINE_FORCE_SSBS
on "${DROIDDECK_FORCE_SSBS:-}" && export WINE_FORCE_SSBS=1
export HODLL=libwow64fex.dll WINEDEBUG=err+all,fixme-all
# The network adapter list (GetAdaptersAddresses) from the layer's getifaddrs code: its default if_nameindex code never
# answered here, and the Paradox Launcher (Europa Universalis IV) waited on it forever.
export WINE_NEW_NDIS=${WINE_NEW_NDIS:-1}
export XENVIRONMENT=$TOOL/bionic/Xdefaults
# The adapter's Wayland swapchain gets its buffers back from gamescope later than DroidDeck-Proton's Turnip does;
# with gamescope's default three images the game waits for one about a fifth of the time at high frame rates.
@@ -309,21 +306,6 @@ if [ "$verb" != runinprefix ] && prefix_busy; then
fi
prefix_busy || rm -f "$NTSYNC_SHM".v*
# Steam's running client, as a game's steam_api checks it: Proton names its steam.exe (the prefix's first program,
# alive while the game runs), which this tool does not start. Here the first program is the one Steam started, so a
# launcher that starts the game and quits (EU4's dowser.exe) left a game that reported "Steam not detected". The
# PID is the one this tool's own prefixes carry.
steam_pid() {
R=$COMPAT/pfx/user.reg
[ -f "$R" ] || return 0
awk '/^\[/ { on = index($0, "[Software\\\\Valve\\\\Steam\\\\ActiveProcess]") == 1 }
on && /^"PID"=dword:/ && $0 != "\"PID\"=dword:0000fffe" { found = 1 } END { exit !found }' "$R" || return 0
awk '/^\[/ { on = index($0, "[Software\\\\Valve\\\\Steam\\\\ActiveProcess]") == 1 }
on && /^"PID"=dword:/ { print "\"PID\"=dword:0000fffe"; next } { print }' "$R" > "$R.dd-new.$$" && mv -f "$R.dd-new.$$" "$R" &&
echo "$(date +%H:%M:%S) Steam's process ID in the registry set to this tool's"
}
prefix_busy || steam_pid
# Links into a tool that is gone (an older DroidDeck-Bionic, a deleted DroidDeck-Proton) or to a file it no longer has.
# Wine's update cannot write over them, so drivers (network, controller) and other files stay missing. Drop them and
# clear both stamps: prepare_prefix relinks this tool's files and Wine's update puts its own back.
-16
View File
@@ -36,21 +36,6 @@ zpath() {
esac
}
# Drive links of the prefix in compatdata folder $1 that name guest paths (DroidDeck-Proton's s: for the Steam library)
# -> their Android paths, which this Wine follows. A game's mods on S: were missing otherwise. A session's start
# gives them their guest paths back (NativeGuest.relinkPrefixDrives); z: is launch.sh's.
android_drives() {
local d t a
for d in "$1"/pfx/dosdevices/[a-y]:; do
[ -L "$d" ] || continue
t=$(readlink "$d")
case "$t" in /*) ;; *) continue ;; esac
a=$(real "$t")
[ "$a" = "$t" ] && continue
ln -sfn "$a" "$d.dd-new.$$" && mv -fT "$d.dd-new.$$" "$d" && echo "drive ${d##*/} -> $a"
done
}
# Where a game launch's log goes in DroidDeck's session folder (Share logs takes that folder): the game's log folder
# when Detailed graphics logs made one (droiddeck-game-env), else a folder of its own; nothing for other verbs
session_logs() {
@@ -124,7 +109,6 @@ print(" ".join(sorted(n for n in names if re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]*"
PY
)
export DROIDDECK_BIONIC_KEEP
[ -n "${STEAM_COMPAT_DATA_PATH:-}" ] && android_drives "$STEAM_COMPAT_DATA_PATH" >&2
exec /system/bin/sh "$tool/bionic/launch.sh" "$verb" "$compat" "$exe" ${args[@]+"${args[@]}"} ;;
getcompatpath)
p=$(real "${1:-}")
-47
View File
@@ -144,53 +144,6 @@ class LaunchLog(unittest.TestCase):
self.assertIn('DXVK_LOG_PATH=${DXVK_LOG_PATH:-$COMPAT}', text)
class PrefixFromProton(unittest.TestCase):
def setUp(self):
self.tmp = tempfile.TemporaryDirectory()
self.addCleanup(self.tmp.cleanup)
self.compat = Path(self.tmp.name) / 'compatdata/236850'
self.drives = self.compat / 'pfx/dosdevices'
self.drives.mkdir(parents=True)
def test_guest_drive_links_get_android_paths(self):
for name, target in (('c:', '../drive_c'), ('s:', '/root/.local/share/Steam'), ('d:', '/mnt/sd/Steam'),
('e:', '/storage/emulated/0/Games'), ('z:', '/')):
os.symlink(target, self.drives / name)
out = proton_function('android_drives "$1"', str(self.compat))
links = {p.name: os.readlink(p) for p in self.drives.iterdir()}
self.assertEqual({'c:': '../drive_c', 's:': ANDROID + '/root/.local/share/Steam', 'd:': '/storage/1234-5678/Steam/Steam',
'e:': '/storage/emulated/0/Games', 'z:': '/'}, links)
self.assertEqual(2, len(out.splitlines()))
self.assertEqual('', proton_function('android_drives "$1"', str(self.compat)))
def test_a_prefix_without_drives_is_left_alone(self):
self.assertEqual('', proton_function('android_drives "$1"', str(Path(self.tmp.name) / 'compatdata/1')))
def steam_pid(self, reg):
text = LAUNCH.read_text()
function = text[text.index('steam_pid() {'):text.index('prefix_busy || steam_pid')]
(self.compat / 'pfx/user.reg').write_text(reg)
out = subprocess.run(['sh', '-c', function + 'steam_pid'], env=dict(os.environ, COMPAT=str(self.compat)),
capture_output=True, text=True, check=True).stdout
return out, (self.compat / 'pfx/user.reg').read_text()
def test_steams_process_id_is_this_tools(self):
reg = ('[Software\\\\Valve\\\\Steam\\\\ActiveProcess] 1795314478\n#time=1dd7a2916a0be94\n"PID"=dword:00000020\n'
'"SteamPath"="C:\\\\Program Files (x86)\\\\Steam"\n\n[Software\\\\Other] 1\n"PID"=dword:00000020\n')
out, after = self.steam_pid(reg)
self.assertIn('process ID', out)
self.assertEqual(reg.replace('"PID"=dword:00000020', '"PID"=dword:0000fffe', 1), after)
out, again = self.steam_pid(after)
self.assertEqual(('', after), (out, again))
def test_a_prefix_without_steams_key_is_unchanged(self):
reg = '[Software\\\\Wine] 1\n"PID"=dword:00000020\n'
self.assertEqual(('', reg), self.steam_pid(reg))
def test_the_network_list_uses_getifaddrs(self):
self.assertIn('export WINE_NEW_NDIS=${WINE_NEW_NDIS:-1}', LAUNCH.read_text())
class StorePaths(unittest.TestCase):
def setUp(self):
self.tmp = tempfile.TemporaryDirectory()