mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
fix(input): make a hardware mouse and keyboard work like a PC (#2053)
* feat(gamescope): a three way switch for relative mouse motion Games that confine the cursor and warp it back to read movement never reach the nested hints rule, so their aim stays bounded by the screen. The convar defaults to 0 and leaves that rule alone; 1 forces relative motion for the focused game, 2 keeps the pointer absolute even when the rule would apply. (cherry picked from commitdb3d7555e0) * feat(input): the session carries a relative mouse mode per game Reads the mode from the game's gesture config, hands it to gamescope as gamescope_relative_mouse, and pushes a change to the running session through gamescopectl. (cherry picked from commite350d88464) * feat(drawer): the relative mouse switch is a three way choice Auto leaves it to the game, on forces relative motion, off keeps the pointer absolute. Named in all 32 locales so none of the three falls back to English. (cherry picked from commite96a187e02) * fix(input): follow the focused game's relative mouse mode Switching to a game whose saved mode differs left the session on the previous game's mode, since only the drawer state was refreshed. The requests also ran on a thread per selection, so two quick picks could reach gamescope out of order. (cherry picked from commit7ff8c5d568) * fix(input): retry the relative mouse mode gamescope did not take The drawer state moved before the request ran, so a failed request left the two out of step and the next focus change skipped the resend. (cherry picked from commitcf0f82d8cd) * fix(input): the relative mouse mode tracks the latest choice The guest agent answers ok when it handled the exec, so a failing gamescopectl was recorded as applied. Reconcile the newest desired mode on the worker thread after each request, and only mark applied when the command really exited zero. (cherry picked from commit5f5e3bd52e) * gamescope: a hidden cursor under any pointer constraint is relative Games that hide the cursor and confine the pointer had no lock hint, so the nested pointer stayed absolute and the camera froze. * Treat a hardware mouse as a real mouse in sessions A mouse now moves the guest pointer by relative motion for the whole session through pointer capture, so it no longer stops at screen edges or reaches system gestures. Its cursor stays visible in every touch mode, follows the game showing or hiding it, and clicks no longer press on-screen controls. * gamescope: use the mouse test release * Direct touch turns the camera while a game holds the pointer A swipe in direct touch now sends relative motion when a game has the pointer locked, including when the lock starts during the swipe, as when a game hides the cursor while a button is held. * Address review findings on mouse and touch input Keep touchpad taps on on-screen controls, cancel a pending long press during a locked swipe, let the three-finger gesture cancel a locked swipe, refresh capture when the output changes, and use the menu's key for the relative mouse setting. * Keep locked touches inside the game picture and free the mouse in touch editors * End touch editor ownership when the editor goes away * Bring the mouse cursor back when a touch editor closes * Release a pointer lock at the game's pointer * gamescope: use the pointer position test release * Fit the X screen to a fullscreen window larger than it * gamescope: use the X screen fit test release * Return the X screen when no game window has focus * gamescope: use the X screen return test release * ci: avoid redundant gamescope builds * fix: hardware mouse in Desktop and pointer warping games KWin nested on the host only reads relative motion while its own pointer lock is on, so a program that locked the pointer in Desktop (Blender orbit and pan) stopped receiving motion. A captured hardware mouse now turns that lock on, and a real Right Ctrl no longer toggles it. Gamescope follows a game's pointer warps instead of overriding them, and absolute motion also sends raw motion. Also retries relative mouse requests, tidies the unplug path, passes side buttons and fits a second oversized window correctly. * chore: use the gamescope build with patch 0131 * fix: Desktop mouse lock keeps retrying after early attempts fail * fix: hold the key that turns on the Desktop mouse lock KWin ignores a press and release delivered together. * fix: gamescope enters warp following sooner and keeps steady motion * chore: use gamescope p26 * Capture system keys in a focused session and keep the first Desktop mouse motion in place * Use the p27 gamescope build * Update the system keys row test * Recognise a captured mouse so the Desktop grab can start * Keep touch warps out of relative motion * Send Esc from keyboards that report it as Back * Use the p28 gamescope build * Release captured keys on pause, forward motion during a grab and wait for a pending screen fit * Use the p29 gamescope build * fix(input): keep held system keys consumed until they are released Copy each captured key event, since the service owns the original only for the callback, and consume the physical release of a key already released to the guest. Use the published gamescope p20. * fix(input): capture a system key only from its first press --------- Co-authored-by: kingokksa <kingokksa@qq.com> Co-authored-by: maxjivi05 <6025299+maxjivi05@users.noreply.github.com>
This commit is contained in:
56 files changed
+1210
-212
No files matched your search
@@ -66,6 +66,10 @@ class DirectTouchHold(
|
||||
held = false
|
||||
}
|
||||
|
||||
fun cancelPendingHold() {
|
||||
handler.removeCallbacks(hold)
|
||||
}
|
||||
|
||||
fun onTouch(event: MotionEvent): Boolean {
|
||||
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
|
||||
if (liftPending) {
|
||||
|
||||
@@ -7,7 +7,7 @@ object GuestKeys {
|
||||
fun send(event: KeyEvent, sendKey: (code: Int, down: Boolean) -> Unit): Boolean {
|
||||
val down = event.action == KeyEvent.ACTION_DOWN
|
||||
if (!down && event.action != KeyEvent.ACTION_UP) return false
|
||||
var evdev = EvdevKeys.fromKeyCode(event.keyCode)
|
||||
var evdev = if (isKeyboardEscape(event.keyCode, event.scanCode)) KEY_ESC else EvdevKeys.fromKeyCode(event.keyCode)
|
||||
val ch = event.unicodeChar
|
||||
val plain = if (ch > 0) EvdevKeys.unshiftedChar(ch) else 0
|
||||
if (evdev <= 0 && ch > 0) {
|
||||
@@ -27,5 +27,9 @@ object GuestKeys {
|
||||
return true
|
||||
}
|
||||
|
||||
fun isKeyboardEscape(keyCode: Int, scanCode: Int): Boolean =
|
||||
keyCode == KeyEvent.KEYCODE_BACK && scanCode == KEY_ESC
|
||||
|
||||
private const val KEY_ESC = 1
|
||||
private const val KEY_LEFTSHIFT = 42
|
||||
}
|
||||
@@ -45,6 +45,62 @@ object HomeButtonShortcuts {
|
||||
fun onDeviceRemoved(device: Int) = input.onDeviceRemoved(device)
|
||||
}
|
||||
|
||||
object SystemKeyCapture {
|
||||
private var owner: Any? = null
|
||||
private var active: () -> Boolean = { false }
|
||||
private var send: (KeyEvent) -> Unit = {}
|
||||
private val held = HashMap<Pair<Int, Int>, KeyEvent>()
|
||||
private val releasing = HashSet<Pair<Int, Int>>()
|
||||
internal var isKeyboard: (KeyEvent) -> Boolean = ::fromKeyboard
|
||||
|
||||
fun attach(owner: Any, active: () -> Boolean, send: (KeyEvent) -> Unit) {
|
||||
this.owner = owner
|
||||
this.active = active
|
||||
this.send = send
|
||||
}
|
||||
|
||||
fun detach(owner: Any) {
|
||||
if (this.owner !== owner) return
|
||||
held.values.forEach { send(KeyEvent.changeAction(it, KeyEvent.ACTION_UP)) }
|
||||
releasing += held.keys
|
||||
held.clear()
|
||||
this.owner = null
|
||||
active = { false }
|
||||
send = {}
|
||||
}
|
||||
|
||||
internal fun captures(keyCode: Int, metaState: Int): Boolean = when {
|
||||
keyCode == KeyEvent.KEYCODE_META_LEFT || keyCode == KeyEvent.KEYCODE_META_RIGHT -> true
|
||||
metaState and KeyEvent.META_META_ON != 0 -> true
|
||||
metaState and KeyEvent.META_ALT_ON != 0 -> keyCode == KeyEvent.KEYCODE_TAB || keyCode == KeyEvent.KEYCODE_ESCAPE
|
||||
else -> false
|
||||
}
|
||||
|
||||
private fun fromKeyboard(event: KeyEvent): Boolean =
|
||||
event.device?.let { !it.isVirtual && it.keyboardType == android.view.InputDevice.KEYBOARD_TYPE_ALPHABETIC } == true
|
||||
|
||||
fun onKeyEvent(event: KeyEvent): Boolean {
|
||||
val key = event.deviceId to event.keyCode
|
||||
if (event.action == KeyEvent.ACTION_DOWN && event.repeatCount == 0) {
|
||||
releasing -= key
|
||||
} else if (key in releasing) {
|
||||
if (event.action == KeyEvent.ACTION_UP) releasing -= key
|
||||
return true
|
||||
}
|
||||
val taken = when (event.action) {
|
||||
KeyEvent.ACTION_DOWN -> {
|
||||
val take = key in held || (event.repeatCount == 0 && active() && isKeyboard(event) && captures(event.keyCode, event.metaState))
|
||||
if (take) held[key] = KeyEvent(event)
|
||||
take
|
||||
}
|
||||
KeyEvent.ACTION_UP -> held.remove(key) != null
|
||||
else -> false
|
||||
}
|
||||
if (taken) send(event)
|
||||
return taken
|
||||
}
|
||||
}
|
||||
|
||||
class HomeButtonService : AccessibilityService(), InputManager.InputDeviceListener {
|
||||
private var bottomScreen: BottomScreenWatch? = null
|
||||
|
||||
@@ -58,7 +114,8 @@ class HomeButtonService : AccessibilityService(), InputManager.InputDeviceListen
|
||||
bottomScreen = null
|
||||
}
|
||||
|
||||
override fun onKeyEvent(event: KeyEvent) = HomeButtonShortcuts.onKeyEvent(this, event)
|
||||
override fun onKeyEvent(event: KeyEvent) =
|
||||
SystemKeyCapture.onKeyEvent(event) || HomeButtonShortcuts.onKeyEvent(this, event)
|
||||
override fun onAccessibilityEvent(event: AccessibilityEvent?) { event?.let { bottomScreen?.onEvent(it) } }
|
||||
override fun onInterrupt() { HomeButtonShortcuts.release() }
|
||||
override fun onInputDeviceAdded(deviceId: Int) {}
|
||||
|
||||
@@ -519,6 +519,7 @@ class OnScreenControls(
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||
if (editing) return onEditTouch(event)
|
||||
if (event.getToolType(event.actionIndex) == MotionEvent.TOOL_TYPE_MOUSE) return false
|
||||
when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_POINTER_DOWN -> {
|
||||
val index = event.actionIndex
|
||||
|
||||
@@ -56,6 +56,7 @@ class ScreenKeys(context: Context, private val sendKey: (Int, Boolean) -> Unit)
|
||||
private var guideY = -1f
|
||||
private val addPress = Runnable { addX = pressX; addY = pressY; onAdd?.invoke() }
|
||||
private var editing = false
|
||||
val isEditing get() = editing
|
||||
private var selected: Entry? = null
|
||||
private var dragX = 0f
|
||||
private var dragY = 0f
|
||||
@@ -811,6 +812,7 @@ class ScreenKeys(context: Context, private val sendKey: (Int, Boolean) -> Unit)
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean = if (editing) editTouch(event) else playTouch(event)
|
||||
|
||||
private fun playTouch(event: MotionEvent): Boolean {
|
||||
if (event.getToolType(event.actionIndex) == MotionEvent.TOOL_TYPE_MOUSE) return false
|
||||
when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_POINTER_DOWN -> {
|
||||
val index = event.actionIndex
|
||||
|
||||
@@ -107,6 +107,7 @@ class SteamTouchControls(
|
||||
var onTouchMiss: ((MotionEvent) -> Unit)? = null
|
||||
|
||||
private var editing = false
|
||||
var onEditingChanged: ((Boolean) -> Unit)? = null
|
||||
private var editElements: MutableList<Element> = mutableListOf()
|
||||
private var hidden: MutableList<Element> = mutableListOf()
|
||||
private var selected = -1
|
||||
@@ -617,6 +618,7 @@ class SteamTouchControls(
|
||||
}
|
||||
return true
|
||||
}
|
||||
if (event.getToolType(event.actionIndex) == MotionEvent.TOOL_TYPE_MOUSE) return false
|
||||
val index = event.actionIndex
|
||||
lastTouchMs = android.os.SystemClock.uptimeMillis()
|
||||
if (faded) { faded = false; invalidate() }
|
||||
@@ -705,6 +707,7 @@ class SteamTouchControls(
|
||||
fun startEditing() {
|
||||
releaseAll()
|
||||
editing = true
|
||||
onEditingChanged?.invoke(true)
|
||||
editSets.clear()
|
||||
selected = -1
|
||||
pendingBindings.clear()
|
||||
@@ -755,8 +758,13 @@ class SteamTouchControls(
|
||||
actionSet = saved
|
||||
}
|
||||
|
||||
fun cancelEditing() {
|
||||
if (editing) stopEditing()
|
||||
}
|
||||
|
||||
private fun stopEditing() {
|
||||
editing = false
|
||||
onEditingChanged?.invoke(false)
|
||||
trayOpen = false
|
||||
trayDrag = null
|
||||
selected = -1
|
||||
|
||||
@@ -39,6 +39,7 @@ data class TouchGestureConfig(
|
||||
val showGestureDebugOverlay: Boolean = false,
|
||||
val gestureThreshold: Int = DEFAULT_GESTURE_THRESHOLD,
|
||||
val mouseDragMovementMode: String = MOUSE_DRAG_MOVEMENT_DIRECT,
|
||||
val relativeMouseMode: Int = RELATIVE_MOUSE_AUTO,
|
||||
) {
|
||||
|
||||
fun toJson(): String {
|
||||
@@ -75,6 +76,7 @@ data class TouchGestureConfig(
|
||||
put(KEY_SHOW_GESTURE_DEBUG_OVERLAY, showGestureDebugOverlay)
|
||||
put(KEY_GESTURE_THRESHOLD, gestureThreshold)
|
||||
put(KEY_MOUSE_DRAG_MOVEMENT_MODE, mouseDragMovementMode)
|
||||
put(KEY_RELATIVE_MOUSE_MODE, relativeMouseMode)
|
||||
}.toString()
|
||||
}
|
||||
|
||||
@@ -91,6 +93,10 @@ data class TouchGestureConfig(
|
||||
|
||||
const val MOUSE_DRAG_MOVEMENT_DIRECT = "direct"
|
||||
const val MOUSE_DRAG_MOVEMENT_RELATIVE = "relative"
|
||||
|
||||
const val RELATIVE_MOUSE_AUTO = 0
|
||||
const val RELATIVE_MOUSE_ON = 1
|
||||
const val RELATIVE_MOUSE_OFF = 2
|
||||
const val ACTION_SHOW_KEYBOARD = "show_keyboard"
|
||||
const val ACTION_KEY_ESC = "key_ESC"
|
||||
const val ACTION_KEY_TILDE = "key_TILDE"
|
||||
@@ -114,6 +120,7 @@ data class TouchGestureConfig(
|
||||
private const val KEY_LONG_PRESS_MOUSE_BEHAVIOR = "longPressMouseBehavior"
|
||||
private const val KEY_LONG_PRESS_DELAY = "longPressDelay"
|
||||
private const val KEY_DIRECT_HOLD_BEHAVIOR = "directHoldBehavior"
|
||||
private const val KEY_RELATIVE_MOUSE_MODE = "relativeMouseMode"
|
||||
private const val KEY_DOUBLE_TAP_ENABLED = "doubleTapEnabled"
|
||||
private const val KEY_DOUBLE_TAP_DELAY = "doubleTapDelay"
|
||||
private const val KEY_TWO_FINGER_DRAG_ENABLED = "twoFingerDragEnabled"
|
||||
@@ -191,6 +198,7 @@ data class TouchGestureConfig(
|
||||
mouseDragMovementMode = normalizeMouseDragMovementMode(
|
||||
obj.optString(KEY_MOUSE_DRAG_MOVEMENT_MODE, MOUSE_DRAG_MOVEMENT_DIRECT),
|
||||
),
|
||||
relativeMouseMode = normalizeRelativeMouseMode(obj.optInt(KEY_RELATIVE_MOUSE_MODE, RELATIVE_MOUSE_AUTO)),
|
||||
)
|
||||
} catch (_: Exception) {
|
||||
fallbackDefaults()
|
||||
@@ -205,6 +213,10 @@ data class TouchGestureConfig(
|
||||
return if (value == MOUSE_BEHAVIOR_CLICK) MOUSE_BEHAVIOR_CLICK else MOUSE_BEHAVIOR_HOLD
|
||||
}
|
||||
|
||||
private fun normalizeRelativeMouseMode(mode: Int): Int {
|
||||
return if (mode in RELATIVE_MOUSE_AUTO..RELATIVE_MOUSE_OFF) mode else RELATIVE_MOUSE_AUTO
|
||||
}
|
||||
|
||||
private fun normalizeMouseDragMovementMode(mode: String?): String {
|
||||
return if (mode == MOUSE_DRAG_MOVEMENT_RELATIVE) {
|
||||
MOUSE_DRAG_MOVEMENT_RELATIVE
|
||||
|
||||
Reference in new issue
Block a user