feat(input): a pen moves the pointer while hovering, clicks with its tip and right-clicks with its side button (#2625)

* feat(compositor): pen samples drive the pointer like a mouse

Input record 13 carries the pen's state (in proximity, tip, right and
middle button) and its position in input space as 24.8 fixed point.
Hover moves the pointer, the tip holds the left button, and a record
without the in-proximity bit releases every button. Under a pointer
lock only the buttons pass. A button pressed or released mid-stroke
keeps the implicit grab on the window the stroke started in, unless
that window closed.

* feat(input): a pen moves the pointer while hovering, clicks with its tip and right-clicks with its side button

In Mouse mode (the default) a pen's hover moves the pointer, the tip
holds the left button and the side button right-clicks; Touch keeps it a
finger. The side button can send a middle click or nothing instead, and
a Bluetooth pen key counts as the side button while the pen is near.
With glasses or a program's pointer lock the pen drives the touchpad.
A hover exit followed within 50 ms by more hover or a touch keeps the
pen near, so a pen at the edge of its hover range does not flicker out,
and a hover that sends nothing for 2 s leaves proximity. On the desktop
a pen that comes near releases KWin's grab of a hardware mouse, so the
pen moves KWin's pointer. Whatever cancels touches also ends the pen,
and stylus devices no longer count as hardware mice.

* feat(input): pen mode and side button settings in the Controls tab and the session drawer

A Pen group follows the touch settings once the phone has a stylus
device or a pen event was seen, which is remembered as penSeen and kept
by a settings reset. It holds Pen (Mouse, Touch) and Side button (Right
click, Middle click, Off); Side button is hidden in Touch. Before
Android 14 a touchscreen reports the stylus source without a pen, so
there it counts only with its first pen event. The strings are
translated into all 32 languages.

* docs: describe pen input and its limits

---------

Co-authored-by: alien2003 <11610652+alien2003@users.noreply.github.com>
This commit is contained in:
alien2003andalien2003 authored and GitHub committed 2026-11-15 09:38:01 -05:00
1 parent de70e37f30
commit decab6ea90
63 files changed
+2352 -38

No files matched your search

+74 -4
View File
@@ -127,6 +127,9 @@ static int log_budget(void) {
#ifndef BTN_RIGHT
#define BTN_RIGHT 0x111
#endif
#ifndef BTN_MIDDLE
#define BTN_MIDDLE 0x112
#endif
#define INPUT_SPACE_W 1920
#define INPUT_SPACE_H 1080
@@ -582,6 +585,13 @@ int droiddeck_cursor_snapshot(int *out, int cap) {
}
struct active_touch { struct surface *surface; int pointer_fallback; };
static struct active_touch g_touch_points[MAX_TOUCH_POINTS];
#define PEN_IN (1 << 0)
#define PEN_TIP (1 << 1)
#define PEN_RIGHT (1 << 2)
#define PEN_MIDDLE (1 << 3)
#define PEN_BIT(button) (1 << ((button) - BTN_LEFT))
struct pen_state { int in, buttons; struct surface *grab; };
static struct pen_state g_pen;
static void touch_cancel_surface(struct surface *surface);
static struct surface *g_grab;
static void publish_query_state(void);
@@ -1339,6 +1349,7 @@ static void surface_resource_destroy(struct wl_resource *r) {
if (g_grab == s) g_grab = NULL;
if (g_key_target == s) g_key_target = NULL;
if (g_ime_click == s) g_ime_click = NULL;
if (g_pen.grab == s) g_pen.grab = NULL;
droiddeck_text_input_surface_gone(r);
if (g_desktop == s) { g_desktop = NULL; droiddeck_log("desktop", "the desktop closed"); }
if (g_hud_surface == s) { g_hud_surface = NULL; droiddeck_on_game_surface(NULL, NULL); }
@@ -3240,14 +3251,14 @@ static void deliver_pointer(const struct input_msg *m) {
pointer_event(x, y, m->p1 == 1 ? 0 : BTN_LEFT, m->p1 == 0);
}
static void input_output_to_scene(int px, int py, double *x, double *y) {
static void input_output_to_scene(double px, double py, double *x, double *y) {
int w, h, ow, oh;
scene_size(&w, &h);
vkp_output_size(&ow, &oh);
if (ow <= 0 || oh <= 0 ||
!vkp_output_to_scene((double)px * ow / INPUT_SPACE_W, (double)py * oh / INPUT_SPACE_H, x, y)) {
*x = (double)px * w / INPUT_SPACE_W;
*y = (double)py * h / INPUT_SPACE_H;
!vkp_output_to_scene(px * ow / INPUT_SPACE_W, py * oh / INPUT_SPACE_H, x, y)) {
*x = px * w / INPUT_SPACE_W;
*y = py * h / INPUT_SPACE_H;
}
if (*x < 0) *x = 0;
if (*y < 0) *y = 0;
@@ -3476,6 +3487,57 @@ static void deliver_touch(const struct input_msg *m) {
publish_query_state();
}
static void pen_log_target(void) {
static struct wl_client *said;
for (int i = 0; i < g_nptrs; i++) {
if (!g_ptrs[i].focus) continue;
struct wl_client *client = wl_resource_get_client(g_ptrs[i].focus);
if (client != said && log_budget()) {
char name[160];
describe(wl_resource_get_user_data(g_ptrs[i].focus), name, sizeof(name));
droiddeck_log("pen", "%s gets the pen as the pointer", name);
}
said = client;
return;
}
}
static int pen_buttons(int flags) {
int held = 0;
if (flags & PEN_TIP) held |= PEN_BIT(BTN_LEFT);
if (flags & PEN_RIGHT) held |= PEN_BIT(BTN_RIGHT);
if (flags & PEN_MIDDLE) held |= PEN_BIT(BTN_MIDDLE);
return held;
}
static void pen_release(int buttons) {
for (uint32_t button = BTN_LEFT; button <= BTN_MIDDLE; button++)
if (buttons & PEN_BIT(button)) pointer_button(button, 0);
}
static void deliver_pen(const struct input_msg *m) {
if (!(m->p1 & PEN_IN)) {
pen_release(g_pen.buttons);
if (g_pen.in) g_raw_valid = 0;
memset(&g_pen, 0, sizeof(g_pen));
return;
}
int held = pen_buttons(m->p1);
if (!g_pen.in) g_raw_valid = 0;
g_pen.in = 1;
double x, y;
input_output_to_scene(m->p2 / 256.0, m->p3 / 256.0, &x, &y);
if (g_pen.buttons) g_grab = g_pen.grab;
if (!pointer_locked_for_cursor()) pointer_event(x, y, 0, 0);
for (uint32_t button = BTN_LEFT; button <= BTN_MIDDLE; button++)
if (held & ~g_pen.buttons & PEN_BIT(button)) pointer_button(button, 1);
g_pen.grab = g_grab;
pen_release(g_pen.buttons & ~held);
if (held) g_grab = g_pen.grab;
g_pen.buttons = held;
pen_log_target();
}
static void key_event(uint32_t evdev, int pressed);
struct wl_resource *droiddeck_ime_target(void);
static void deliver_key(const struct input_msg *m) {
@@ -3627,6 +3689,7 @@ static int on_input_readable(int fd, uint32_t mask, void *data) {
case 10: break;
case 11: axis_event(m.p1, m.p2, 0); break;
case 12: axis_event(m.p1, m.p2, 1); break;
case 13: deliver_pen(&m); break;
case 20: stream_take(); break;
case 21: if (!m.p1) stream_forget_all(); schedule_render(); break;
case 22: schedule_render(); break;
@@ -3666,6 +3729,13 @@ void droiddeck_wayland_send_touch(int action, int pointer_id, int x, int y) {
(void)n;
}
void droiddeck_wayland_send_pen(int flags, int x, int y) {
if (g_input_pipe[1] < 0) return;
struct input_msg m = { 13, flags, x, y, 0 };
ssize_t n = write(g_input_pipe[1], &m, sizeof(m));
(void)n;
}
void droiddeck_wayland_send_key(int evdev, int state) {
if (g_input_pipe[1] < 0) return;
struct input_msg m = { 1, evdev, state, 0, 0 };
@@ -24,6 +24,7 @@ extern int droiddeck_wayland_run(void);
extern void droiddeck_wayland_set_scale_mode(int mode, int alignment);
extern void droiddeck_wayland_send_pointer(int action, int x, int y);
extern void droiddeck_wayland_send_touch(int action, int pointer_id, int x, int y);
extern void droiddeck_wayland_send_pen(int flags, int x, int y);
extern int droiddeck_cursor_snapshot(int *out, int cap);
extern int droiddeck_cursor_serial(void);
extern int droiddeck_hud_frame_times(float *out, int len, int64_t *total);
@@ -280,6 +281,12 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSendTouch(
droiddeck_wayland_send_touch(action, pointer_id, x, y);
}
JNIEXPORT void JNICALL
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSendPen(
JNIEnv *env, jclass clazz, jint flags, jint x, jint y) {
droiddeck_wayland_send_pen(flags, x, y);
}
JNIEXPORT jint JNICALL
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeCursorSnapshot(
JNIEnv *env, jclass clazz, jintArray out) {
@@ -535,6 +535,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
private var upscaleSharpness by mutableStateOf(75)
private var hdrReason by mutableStateOf<String?>(null)
private var touchMode by mutableStateOf(SessionPrefs.TOUCH_AUTO)
private var pen by mutableStateOf<SessionPrefs.Pen?>(null)
private var suspendPolicy by mutableStateOf(SessionPrefs.SUSPEND_MANUAL)
private var steamDownloadsInBackground by mutableStateOf(false)
private var oscMode by mutableStateOf(SessionPrefs.OSC_AUTO)
@@ -2471,6 +2472,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
upscaler = upscaler, upscaleSharpness = upscaleSharpness,
gpuDrivers = drivers.summary(),
touchMode = touchMode,
pen = pen,
suspendPolicy = suspendPolicy,
steamDownloadsInBackground = steamDownloadsInBackground,
pipSupported = com.droiddeck.launcher.session.SessionPipController.supported(this),
@@ -2523,6 +2525,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
onUpscaler = { m -> SessionPrefs.setUpscaler(this, m); upscaler = m },
onUpscaleSharpness = { pct -> SessionPrefs.setUpscaleSharpness(this, pct); upscaleSharpness = pct },
onTouch = { t -> SessionPrefs.setTouchMode(this, t); touchMode = t },
onPen = { key, value -> SessionPrefs.setPenSetting(this, key, value); pen = SessionPrefs.pen(this) },
onSuspendPolicy = { policy -> SessionPrefs.setSuspendPolicy(this, mode, policy); suspendPolicy = policy },
onSteamDownloadsInBackground = { enabled ->
SessionPrefs.setSteamDownloadsInBackground(this, enabled)
@@ -2869,6 +2872,8 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
upscaleSharpness = SessionPrefs.upscaleSharpness(this)
hdrReason = com.droiddeck.launcher.wayland.HdrSupport.probe(this).reason
touchMode = SessionPrefs.touchMode(this)
if (!SessionPrefs.penSeen(this) && com.droiddeck.launcher.input.PenStream.penConnected()) SessionPrefs.setPenSeen(this)
pen = SessionPrefs.pen(this).takeIf { SessionPrefs.penSeen(this) }
suspendPolicy = SessionPrefs.suspendPolicy(this, mode)
steamDownloadsInBackground = SessionPrefs.steamDownloadsInBackground(this)
oscMode = SessionPrefs.oscMode(this)
@@ -97,8 +97,11 @@ import com.droiddeck.launcher.input.PadState
import com.droiddeck.launcher.input.SteamControllerBle
import com.droiddeck.launcher.input.DirectTouchHold
import com.droiddeck.launcher.input.GestureTouchStreamGate
import com.droiddeck.launcher.input.PenRouter
import com.droiddeck.launcher.input.PenStream
import com.droiddeck.launcher.input.PointerGestures
import com.droiddeck.launcher.input.PointerSpace
import com.droiddeck.launcher.input.pointerSubset
import com.droiddeck.launcher.input.SecondScreenDisplay
import com.droiddeck.launcher.input.SecondScreenDisplays
import com.droiddeck.launcher.input.SecondScreenMode
@@ -266,6 +269,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
private var steamTouchOptions: com.droiddeck.launcher.input.SteamTouchConfig.Options? = null
private var routedTouchMode = SessionPrefs.TOUCH_AUTO
private var touchRoute: com.droiddeck.launcher.input.TouchRouter.Route? = null
private var penSettings by mutableStateOf(SessionPrefs.Pen())
private var penSeen by mutableStateOf(false)
private var penRoute: PenRouter.Route? = null
private var penDown = false
private val penStream = PenStream(WaylandCompositor::nativeSendPen)
private var keyboard: KeyboardHost? = null
private var desktopKeyboardButton: com.droiddeck.launcher.input.DesktopKeyboardButton? = null
private var lastUserPressMs = 0L
@@ -667,6 +675,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
private val deviceListener = object : InputManager.InputDeviceListener {
override fun onInputDeviceAdded(deviceId: Int) {
logInputDevice("connected", deviceId)
if (!penSeen && InputDevice.getDevice(deviceId)?.let { PenStream.isPenDevice(it.sources) } == true) notePenSeen()
joyConVr?.refresh()
padBridge?.syncConnectedControllers()
refreshControls()
@@ -677,6 +686,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
}
override fun onInputDeviceRemoved(deviceId: Int) {
physicalShortcuts.onDeviceRemoved(deviceId)
penStream.deviceRemoved(deviceId)
Log.i(TAG, "input device $deviceId disconnected")
dropMouseCursor()
backQamInput.onDeviceRemoved(deviceId)
@@ -771,6 +781,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
uiHandler.postDelayed(::updatePointerCapture, 250)
}
}
override fun onResolvePointerIcon(event: MotionEvent, pointerIndex: Int): android.view.PointerIcon? =
if (platformPointerShown == false && PenStream.isPen(event, pointerIndex)) pointerIcon
else super.onResolvePointerIcon(event, pointerIndex)
}
sessionRoot = root
surfaceView = SurfaceView(this)
@@ -852,7 +865,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
refreshGestureConfig()
root.isMotionEventSplittingEnabled = true
surfaceView.setOnTouchListener { _, event ->
if (!event.isFromSource(InputDevice.SOURCE_TOUCHSCREEN)) {
if (!event.isFromSource(InputDevice.SOURCE_TOUCHSCREEN) && PenStream.penIndex(event) < 0) {
false
} else if (!gestureTouchStreamGate.accepts(GestureTouchStreamGate.Source.SURFACE, event)) {
false
@@ -1374,6 +1387,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
micEnabled = SessionState.micEnabled,
onMicEnabled = { SessionService.setMicEnabled(this@SessionActivity, it) },
touchAuto = getString(if (usingTouchpad()) R.string.session_touch_auto_touchpad else R.string.session_touch_auto_direct),
pen = penSettings.takeIf { penSeen },
onPen = { key, value -> SessionPrefs.setPenSetting(this@SessionActivity, key, value); readPrefs() },
fexPreset = fexPreset,
secondScreenMode = secondScreenMode,
secondScreenNone = !bottomOutputActive && !dockDrawer(),
@@ -2365,6 +2380,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
textureLodBias = SessionPrefs.textureLodBias(this)
val nextTouchMode = SessionPrefs.touchMode(this)
if (touchMode != nextTouchMode) {
cancelPen()
if (::touchpad.isInitialized) touchpad.cancel()
if (::directTouchHold.isInitialized) directTouchHold.cancel()
if (::twoFingerGestures.isInitialized) twoFingerGestures.cancel()
@@ -2378,6 +2394,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
if (nextTouchMode == SessionPrefs.TOUCH_OFF || !usingTouchpad()) cursorVisible = false
}
touchMode = nextTouchMode
val nextPen = SessionPrefs.pen(this)
if (penSettings != nextPen) cancelPen()
penSettings = nextPen
penStream.sideButton = nextPen.button
if (!penSeen && (SessionPrefs.penSeen(this) || PenStream.penConnected())) notePenSeen()
val nextRoutedTouchMode = effectiveTouchMode()
if (routedTouchMode != nextRoutedTouchMode) gestureTouchStreamGate.reset()
routedTouchMode = nextRoutedTouchMode
@@ -2753,9 +2774,20 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
if (::directTouchHold.isInitialized) directTouchHold.cancel()
if (::twoFingerGestures.isInitialized) twoFingerGestures.cancel()
if (::scrollTouch.isInitialized) scrollTouch.cancel()
if (sessionTouchDown || penDown) dismissTouch = true
cancelPen()
scrollTouchGesture = false
gesturePointerReady = false
if (sessionTouchDown) dismissTouch = true
}
private fun cancelPen(releaseKey: Boolean = false) {
penStream.cancel(releaseKey)
penDown = false
}
private fun notePenSeen() {
penSeen = true
SessionPrefs.setPenSeen(this)
}
private fun panelBounds(): android.graphics.Rect = if (Build.VERSION.SDK_INT >= 30) {
@@ -3219,6 +3251,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
return super.dispatchKeyEvent(event)
}
}
if (penStream.holdsKey(event) || (penSettings.mode != SessionPrefs.PEN_TOUCH && PenStream.isPenKey(event))) return penStream.onKey(event)
if (appTextFocus) return super.dispatchKeyEvent(event)
if (!pipUi) {
if (physicalInputBindings?.onKey(event, resumed && !drawerOpen && !pcKeyboardOpen && !achievementsOpen &&
@@ -3404,6 +3437,19 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
if (joyConVr?.onMotionEvent(event) == true) return true
if (PadBridge.isControllerMotionEvent(event) && padMouseMode() && padMouse.onMotion(event)) return true
if (padBridge?.onMotionEvent(event) == true) return true
val pen = PenStream.penIndex(event)
if (pen >= 0) when (routePen(event, pen)) {
PenRouter.Route.TOUCH -> {}
PenRouter.Route.PEN -> {
if (!appUiOwnsPointer()) return penSample(event, pen) || super.dispatchGenericMotionEvent(event)
if (super.dispatchGenericMotionEvent(event)) {
penStream.cancel()
return true
}
return !touchEditorOpen && penSample(event, pen)
}
else -> return super.dispatchGenericMotionEvent(event)
}
if (event.isFromSource(android.view.InputDevice.SOURCE_MOUSE) && !drawerOpen) {
if (appUiOwnsPointer()) {
if (super.dispatchGenericMotionEvent(event)) return true
@@ -3438,7 +3484,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
override fun dispatchTouchEvent(event: MotionEvent): Boolean {
if (pipUi) return true
notePress(event)
if (event.actionMasked == MotionEvent.ACTION_DOWN && event.isFromSource(InputDevice.SOURCE_TOUCHSCREEN)) {
if (event.actionMasked == MotionEvent.ACTION_DOWN &&
(event.isFromSource(InputDevice.SOURCE_TOUCHSCREEN) || PenStream.penIndex(event) >= 0)) {
drawerControllerActive = false
gestureTouchStreamGate.reset()
}
@@ -4440,6 +4487,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
}
if (next == routedTouchMode) return
if (::touchscreenGestures.isInitialized) touchscreenGestures.cancel()
cancelPen()
gesturePointerReady = false
if (::touchpad.isInitialized) touchpad.cancel()
if (::directTouchHold.isInitialized) directTouchHold.cancel()
@@ -4608,7 +4656,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
private var sessionTouchDown = false
override fun onTouchEvent(event: MotionEvent): Boolean {
if (event.isFromSource(android.view.InputDevice.SOURCE_MOUSE)) return onMouse(event)
val pen = PenStream.penIndex(event)
val penRouted = if (pen >= 0) routePen(event, pen).takeIf { it != PenRouter.Route.TOUCH } else null
if (penRouted == null && event.isFromSource(android.view.InputDevice.SOURCE_MOUSE)) return onMouse(event)
when (event.actionMasked) {
MotionEvent.ACTION_DOWN -> {
sessionTouchDown = true
@@ -4627,19 +4677,14 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) dismissTouch = false
return true
}
val uiBlocking = drawerOpen || achievementsOpen || gestureSettingsOpen || inputSettingsOpen || pipUi || SessionState.suspended
if (penRouted != null) return onPenTouch(event, pen, penRouted)
val uiBlocking = uiBlocksTouch()
if (event.actionMasked == MotionEvent.ACTION_DOWN && !uiBlocking && routedTouchMode != SessionPrefs.TOUCH_GESTURES) {
scrollTouchGesture = scrollTouchMode()
scrollRestX = 0f
scrollRestY = 0f
}
val snapshot = com.droiddeck.launcher.input.TouchRouter.Snapshot(
uiBlocking = uiBlocking,
mode = routedTouchMode,
scrollLayer = scrollTouchGesture,
steamSession = SessionState.mode == SessionService.MODE_STEAM,
steamDesktopUi = SessionState.steamUi == "desktop",
)
val snapshot = fingerTouchSnapshot(uiBlocking)
val route = com.droiddeck.launcher.input.TouchRouter.decide(snapshot)
if (route != touchRoute) {
Log.i(TAG, "touch route $touchRoute -> $route (mode=$routedTouchMode steamUi=${SessionState.steamUi} scrollLayer=$scrollTouchGesture)")
@@ -4667,17 +4712,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
if (threeFingerTap.active || wasActive) return true
}
if (route == com.droiddeck.launcher.input.TouchRouter.Route.TOUCHPAD) {
val rect = (if (pointerLocked) drawnRect() else pointerSurfaceRect()) ?: return false
if (touchpad.bounds != rect) {
val fresh = touchpad.bounds.width() <= 1f
touchpad.bounds = rect
if (fresh) touchpad.place(rect.centerX(), rect.centerY())
}
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
touchpad.desktop = SessionState.mode == SessionService.MODE_DESKTOP
placeTouchpadAtGuest(rect)
}
touchpad.onTouch(event)
touchpadTouch(event)
} else {
dispatchDirectTouch(event)
}
@@ -4685,6 +4720,92 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
}
}
private fun uiBlocksTouch(): Boolean =
drawerOpen || achievementsOpen || gestureSettingsOpen || inputSettingsOpen || pipUi || SessionState.suspended
private fun fingerTouchSnapshot(uiBlocking: Boolean) = com.droiddeck.launcher.input.TouchRouter.Snapshot(
uiBlocking = uiBlocking,
mode = routedTouchMode,
scrollLayer = scrollTouchGesture,
steamSession = SessionState.mode == SessionService.MODE_STEAM,
steamDesktopUi = SessionState.steamUi == "desktop",
)
private fun touchpadTouch(event: MotionEvent): Boolean {
val rect = (if (pointerLocked) drawnRect() else pointerSurfaceRect()) ?: return false
if (touchpad.bounds != rect) {
val fresh = touchpad.bounds.width() <= 1f
touchpad.bounds = rect
if (fresh) touchpad.place(rect.centerX(), rect.centerY())
}
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
touchpad.desktop = SessionState.mode == SessionService.MODE_DESKTOP
placeTouchpadAtGuest(rect)
}
return touchpad.onTouch(event)
}
private fun routePen(event: MotionEvent, pen: Int): PenRouter.Route {
if (!penSeen) notePenSeen()
val action = event.actionMasked
if (action == MotionEvent.ACTION_HOVER_ENTER || action == MotionEvent.ACTION_HOVER_MOVE || action == MotionEvent.ACTION_HOVER_EXIT) penDown = false
val own = PenStream.isPenAction(event, pen)
val starts = own && (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_POINTER_DOWN)
val route = penRoute.takeIf { penDown && !starts } ?: decidePen()
if (own) penDown = starts
return route
}
private fun decidePen(): PenRouter.Route {
val mode = penSettings.mode
val route = PenRouter.decide(uiBlocksTouch(), mode, glassesOutputActive, programLocksPointer())
if (route != penRoute) {
if (penRoute == PenRouter.Route.PEN) penStream.cancel()
Log.i(TAG, "pen route $penRoute -> $route (mode=$mode)")
penRoute = route
}
return route
}
private fun onPenTouch(event: MotionEvent, pen: Int, route: PenRouter.Route): Boolean {
if (route == PenRouter.Route.RELATIVE && event.pointerCount > 1 &&
com.droiddeck.launcher.input.TouchRouter.decide(fingerTouchSnapshot(uiBlocksTouch())) ==
com.droiddeck.launcher.input.TouchRouter.Route.TOUCHPAD) {
touchpadTouch(event)
return true
}
if (event.pointerCount > 1) {
var fingers = 0
for (index in 0 until event.pointerCount) if (!PenStream.isPen(event, index)) fingers = fingers or (1 shl event.getPointerId(index))
event.pointerSubset(fingers)?.let { split -> try { onTouchEvent(split) } finally { split.recycle() } }
}
when (route) {
PenRouter.Route.PEN -> penSample(event, pen)
PenRouter.Route.RELATIVE -> {
val split = if (event.pointerCount == 1) MotionEvent.obtain(event) else event.pointerSubset(1 shl event.getPointerId(pen))
split?.let {
try {
if (it.actionMasked == MotionEvent.ACTION_UP && it.flags and MotionEvent.FLAG_CANCELED != 0) it.action = MotionEvent.ACTION_CANCEL
touchpadTouch(it)
} finally { it.recycle() }
}
}
else -> {}
}
return true
}
private fun penSample(event: MotionEvent, pen: Int): Boolean {
val area = pointerSurfaceRect() ?: return false
val view = outputView()
if (!penStream.onMotion(event, pen, area, view.width, view.height)) return false
if (penStream.inProximity) {
if (pointerLocked) releaseDesktopMouseGrab()
showCursor(event.getX(pen).coerceIn(area.left, area.right), event.getY(pen).coerceIn(area.top, area.bottom), fromMouse = true)
}
return true
}
private val directTouchSink = object : DirectTouchHold.Touch {
override fun down(pointerId: Int, x: Float, y: Float) = sendDirectTouch(0, pointerId, x, y)
override fun move(pointerId: Int, x: Float, y: Float) = sendDirectTouch(1, pointerId, x, y)
@@ -4770,7 +4891,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
}
private fun isHardwareMouse(d: InputDevice?): Boolean =
d != null && !d.isVirtual && (d.supportsSource(InputDevice.SOURCE_MOUSE) || d.supportsSource(InputDevice.SOURCE_MOUSE_RELATIVE))
d != null && !d.isVirtual && !d.supportsSource(InputDevice.SOURCE_STYLUS) &&
(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) {
@@ -4809,7 +4931,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
pointerLocked && SessionState.mode != SessionService.MODE_DESKTOP
private fun desktopMouseGrabAllowed(): Boolean =
SessionState.mode == SessionService.MODE_DESKTOP && relativeMouseAttached() && !bottomOutputActive
SessionState.mode == SessionService.MODE_DESKTOP && !penStream.inProximity && relativeMouseAttached() && !bottomOutputActive
private fun tapDesktopGrabKey() {
val now = android.os.SystemClock.uptimeMillis()
@@ -5104,6 +5226,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
private fun releaseHeldGuestInput() {
mouseBackInput.cancel()
cancelPen(releaseKey = true)
heldButtons.release(1 or 2 or 8 or 16)
guestKeysDown.toList().forEach { sendGuestKey(it, false) }
heldKeys.release(8 or 16 or 32)
@@ -5195,6 +5318,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
scrollTouch.cancel()
directTouchHold.cancel()
twoFingerGestures.cancel()
cancelPen()
guestKeysDown.toList().forEach { sendGuestKey(it, false) }
heldKeys.clear()
heldButtons.clear()
@@ -5391,6 +5515,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
if (::touchpad.isInitialized) touchpad.cancel()
if (::directTouchHold.isInitialized) directTouchHold.cancel()
if (::twoFingerGestures.isInitialized) twoFingerGestures.cancel()
cancelPen(releaseKey = true)
uiHandler.removeCallbacks(clearRecognizedGesture)
uiHandler.removeCallbacks(cursorResync)
val screenOff = screenIsOff()
@@ -5697,7 +5822,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
}
if (shown != null) {
closeSecondScreen(reset = false)
val screen = com.droiddeck.launcher.ui.BottomGameScreen(this, shown, this, ::onBottomGameTouch)
val screen = com.droiddeck.launcher.ui.BottomGameScreen(this, shown, this, ::onBottomGameTouch, ::onBottomGameHover)
bottomGame = screen
surfaceW = 0
surfaceH = 0
@@ -5749,9 +5874,23 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
if (surfaceView.holder.surface?.isValid == true) surfaceCreated(surfaceView.holder)
}
private fun onBottomGameHover(event: MotionEvent): Boolean {
val pen = PenStream.penIndex(event)
if (pipUi || pen < 0) return false
return when (routePen(event, pen)) {
PenRouter.Route.TOUCH -> false
PenRouter.Route.PEN -> {
notePress(event)
penSample(event, pen)
true
}
else -> true
}
}
private fun onBottomGameTouch(event: MotionEvent): Boolean {
if (pipUi) return true
if (!event.isFromSource(InputDevice.SOURCE_TOUCHSCREEN)) return false
if (!event.isFromSource(InputDevice.SOURCE_TOUCHSCREEN) && PenStream.penIndex(event) < 0) return false
notePress(event)
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
drawerControllerActive = false
@@ -6052,6 +6191,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
padBridge?.stop()
DeckControls.clearRouter(inputRouter)
inputRouter = null
cancelPen()
heldKeys.clear()
heldButtons.clear()
steamController?.stop()
@@ -296,6 +296,8 @@ object DeviceReport {
k("Microphone", SessionPrefs.micEnabled(context))
k("On-screen controls", SessionPrefs.oscMode(context))
k("Touch mode", SessionPrefs.touchMode(context))
k("Pen mode", SessionPrefs.penMode(context))
k("Pen side button", SessionPrefs.penButton(context))
k("Performance HUD", SessionPrefs.hudEnabled(context))
k("Game storage", when (val g = SessionPrefs.gameStorage(context)) {
"" -> "automatic (" + (com.droiddeck.launcher.session.GameStorage.effective(context)?.path ?: "no card present") + ")"
@@ -3,11 +3,16 @@ package com.droiddeck.launcher.input
object InputSpace {
const val WIDTH = 1920
const val HEIGHT = 1080
const val FIXED_ONE = 256
fun x(position: Float, viewWidth: Int): Int = scale(position, viewWidth, WIDTH)
fun y(position: Float, viewHeight: Int): Int = scale(position, viewHeight, HEIGHT)
fun fixedX(position: Float, viewWidth: Int): Int = scale(position, viewWidth, WIDTH * FIXED_ONE)
fun fixedY(position: Float, viewHeight: Int): Int = scale(position, viewHeight, HEIGHT * FIXED_ONE)
private fun scale(position: Float, extent: Int, size: Int): Int =
if (extent <= 0) 0 else (position / extent * size).toInt().coerceIn(0, size - 1)
}
@@ -0,0 +1,14 @@
package com.droiddeck.launcher.input
import com.droiddeck.launcher.session.SessionPrefs
object PenRouter {
enum class Route { BLOCKED, PEN, RELATIVE, TOUCH }
fun decide(uiBlocking: Boolean, mode: String, glasses: Boolean, programLock: Boolean): Route = when {
uiBlocking -> Route.BLOCKED
mode == SessionPrefs.PEN_TOUCH -> Route.TOUCH
glasses || programLock -> Route.RELATIVE
else -> Route.PEN
}
}
@@ -0,0 +1,247 @@
package com.droiddeck.launcher.input
import android.graphics.RectF
import android.os.Build
import android.os.Handler
import android.os.Looper
import android.os.SystemClock
import android.view.InputDevice
import android.view.KeyEvent
import android.view.MotionEvent
import com.droiddeck.launcher.session.SessionPrefs
class PenStream(private val sink: Sink) {
fun interface Sink {
fun sample(flags: Int, x: Int, y: Int)
}
private val handler = Handler(Looper.getMainLooper())
private val exitLater = Runnable { if (exitPending) leave() }
private val hoverWatchdog = Runnable { checkHover() }
private var watching = false
private var contact = false
private var barrel = 0
private var keyDown = false
private var keyDevice = Int.MIN_VALUE
private var keyCode = 0
private var exitPending = false
private var exitTime = 0L
private var deviceId = Int.MIN_VALUE
private var x = 0
private var y = 0
private var sampleTime = 0L
var sideButton = SessionPrefs.PEN_BUTTON_RIGHT
var inProximity = false
private set
fun onMotion(event: MotionEvent, pointer: Int, area: RectF, width: Int, height: Int): Boolean {
val action = event.actionMasked
val time = event.eventTime
val own = isPenAction(event, pointer)
expire(time)
when (action) {
MotionEvent.ACTION_HOVER_ENTER, MotionEvent.ACTION_HOVER_MOVE -> {
continueAt(time)
contact = false
enter(event)
samples(event, pointer, area, width, height)
}
MotionEvent.ACTION_HOVER_EXIT -> if (inProximity && !exitPending && !contact) pendExit(time)
MotionEvent.ACTION_BUTTON_PRESS, MotionEvent.ACTION_BUTTON_RELEASE -> {
continueAt(time)
if (!inProximity) return true
barrel = event.buttonState
samples(event, pointer, area, width, height)
}
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_POINTER_DOWN -> if (own) {
continueAt(time)
enter(event)
contact = true
samples(event, pointer, area, width, height)
} else if (contact) samples(event, pointer, area, width, height)
MotionEvent.ACTION_MOVE -> if (contact) {
barrel = event.buttonState
samples(event, pointer, area, width, height)
}
MotionEvent.ACTION_UP, MotionEvent.ACTION_POINTER_UP -> if (!own) {
if (contact) samples(event, pointer, area, width, height)
} else if (contact) {
if (event.flags and MotionEvent.FLAG_CANCELED != 0) cancel()
else {
barrel = event.buttonState
samples(event, pointer, area, width, height, lift = true)
pendExit(time)
}
}
MotionEvent.ACTION_CANCEL -> cancel()
else -> return false
}
return true
}
fun onKey(event: KeyEvent): Boolean {
expire(event.eventTime)
val down = event.action == KeyEvent.ACTION_DOWN
val repeat = event.repeatCount > 0
if (exitPending && !repeat) leave()
if (!inProximity || exitPending) {
if (!repeat && event.deviceId == keyDevice && event.keyCode == keyCode) keyDown = down
return true
}
if (down == keyDown) return true
val before = state()
keyDown = down
if (down) {
keyDevice = event.deviceId
keyCode = event.keyCode
}
if (state() == before) return true
emit(state())
return true
}
fun cancel(releaseKey: Boolean = false) {
if (releaseKey) keyDown = false
leave()
}
fun holdsKey(event: KeyEvent): Boolean = keyDown && event.deviceId == keyDevice && event.keyCode == keyCode
fun deviceRemoved(deviceId: Int) {
if (deviceId == this.deviceId) cancel()
if (!keyDown || deviceId != keyDevice) return
val before = state()
keyDown = false
if (inProximity && state() != before) emit(state())
}
private fun enter(event: MotionEvent) {
barrel = event.buttonState
if (inProximity) return
inProximity = true
deviceId = event.deviceId
}
private fun continueAt(time: Long) {
if (!exitPending) return
if (time - exitTime > EXIT_GRACE_MS) { leave(); return }
exitPending = false
handler.removeCallbacks(exitLater)
}
private fun pendExit(time: Long) {
exitPending = true
exitTime = time
handler.removeCallbacks(exitLater)
handler.postDelayed(exitLater, EXIT_GRACE_MS)
}
private fun expire(time: Long) {
if (inProximity && !contact && time - sampleTime >= HOVER_TIMEOUT_MS) leave()
}
private fun watchHover(delay: Long = HOVER_TIMEOUT_MS) {
if (watching || contact) return
watching = true
handler.postDelayed(hoverWatchdog, delay)
}
private fun checkHover() {
watching = false
if (!inProximity || contact || exitPending) return
val silent = SystemClock.uptimeMillis() - sampleTime
if (silent >= HOVER_TIMEOUT_MS) leave() else watchHover(HOVER_TIMEOUT_MS - silent)
}
private fun leave() {
if (!inProximity) return
emit(0)
handler.removeCallbacks(exitLater)
handler.removeCallbacks(hoverWatchdog)
watching = false
inProximity = false
contact = false
exitPending = false
barrel = 0
}
private fun samples(event: MotionEvent, pointer: Int, area: RectF, width: Int, height: Int, lift: Boolean = false) {
for (h in 0 until event.historySize) sample(event, pointer, h, area, width, height)
if (lift) contact = false
sample(event, pointer, -1, area, width, height)
}
private fun sample(event: MotionEvent, pointer: Int, h: Int, area: RectF, width: Int, height: Int) {
x = InputSpace.fixedX(event.axis(MotionEvent.AXIS_X, pointer, h).coerceIn(area.left, area.right), width)
y = InputSpace.fixedY(event.axis(MotionEvent.AXIS_Y, pointer, h).coerceIn(area.top, area.bottom), height)
sampleTime = if (h < 0) event.eventTime else event.getHistoricalEventTime(h)
emit(state())
watchHover()
}
private fun emit(flags: Int) = sink.sample(flags, x, y)
private fun state(): Int =
PEN_IN or (if (contact) PEN_TIP else 0) or buttonFlags(keyDown || barrel and MotionEvent.BUTTON_STYLUS_PRIMARY != 0,
barrel and MotionEvent.BUTTON_STYLUS_SECONDARY != 0, sideButton)
private fun MotionEvent.axis(axis: Int, pointer: Int, h: Int): Float =
if (h < 0) getAxisValue(axis, pointer) else getHistoricalAxisValue(axis, pointer, h)
companion object {
const val PEN_IN = 1 shl 0
const val PEN_TIP = 1 shl 1
const val PEN_RIGHT = 1 shl 2
const val PEN_MIDDLE = 1 shl 3
const val HOVER_TIMEOUT_MS = 2_000L
const val EXIT_GRACE_MS = 50L
private val PEN_NAME = Regex("\\b(pen|stylus)", RegexOption.IGNORE_CASE)
fun isPen(event: MotionEvent, index: Int): Boolean = when (event.getToolType(index)) {
MotionEvent.TOOL_TYPE_STYLUS, MotionEvent.TOOL_TYPE_ERASER -> true
MotionEvent.TOOL_TYPE_UNKNOWN -> event.isFromSource(InputDevice.SOURCE_STYLUS)
else -> false
}
fun penConnected(): Boolean =
InputDevice.getDeviceIds().any { id -> InputDevice.getDevice(id)?.let { isPenDevice(it.sources) } == true }
// Before Android 14 a touchscreen that declares ABS_MT_TOOL_TYPE reports SOURCE_STYLUS without any pen.
fun isPenDevice(sources: Int, sdk: Int = Build.VERSION.SDK_INT): Boolean =
sources and InputDevice.SOURCE_STYLUS == InputDevice.SOURCE_STYLUS &&
(sources and InputDevice.SOURCE_TOUCHSCREEN != InputDevice.SOURCE_TOUCHSCREEN || sdk >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
fun penIndex(event: MotionEvent): Int {
for (index in 0 until event.pointerCount) if (isPen(event, index)) return index
return -1
}
fun isPenAction(event: MotionEvent, index: Int): Boolean = when (event.actionMasked) {
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> true
MotionEvent.ACTION_POINTER_DOWN, MotionEvent.ACTION_POINTER_UP -> event.actionIndex == index
else -> false
}
fun isPenKey(event: KeyEvent): Boolean {
val device = event.device ?: return false
return isPenKeyboard(device.name, device.sources, Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || device.isExternal,
device.keyboardType == InputDevice.KEYBOARD_TYPE_ALPHABETIC)
}
fun isPenKeyboard(name: String?, sources: Int, external: Boolean, alphabetic: Boolean): Boolean =
external && !alphabetic && sources == InputDevice.SOURCE_KEYBOARD && name != null && PEN_NAME.containsMatchIn(name)
fun buttonFlags(primary: Boolean, secondary: Boolean, sideButton: String): Int {
val first = when (sideButton) {
SessionPrefs.PEN_BUTTON_RIGHT -> PEN_RIGHT
SessionPrefs.PEN_BUTTON_MIDDLE -> PEN_MIDDLE
else -> 0
}
val second = if (sideButton == SessionPrefs.PEN_BUTTON_RIGHT) PEN_MIDDLE else PEN_RIGHT
return (if (primary) first else 0) or (if (secondary) second else 0)
}
}
}
@@ -23,13 +23,20 @@ internal fun MotionEvent.pointerSubset(pointerIdBits: Int): MotionEvent? {
}
val properties = Array(indices.size) { MotionEvent.PointerProperties() }
val coordinates = Array(indices.size) { MotionEvent.PointerCoords() }
indices.forEachIndexed { target, index ->
getPointerProperties(index, properties[target])
getPointerCoords(index, coordinates[target])
indices.forEachIndexed { target, index -> getPointerProperties(index, properties[target]) }
fun sample(position: Int): Array<MotionEvent.PointerCoords> {
indices.forEachIndexed { target, index ->
if (position < historySize) getHistoricalPointerCoords(index, position, coordinates[target])
else getPointerCoords(index, coordinates[target])
}
return coordinates
}
return MotionEvent.obtain(
downTime, eventTime, splitAction, indices.size, properties, coordinates,
fun time(position: Int) = if (position < historySize) getHistoricalEventTime(position) else eventTime
val split = MotionEvent.obtain(
downTime, time(0), splitAction, indices.size, properties, sample(0),
metaState, buttonState, xPrecision, yPrecision,
deviceId, edgeFlags, source, flags,
)
for (position in 1..historySize) split.addBatch(time(position), sample(position), metaState)
return split
}
@@ -516,6 +516,38 @@ object SessionPrefs {
prefs(context).edit().putString("touch", mode).apply()
}
const val PEN_MOUSE = "mouse"
const val PEN_TOUCH = "touch"
const val PEN_BUTTON_RIGHT = "right"
const val PEN_BUTTON_MIDDLE = "middle"
const val PEN_BUTTON_OFF = "off"
data class Pen(val mode: String = PEN_MOUSE, val button: String = PEN_BUTTON_RIGHT)
private val PEN_SETTINGS = mapOf(
"pen" to setOf(PEN_MOUSE, PEN_TOUCH),
"penButton" to setOf(PEN_BUTTON_RIGHT, PEN_BUTTON_MIDDLE, PEN_BUTTON_OFF),
)
private fun penSetting(context: Context, key: String, default: String): String =
prefs(context).getString(key, default)?.takeIf { it in PEN_SETTINGS.getValue(key) } ?: default
fun setPenSetting(context: Context, key: String, value: String) {
require(value in PEN_SETTINGS.getValue(key))
prefs(context).edit().putString(key, value).apply()
}
fun penMode(context: Context): String = penSetting(context, "pen", PEN_MOUSE)
fun penButton(context: Context): String = penSetting(context, "penButton", PEN_BUTTON_RIGHT)
fun pen(context: Context): Pen = Pen(penMode(context), penButton(context))
fun penSeen(context: Context): Boolean = prefs(context).getBoolean("penSeen", false)
fun setPenSeen(context: Context) {
if (!penSeen(context)) prefs(context).edit().putBoolean("penSeen", true).apply()
}
const val SHAPE_AUTO = "auto"
const val SHAPE_WIDE = "16:9"
const val SHAPE_EXACT = "exact"
@@ -16,7 +16,7 @@ object SettingsReset {
"dualScreenMode", "dualScreenSessionMode", "dualScreenLauncher", "dualScreenSessionControls", "androidTextFieldKeyboard",
"gameStoresEnabled", "soundtracksEnabled", "soundtracksIngame", "gameStoresSpeedTier", "gameStoresParallel", "storesOpenTab", "storesShowMature",
"storesInstallLanguage",
"hud", "hudDeck", "hudFps", "hudBattery", "hudGraph", "hudColor", "hudOpacity", "__KEEP_droidDeckHud__", "__KEEP_droidDeckHudPos__", "backHold", "backActionsInverted", "backDoubleTapMs", "touch", "osc", "shape", "steamController",
"hud", "hudDeck", "hudFps", "hudBattery", "hudGraph", "hudColor", "hudOpacity", "__KEEP_droidDeckHud__", "__KEEP_droidDeckHudPos__", "backHold", "backActionsInverted", "backDoubleTapMs", "touch", "pen", "penButton", "osc", "shape", "steamController",
"gamepadLeft", "gamepadRight", "pipAutoEnter", "unfoldedControls", "unfoldedControlsWithController",
"stretch16x9", "picturePosition", "railLabels", "agentTab", "navTabOrder", "navTabShelved", "navTabHidden", "pcKeyboardSize", "pcKeyboardOpacity", "pcKeyboardHiddenKeys",
"gpuDriverMode", "androidDriver", "linuxDriver", "linuxDriver.steam", "linuxDriver.desktop",
@@ -19,6 +19,7 @@ class BottomGameScreen(
display: Display,
private val callback: SurfaceHolder.Callback,
private val onTouch: (MotionEvent) -> Boolean,
private val onHover: (MotionEvent) -> Boolean,
) : Presentation(activity, display) {
val surfaceView = SurfaceView(getContext())
val holder: SurfaceHolder get() = surfaceView.holder
@@ -51,7 +52,7 @@ class BottomGameScreen(
activity.dispatchKeyEvent(event) || super.dispatchKeyEvent(event)
override fun dispatchGenericMotionEvent(event: MotionEvent): Boolean =
activity.dispatchGenericMotionEvent(event) || super.dispatchGenericMotionEvent(event)
onHover(event) || activity.dispatchGenericMotionEvent(event) || super.dispatchGenericMotionEvent(event)
}
object GameScreenSwap {
@@ -63,6 +63,7 @@ class ModeSettings(
val upscaler: Int = 0,
val upscaleSharpness: Int = 75,
val touchMode: String,
val pen: SessionPrefs.Pen? = null,
val suspendPolicy: String,
val steamDownloadsInBackground: Boolean = false,
val pipSupported: Boolean = false,
@@ -116,6 +117,7 @@ class ModeSettingsActions(
val onUpscaler: (Int) -> Unit = {},
val onUpscaleSharpness: (Int) -> Unit = {},
val onTouch: (String) -> Unit,
val onPen: (key: String, value: String) -> Unit = { _, _ -> },
val onSuspendPolicy: (String) -> Unit,
val onSteamDownloadsInBackground: (Boolean) -> Unit = {},
val onPipAutoEnter: (Boolean) -> Unit = {},
@@ -321,6 +323,7 @@ fun ModeSheetRows(s: ModeSettings, a: ModeSettingsActions, tab: String, extras:
}
PhysicalShortcutRows()
}
s.pen?.let { PenSettingsGroup(host, it, onPick = a.onPen) }
}
if (tab == SheetTab.AUDIO && steam) {
if (s.directAudio != null && s.mic != null) SettingsGroup(stringResource(R.string.mode_audio)) {
@@ -0,0 +1,25 @@
package com.droiddeck.launcher.ui
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.droiddeck.launcher.R
import com.droiddeck.launcher.session.SessionPrefs
@Composable
internal fun PenSettingsGroup(
host: MenuHost, pen: SessionPrefs.Pen, track: (String) -> Modifier = { Modifier },
onPick: (key: String, value: String) -> Unit,
) {
SettingsGroup(stringResource(R.string.mode_pen)) {
ChoiceRow(host, "pen", stringResource(R.string.mode_pen), null,
listOf(SessionPrefs.PEN_MOUSE to stringResource(R.string.mode_pen_mouse),
SessionPrefs.PEN_TOUCH to stringResource(R.string.mode_pen_touch)),
pen.mode, chipModifier = track("pen")) { onPick("pen", it) }
if (pen.mode != SessionPrefs.PEN_TOUCH) ChoiceRow(host, "pen-button", stringResource(R.string.mode_pen_button), null,
listOf(SessionPrefs.PEN_BUTTON_RIGHT to stringResource(R.string.gesture_right_click),
SessionPrefs.PEN_BUTTON_MIDDLE to stringResource(R.string.gesture_middle_click),
SessionPrefs.PEN_BUTTON_OFF to stringResource(R.string.widgets_off)),
pen.button, chipModifier = track("pen-button")) { onPick("penButton", it) }
}
}
@@ -239,6 +239,8 @@ class DrawerActions(
val onPadType: (String) -> Unit = {},
val touchMode: String,
val touchAuto: String,
val pen: SessionPrefs.Pen? = null,
val onPen: (key: String, value: String) -> Unit = { _, _ -> },
val fexPreset: String,
val upscaler: Int = 0,
val upscaleSharpness: Int = 75,
@@ -672,6 +674,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
onPick = a.onDirectHoldBehavior)
}
}
a.pen?.let { PenSettingsGroup(host, it, track = { key -> focus.track(page, key) }, onPick = a.onPen) }
SettingsGroup(stringResource(R.string.input_screen_visibility)) {
ChoiceRow(host, "osc", stringResource(R.string.mode_osc), null,
if (a.steam) listOf(SessionPrefs.OSC_AUTO to stringResource(R.string.common_auto), SessionPrefs.OSC_ALWAYS to stringResource(R.string.common_always), SessionPrefs.OSC_STEAM_TOUCH to stringResource(R.string.osc_steam_touch), SessionPrefs.OSC_STEAM_QAM to stringResource(R.string.mode_osc_qam), SessionPrefs.OSC_NEVER to stringResource(R.string.common_never))
@@ -162,6 +162,8 @@ public final class WaylandCompositor {
public static native void nativeSendTouch(int action, int pointerId, int x, int y);
public static native void nativeSendPen(int flags, int x, int y);
public static native int nativeCursorSnapshot(int[] out);
public static native int nativeCursorSerial();
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">لوحة اللمس</string>
<string name="mode_touch_direct">مباشر</string>
<string name="mode_touch_note">تلقائي: لوحة لمس على سطح المكتب، ولمس مباشر في Steam.</string>
<string name="mode_pen">القلم</string>
<string name="mode_pen_mouse">الفأرة</string>
<string name="mode_pen_touch">اللمس</string>
<string name="mode_pen_button">الزر الجانبي</string>
<string name="mode_osc">عناصر التحكم على الشاشة</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">يعرض الخيار «تلقائي» عناصر التحكم عند عدم توصيل وحدة تحكم.</string>
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Touchpad</string>
<string name="mode_touch_direct">Directo</string>
<string name="mode_touch_note">Auto: touchpad en Escritorio, directo en Steam.</string>
<string name="mode_pen">Lápiz</string>
<string name="mode_pen_mouse">Ratón</string>
<string name="mode_pen_touch">Táctil</string>
<string name="mode_pen_button">Botón lateral</string>
<string name="mode_osc">Controles en pantalla</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">Auto muestra los controles en pantalla cuando no hay ningún control conectado.</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Тъчпад</string>
<string name="mode_touch_direct">Директно</string>
<string name="mode_touch_note">Автоматично: тъчпад на работния плот, директно в Steam.</string>
<string name="mode_pen">Писалка</string>
<string name="mode_pen_mouse">Мишка</string>
<string name="mode_pen_touch">Докосване</string>
<string name="mode_pen_button">Страничен бутон</string>
<string name="mode_osc">Екранни контроли</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">Автоматично показва контролите, когато няма свързан контролер.</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Touchpad</string>
<string name="mode_touch_direct">Přímé</string>
<string name="mode_touch_note">Automaticky: touchpad na Ploše, přímo ve Steamu.</string>
<string name="mode_pen">Pero</string>
<string name="mode_pen_mouse">Myš</string>
<string name="mode_pen_touch">Dotyk</string>
<string name="mode_pen_button">Boční tlačítko</string>
<string name="mode_osc">Ovládání na obrazovce</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">Automaticky zobrazí ovládání, pokud není připojen žádný ovladač.</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Touchpad</string>
<string name="mode_touch_direct">Direkte</string>
<string name="mode_touch_note">Auto: touchpad på Skrivebord, direkte i Steam.</string>
<string name="mode_pen">Pen</string>
<string name="mode_pen_mouse">Mus</string>
<string name="mode_pen_touch">Berøring</string>
<string name="mode_pen_button">Sideknap</string>
<string name="mode_osc">Kontroller på skærmen</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">Auto viser kontrollerne, når ingen controller er tilsluttet.</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Touchpad</string>
<string name="mode_touch_direct">Direkt</string>
<string name="mode_touch_note">Auto: Touchpad auf dem Desktop, direkt in Steam.</string>
<string name="mode_pen">Stift</string>
<string name="mode_pen_mouse">Maus</string>
<string name="mode_pen_touch">Touch</string>
<string name="mode_pen_button">Seitentaste</string>
<string name="mode_osc">Bildschirmsteuerung</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">Auto zeigt die Steuerung an, wenn kein Controller verbunden ist.</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Πινακίδα αφής</string>
<string name="mode_touch_direct">Απευθείας</string>
<string name="mode_touch_note">Αυτόματο: πινακίδα αφής στην Επιφάνεια εργασίας, απευθείας στο Steam.</string>
<string name="mode_pen">Γραφίδα</string>
<string name="mode_pen_mouse">Ποντίκι</string>
<string name="mode_pen_touch">Αφή</string>
<string name="mode_pen_button">Πλαϊνό κουμπί</string>
<string name="mode_osc">Χειριστήρια στην οθόνη</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">Το Αυτόματο εμφανίζει τα χειριστήρια όταν δεν είναι συνδεδεμένο χειριστήριο.</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Touchpad</string>
<string name="mode_touch_direct">Directo</string>
<string name="mode_touch_note">Auto: touchpad en Escritorio, directo en Steam.</string>
<string name="mode_pen">Lápiz</string>
<string name="mode_pen_mouse">Ratón</string>
<string name="mode_pen_touch">Táctil</string>
<string name="mode_pen_button">Botón lateral</string>
<string name="mode_osc">Controles en pantalla</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">Auto muestra los controles cuando no hay ningún mando conectado.</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Kosketuslevy</string>
<string name="mode_touch_direct">Suora</string>
<string name="mode_touch_note">Automaattinen: kosketuslevy Työpöydällä, suora Steamissa.</string>
<string name="mode_pen">Kynä</string>
<string name="mode_pen_mouse">Hiiri</string>
<string name="mode_pen_touch">Kosketus</string>
<string name="mode_pen_button">Sivupainike</string>
<string name="mode_osc">Näytön ohjaimet</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">Automaattinen näyttää ohjaimet, kun yhtään ohjainta ei ole kytketty.</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Pavé tactile</string>
<string name="mode_touch_direct">Direct</string>
<string name="mode_touch_note">Auto : pavé tactile pour le bureau, tactile direct pour Steam.</string>
<string name="mode_pen">Stylet</string>
<string name="mode_pen_mouse">Souris</string>
<string name="mode_pen_touch">Tactile</string>
<string name="mode_pen_button">Bouton latéral</string>
<string name="mode_osc">Commandes à l\'écran</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">Le mode automatique affiche les commandes à l\'écran lorsqu\'aucune manette n\'est connectée.</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">टचपैड</string>
<string name="mode_touch_direct">डायरेक्ट</string>
<string name="mode_touch_note">ऑटो: डेस्कटॉप पर टचपैड, Steam में डायरेक्ट।</string>
<string name="mode_pen">पेन</string>
<string name="mode_pen_mouse">माउस</string>
<string name="mode_pen_touch">टच</string>
<string name="mode_pen_button">साइड बटन</string>
<string name="mode_osc">ऑन-स्क्रीन कंट्रोल</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">कोई कंट्रोलर कनेक्ट न होने पर ऑटो कंट्रोल दिखाता है।</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Érintőpad</string>
<string name="mode_touch_direct">Közvetlen</string>
<string name="mode_touch_note">Automatikus: érintőpad az Asztalon, közvetlen a Steamben.</string>
<string name="mode_pen">Toll</string>
<string name="mode_pen_mouse">Egér</string>
<string name="mode_pen_touch">Érintés</string>
<string name="mode_pen_button">Oldalsó gomb</string>
<string name="mode_osc">Képernyőn megjelenő vezérlők</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">Az Automatikus megjeleníti a vezérlőket, ha nincs csatlakoztatott kontroller.</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Touchpad</string>
<string name="mode_touch_direct">Langsung</string>
<string name="mode_touch_note">Otomatis: touchpad di Desktop, langsung di Steam.</string>
<string name="mode_pen">Pena</string>
<string name="mode_pen_mouse">Mouse</string>
<string name="mode_pen_touch">Sentuhan</string>
<string name="mode_pen_button">Tombol samping</string>
<string name="mode_osc">Kontrol di layar</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">Otomatis menampilkan kontrol saat tidak ada pengontrol yang terhubung.</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Touchpad</string>
<string name="mode_touch_direct">Diretto</string>
<string name="mode_touch_note">Auto: touchpad sul Desktop, diretto in Steam.</string>
<string name="mode_pen">Penna</string>
<string name="mode_pen_mouse">Mouse</string>
<string name="mode_pen_touch">Tocco</string>
<string name="mode_pen_button">Tasto laterale</string>
<string name="mode_osc">Controlli su schermo</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">Auto mostra i controlli quando non è collegato nessun controller.</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">トラックパッド</string>
<string name="mode_touch_direct">ダイレクト</string>
<string name="mode_touch_note">自動:デスクトップではトラックパッド、Steamではダイレクトタッチを使用します。</string>
<string name="mode_pen">ペン</string>
<string name="mode_pen_mouse">マウス</string>
<string name="mode_pen_touch">タッチ</string>
<string name="mode_pen_button">サイドボタン</string>
<string name="mode_osc">画面コントローラー</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">自動では、コントローラーが接続されていないときに画面コントローラーを表示します。</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">터치패드</string>
<string name="mode_touch_direct">직접 터치</string>
<string name="mode_touch_note">자동: 데스크톱에서는 터치패드, Steam에서는 직접 터치를 사용합니다.</string>
<string name="mode_pen">펜</string>
<string name="mode_pen_mouse">마우스</string>
<string name="mode_pen_touch">터치</string>
<string name="mode_pen_button">측면 버튼</string>
<string name="mode_osc">화면 컨트롤</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">자동 모드에서는 컨트롤러가 연결되지 않은 경우 화면 컨트롤을 표시합니다.</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Pad sentuh</string>
<string name="mode_touch_direct">Terus</string>
<string name="mode_touch_note">Auto: pad sentuh pada Desktop, terus dalam Steam.</string>
<string name="mode_pen">Pen</string>
<string name="mode_pen_mouse">Tetikus</string>
<string name="mode_pen_touch">Sentuhan</string>
<string name="mode_pen_button">Butang sisi</string>
<string name="mode_osc">Kawalan pada skrin</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">Auto memaparkan kawalan apabila tiada pengawal disambungkan.</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Styreflate</string>
<string name="mode_touch_direct">Direkte</string>
<string name="mode_touch_note">Auto: styreflate på Skrivebord, direkte i Steam.</string>
<string name="mode_pen">Penn</string>
<string name="mode_pen_mouse">Mus</string>
<string name="mode_pen_touch">Berøring</string>
<string name="mode_pen_button">Sideknapp</string>
<string name="mode_osc">Skjermkontroller</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">Auto viser kontrollene når ingen kontroller er tilkoblet.</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Touchpad</string>
<string name="mode_touch_direct">Direct</string>
<string name="mode_touch_note">Automatisch: touchpad op Desktop, direct in Steam.</string>
<string name="mode_pen">Pen</string>
<string name="mode_pen_mouse">Muis</string>
<string name="mode_pen_touch">Aanraken</string>
<string name="mode_pen_button">Zijknop</string>
<string name="mode_osc">Schermbediening</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">Automatisch toont de bediening als er geen controller is verbonden.</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Touchpad</string>
<string name="mode_touch_direct">Bezpośredni</string>
<string name="mode_touch_note">Auto: touchpad na pulpicie, bezpośredni w Steam.</string>
<string name="mode_pen">Rysik</string>
<string name="mode_pen_mouse">Mysz</string>
<string name="mode_pen_touch">Dotyk</string>
<string name="mode_pen_button">Przycisk boczny</string>
<string name="mode_osc">Sterowanie ekranowe</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">Auto pokazuje sterowanie, gdy nie jest podłączony żaden kontroler.</string>
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Painel tátil</string>
<string name="mode_touch_direct">Direto</string>
<string name="mode_touch_note">Automático: painel tátil no Ambiente de trabalho, direto no Steam.</string>
<string name="mode_pen">Caneta</string>
<string name="mode_pen_mouse">Rato</string>
<string name="mode_pen_touch">Toque</string>
<string name="mode_pen_button">Botão lateral</string>
<string name="mode_osc">Controlos no ecrã</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">Em Automático, os controlos aparecem quando não há nenhum comando ligado.</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Touchpad</string>
<string name="mode_touch_direct">Direto</string>
<string name="mode_touch_note">Automático: touchpad na Área de trabalho, direto na Steam.</string>
<string name="mode_pen">Caneta</string>
<string name="mode_pen_mouse">Mouse</string>
<string name="mode_pen_touch">Toque</string>
<string name="mode_pen_button">Botão lateral</string>
<string name="mode_osc">Controles na tela</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">No Automático, os controles na tela aparecem quando não há um controle conectado.</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Touchpad</string>
<string name="mode_touch_direct">Direct</string>
<string name="mode_touch_note">Automat: touchpad pe Desktop, direct în Steam.</string>
<string name="mode_pen">Stilou</string>
<string name="mode_pen_mouse">Mouse</string>
<string name="mode_pen_touch">Atingere</string>
<string name="mode_pen_button">Buton lateral</string>
<string name="mode_osc">Comenzi pe ecran</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">Automat afișează comenzile când niciun controller nu este conectat.</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Тачпад</string>
<string name="mode_touch_direct">Прямой</string>
<string name="mode_touch_note">Авто: тачпад для рабочего стола, прямой сенсорный ввод для Steam.</string>
<string name="mode_pen">Перо</string>
<string name="mode_pen_mouse">Мышь</string>
<string name="mode_pen_touch">Сенсорный ввод</string>
<string name="mode_pen_button">Боковая кнопка</string>
<string name="mode_osc">Экранные элементы управления</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">Автоматический режим показывает экранные элементы управления, если контроллер не подключен.</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Pekplatta</string>
<string name="mode_touch_direct">Direkt</string>
<string name="mode_touch_note">Auto: pekplatta på skrivbordet, direkt i Steam.</string>
<string name="mode_pen">Penna</string>
<string name="mode_pen_mouse">Mus</string>
<string name="mode_pen_touch">Pekskärm</string>
<string name="mode_pen_button">Sidoknapp</string>
<string name="mode_osc">Skärmkontroller</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">Auto visar kontrollerna när ingen handkontroll är ansluten.</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">ทัชแพด</string>
<string name="mode_touch_direct">โดยตรง</string>
<string name="mode_touch_note">อัตโนมัติ: ทัชแพดในเดสก์ท็อป โดยตรงใน Steam</string>
<string name="mode_pen">ปากกา</string>
<string name="mode_pen_mouse">เมาส์</string>
<string name="mode_pen_touch">การสัมผัส</string>
<string name="mode_pen_button">ปุ่มด้านข้าง</string>
<string name="mode_osc">ปุ่มควบคุมบนหน้าจอ</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">อัตโนมัติจะแสดงปุ่มควบคุมเมื่อไม่มีคอนโทรลเลอร์เชื่อมต่ออยู่</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Dokunmatik yüzey</string>
<string name="mode_touch_direct">Doğrudan</string>
<string name="mode_touch_note">Otomatik: Masaüstünde dokunmatik yüzey, Steam\'de doğrudan.</string>
<string name="mode_pen">Kalem</string>
<string name="mode_pen_mouse">Fare</string>
<string name="mode_pen_touch">Dokunma</string>
<string name="mode_pen_button">Yan düğme</string>
<string name="mode_osc">Ekran üstü kontroller</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">Otomatik, kumanda bağlı değilken kontrolleri gösterir.</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Сенсорна панель</string>
<string name="mode_touch_direct">Пряме</string>
<string name="mode_touch_note">«Авто»: сенсорна панель на робочому столі, пряме введення в Steam.</string>
<string name="mode_pen">Перо</string>
<string name="mode_pen_mouse">Миша</string>
<string name="mode_pen_touch">Сенсорне введення</string>
<string name="mode_pen_button">Бічна кнопка</string>
<string name="mode_osc">Екранне керування</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">«Авто» показує екранне керування, коли контролер не під’єднано.</string>
+4
View File
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">Touchpad</string>
<string name="mode_touch_direct">Trực tiếp</string>
<string name="mode_touch_note">Tự động: touchpad ở Desktop, trực tiếp ở Steam.</string>
<string name="mode_pen">Bút</string>
<string name="mode_pen_mouse">Chuột</string>
<string name="mode_pen_touch">Chạm</string>
<string name="mode_pen_button">Nút bên</string>
<string name="mode_osc">Điều khiển trên màn hình</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">Tự động hiện các nút điều khiển khi không có tay cầm kết nối.</string>
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">触控板</string>
<string name="mode_touch_direct">直接</string>
<string name="mode_touch_note">自动:桌面用触控板,Steam 中用直接触摸。</string>
<string name="mode_pen">手写笔</string>
<string name="mode_pen_mouse">鼠标</string>
<string name="mode_pen_touch">触摸</string>
<string name="mode_pen_button">侧键</string>
<string name="mode_osc">屏幕控制</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">自动模式会在未连接手柄时显示屏幕控制。</string>
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">觸控板</string>
<string name="mode_touch_direct">直接</string>
<string name="mode_touch_note">自動:桌面使用觸控板,Steam 使用直接觸控。</string>
<string name="mode_pen">觸控筆</string>
<string name="mode_pen_mouse">滑鼠</string>
<string name="mode_pen_touch">觸控</string>
<string name="mode_pen_button">側鍵</string>
<string name="mode_osc">螢幕控制</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">「自動」會在未連接控制器時顯示螢幕控制。</string>
@@ -269,6 +269,10 @@
<string name="mode_touch_touchpad">觸控板</string>
<string name="mode_touch_direct">直接</string>
<string name="mode_touch_note">自動:桌面使用觸控板,Steam 使用直接觸控。</string>
<string name="mode_pen">觸控筆</string>
<string name="mode_pen_mouse">滑鼠</string>
<string name="mode_pen_touch">觸控</string>
<string name="mode_pen_button">側鍵</string>
<string name="mode_osc">螢幕控制</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">自動模式會在未連接控制器時顯示螢幕控制。</string>
+4
View File
@@ -297,6 +297,10 @@
<string name="mode_touch_touchpad">Touchpad</string>
<string name="mode_touch_direct">Direct</string>
<string name="mode_touch_note">Auto: touchpad on Desktop, direct in Steam.</string>
<string name="mode_pen">Pen</string>
<string name="mode_pen_mouse">Mouse</string>
<string name="mode_pen_touch">Touch</string>
<string name="mode_pen_button">Side button</string>
<string name="mode_osc">On-screen controls</string>
<string name="mode_osc_qam">Steam + QAM</string>
<string name="mode_osc_note">Auto shows the controls when no controller is connected.</string>
@@ -40,4 +40,14 @@ class InputSpaceTest {
assertEquals(InputSpace.HEIGHT - 1, InputSpace.y(5000f, 1504))
assertEquals(0, InputSpace.y(10f, 0))
}
@Test fun fixedPositionsKeepTheFractionOfAnInputUnit() {
assertEquals(960 * 256, InputSpace.fixedX(1200f, 2400))
assertEquals(1700, InputSpace.fixedX(5.534f, 1600))
assertEquals(InputSpace.x(5.534f, 1600), InputSpace.fixedX(5.534f, 1600) / InputSpace.FIXED_ONE)
assertEquals(InputSpace.WIDTH * InputSpace.FIXED_ONE - 1, InputSpace.fixedX(2400f, 2400))
assertEquals(InputSpace.HEIGHT * InputSpace.FIXED_ONE - 1, InputSpace.fixedY(5000f, 1504))
assertEquals(0, InputSpace.fixedY(-1f, 1504))
assertEquals(0, InputSpace.fixedY(10f, 0))
}
}
@@ -0,0 +1,27 @@
package com.droiddeck.launcher.input
import com.droiddeck.launcher.session.SessionPrefs
import org.junit.Assert.assertEquals
import org.junit.Test
class PenRouterTest {
@Test fun appUiBlocksThePenInEveryModeAndScreen() {
for (mode in listOf(SessionPrefs.PEN_MOUSE, SessionPrefs.PEN_TOUCH))
for (glasses in listOf(false, true)) for (lock in listOf(false, true))
assertEquals("$mode $glasses $lock", PenRouter.Route.BLOCKED, PenRouter.decide(true, mode, glasses, lock))
}
@Test fun touchModeKeepsThePenAFingerEverywhere() {
for (glasses in listOf(false, true)) for (lock in listOf(false, true))
assertEquals("$glasses $lock", PenRouter.Route.TOUCH, PenRouter.decide(false, SessionPrefs.PEN_TOUCH, glasses, lock))
}
@Test fun glassesAndProgramLocksMakeTheMouseRelative() {
for ((glasses, lock) in listOf(true to false, false to true, true to true))
assertEquals("$glasses $lock", PenRouter.Route.RELATIVE, PenRouter.decide(false, SessionPrefs.PEN_MOUSE, glasses, lock))
}
@Test fun mouseDrivesThePenRouteOnThePhone() {
assertEquals(PenRouter.Route.PEN, PenRouter.decide(false, SessionPrefs.PEN_MOUSE, false, false))
}
}
@@ -0,0 +1,384 @@
package com.droiddeck.launcher.input
import android.graphics.RectF
import android.os.Looper
import android.os.SystemClock
import android.view.InputDevice
import android.view.KeyEvent
import android.view.MotionEvent
import com.droiddeck.launcher.input.PenStream.Companion.PEN_IN
import com.droiddeck.launcher.input.PenStream.Companion.PEN_MIDDLE
import com.droiddeck.launcher.input.PenStream.Companion.PEN_RIGHT
import com.droiddeck.launcher.input.PenStream.Companion.PEN_TIP
import com.droiddeck.launcher.session.SessionPrefs
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 = [28], manifest = Config.NONE)
class PenStreamTest {
data class Record(val flags: Int, val x: Int, val y: Int)
data class Sample(val time: Long, val x: Float, val y: Float = 300f)
private val records = mutableListOf<Record>()
private val stream = PenStream { flags, x, y -> records += Record(flags, x, y) }
private val area = RectF(0f, 0f, 1000f, 600f)
@Test fun hoverEntersMovesAndLeavesProximity() {
send(MotionEvent.ACTION_HOVER_ENTER, Sample(10, 100f))
send(MotionEvent.ACTION_HOVER_MOVE, Sample(20, 200f))
send(MotionEvent.ACTION_HOVER_EXIT, Sample(30, 250f))
assertEquals(listOf(PEN_IN, PEN_IN), flags())
idle()
assertEquals(listOf(PEN_IN, PEN_IN), flags())
grace()
assertEquals(listOf(PEN_IN, PEN_IN, 0), flags())
assertEquals(listOf(100f, 200f).map(::x), records.take(2).map { it.x })
assertFalse(stream.inProximity)
}
@Test fun hoverExitThenDownWithTheSameTimeStaysInProximity() {
send(MotionEvent.ACTION_HOVER_ENTER, Sample(10, 100f))
send(MotionEvent.ACTION_HOVER_EXIT, Sample(20, 100f))
send(MotionEvent.ACTION_DOWN, Sample(20, 100f))
grace()
assertEquals(listOf(PEN_IN, PEN_IN or PEN_TIP), flags())
}
@Test fun hoverExitThenADownAfterTheGraceLeavesProximityFirst() {
send(MotionEvent.ACTION_HOVER_ENTER, Sample(10, 100f))
send(MotionEvent.ACTION_HOVER_EXIT, Sample(20, 100f))
send(MotionEvent.ACTION_DOWN, Sample(21 + PenStream.EXIT_GRACE_MS, 100f))
assertEquals(listOf(PEN_IN, 0, PEN_IN or PEN_TIP), flags())
}
@Test fun aPenFlickeringAtTheEdgeOfHoverRangeStaysInProximity() {
send(MotionEvent.ACTION_HOVER_ENTER, Sample(10, 100f))
for (i in 0 until 5) {
send(MotionEvent.ACTION_HOVER_EXIT, Sample(20L + i * 22, 100f))
send(MotionEvent.ACTION_HOVER_ENTER, Sample(34L + i * 22, 101f))
}
send(MotionEvent.ACTION_HOVER_EXIT, Sample(130, 101f))
send(MotionEvent.ACTION_DOWN, Sample(130 + PenStream.EXIT_GRACE_MS, 101f))
grace()
assertEquals(List(6) { PEN_IN } + (PEN_IN or PEN_TIP), flags())
assertTrue(stream.inProximity)
}
@Test fun liftingIntoHoverKeepsProximityAndLiftingAwayLeavesIt() {
send(MotionEvent.ACTION_DOWN, Sample(10, 100f))
send(MotionEvent.ACTION_UP, Sample(20, 110f))
send(MotionEvent.ACTION_HOVER_ENTER, Sample(20, 110f))
grace()
assertEquals(listOf(PEN_IN or PEN_TIP, PEN_IN, PEN_IN), flags())
records.clear()
send(MotionEvent.ACTION_DOWN, Sample(30, 100f))
send(MotionEvent.ACTION_UP, Sample(40, 100f))
grace()
assertEquals(listOf(PEN_IN or PEN_TIP, PEN_IN, 0), flags())
}
@Test fun aPenKeyDuringTheExitGraceEndsProximityFirst() {
send(MotionEvent.ACTION_HOVER_ENTER, Sample(10, 100f))
send(MotionEvent.ACTION_HOVER_EXIT, Sample(20, 100f))
assertTrue(stream.onKey(key(KeyEvent.ACTION_DOWN, 25)))
grace()
assertEquals(listOf(PEN_IN, 0), flags())
}
@Test fun historicalSamplesGoOutOldestFirst() {
send(MotionEvent.ACTION_DOWN, Sample(100, 10f))
send(MotionEvent.ACTION_MOVE, Sample(103, 20f), Sample(106, 30f), Sample(109, 40f))
assertEquals(listOf(10f, 20f, 30f, 40f).map(::x), records.map { it.x })
assertTrue(records.all { it.flags == PEN_IN or PEN_TIP })
assertEquals(y(300f), records.last().y)
}
@Test fun cancelEndsTheStrokeAndIgnoresTheRest() {
send(MotionEvent.ACTION_DOWN, Sample(10, 100f))
send(MotionEvent.ACTION_MOVE, Sample(20, 150f))
send(MotionEvent.ACTION_CANCEL, Sample(30, 160f))
send(MotionEvent.ACTION_MOVE, Sample(40, 170f))
send(MotionEvent.ACTION_UP, Sample(50, 170f))
assertEquals(listOf(PEN_IN or PEN_TIP, PEN_IN or PEN_TIP, 0), flags())
assertFalse(stream.inProximity)
}
@Test fun anUpThatAndroidCanceledIsACancelNotALift() {
send(MotionEvent.ACTION_DOWN, Sample(10, 100f))
send(MotionEvent.ACTION_UP, Sample(20, 100f), flags = MotionEvent.FLAG_CANCELED)
assertEquals(listOf(PEN_IN or PEN_TIP, 0), flags())
}
@Test fun theSideButtonSettingMapsThePrimaryButtonAndTheSecondaryGetsTheOtherClick() {
val cases = mapOf(SessionPrefs.PEN_BUTTON_RIGHT to (PEN_RIGHT to PEN_MIDDLE),
SessionPrefs.PEN_BUTTON_MIDDLE to (PEN_MIDDLE to PEN_RIGHT), SessionPrefs.PEN_BUTTON_OFF to (0 to PEN_RIGHT))
for ((setting, expected) in cases) {
assertEquals(setting, 0, PenStream.buttonFlags(primary = false, secondary = false, sideButton = setting))
assertEquals(setting, expected.first, PenStream.buttonFlags(primary = true, secondary = false, sideButton = setting))
assertEquals(setting, expected.second, PenStream.buttonFlags(primary = false, secondary = true, sideButton = setting))
assertEquals(setting, expected.first or expected.second, PenStream.buttonFlags(primary = true, secondary = true, sideButton = setting))
}
stream.sideButton = SessionPrefs.PEN_BUTTON_MIDDLE
send(MotionEvent.ACTION_HOVER_ENTER, Sample(10, 100f), buttons = MotionEvent.BUTTON_STYLUS_PRIMARY)
send(MotionEvent.ACTION_HOVER_MOVE, Sample(20, 100f), buttons = MotionEvent.BUTTON_STYLUS_SECONDARY)
assertEquals(listOf(PEN_IN or PEN_MIDDLE, PEN_IN or PEN_RIGHT), flags())
}
@Test fun barrelButtonsFollowTheButtonState() {
send(MotionEvent.ACTION_HOVER_ENTER, Sample(10, 100f))
send(MotionEvent.ACTION_HOVER_MOVE, Sample(20, 100f), buttons = MotionEvent.BUTTON_STYLUS_PRIMARY)
send(MotionEvent.ACTION_BUTTON_PRESS, Sample(21, 100f), buttons = MotionEvent.BUTTON_STYLUS_PRIMARY or MotionEvent.BUTTON_STYLUS_SECONDARY)
send(MotionEvent.ACTION_DOWN, Sample(30, 100f), buttons = MotionEvent.BUTTON_STYLUS_SECONDARY)
send(MotionEvent.ACTION_MOVE, Sample(40, 100f))
assertEquals(listOf(PEN_IN, PEN_IN or PEN_RIGHT, PEN_IN or PEN_RIGHT or PEN_MIDDLE, PEN_IN or PEN_TIP or PEN_MIDDLE,
PEN_IN or PEN_TIP), flags())
}
@Test fun aBluetoothPenKeyIsTheSideButtonWhileThePenIsNear() {
send(MotionEvent.ACTION_HOVER_ENTER, Sample(10, 100f))
assertTrue(stream.onKey(key(KeyEvent.ACTION_DOWN, 15)))
assertTrue(stream.onKey(key(KeyEvent.ACTION_DOWN, 16, repeat = 1)))
send(MotionEvent.ACTION_HOVER_MOVE, Sample(20, 130f))
assertTrue(stream.onKey(key(KeyEvent.ACTION_UP, 25)))
stream.cancel()
stream.sideButton = SessionPrefs.PEN_BUTTON_MIDDLE
send(MotionEvent.ACTION_HOVER_ENTER, Sample(30, 100f))
stream.onKey(key(KeyEvent.ACTION_DOWN, 35))
stream.onKey(key(KeyEvent.ACTION_UP, 36))
stream.cancel()
assertEquals(listOf(PEN_IN, PEN_IN or PEN_RIGHT, PEN_IN or PEN_RIGHT, PEN_IN, 0,
PEN_IN, PEN_IN or PEN_MIDDLE, PEN_IN, 0), flags())
assertEquals(x(130f), records[2].x)
records.clear()
stream.sideButton = SessionPrefs.PEN_BUTTON_OFF
send(MotionEvent.ACTION_HOVER_ENTER, Sample(40, 100f))
assertTrue(stream.onKey(key(KeyEvent.ACTION_DOWN, 45)))
assertTrue(stream.holdsKey(key(KeyEvent.ACTION_UP, 46)))
assertTrue(stream.onKey(key(KeyEvent.ACTION_UP, 46)))
assertEquals(listOf(PEN_IN), flags())
}
@Test fun aBluetoothPenKeyIsConsumedWhenThePenIsAway() {
assertTrue(stream.onKey(key(KeyEvent.ACTION_DOWN, 10)))
send(MotionEvent.ACTION_HOVER_ENTER, Sample(20, 100f))
assertTrue(stream.onKey(key(KeyEvent.ACTION_UP, 30)))
assertEquals(listOf(PEN_IN), flags())
}
@Test fun aKeyHeldWhileThePenIsAwayIsReleasedAndPressedAgainOnReturn() {
send(MotionEvent.ACTION_HOVER_ENTER, Sample(10, 100f))
stream.onKey(key(KeyEvent.ACTION_DOWN, 15))
send(MotionEvent.ACTION_HOVER_EXIT, Sample(20, 100f))
grace()
stream.onKey(key(KeyEvent.ACTION_DOWN, 500, repeat = 1))
stream.onKey(key(KeyEvent.ACTION_DOWN, 550, repeat = 2))
send(MotionEvent.ACTION_HOVER_ENTER, Sample(600, 100f))
send(MotionEvent.ACTION_DOWN, Sample(610, 100f))
send(MotionEvent.ACTION_UP, Sample(620, 100f))
send(MotionEvent.ACTION_HOVER_ENTER, Sample(620, 100f))
stream.onKey(key(KeyEvent.ACTION_UP, 630))
val right = PEN_IN or PEN_RIGHT
assertEquals(listOf(PEN_IN, right, 0, right, right or PEN_TIP, right, right, PEN_IN), flags())
}
@Test fun aKeyReleasedWhileThePenIsAwayStaysReleased() {
send(MotionEvent.ACTION_HOVER_ENTER, Sample(10, 100f))
stream.onKey(key(KeyEvent.ACTION_DOWN, 15))
send(MotionEvent.ACTION_HOVER_EXIT, Sample(20, 100f))
grace()
assertTrue(stream.holdsKey(key(KeyEvent.ACTION_UP, 40)))
assertTrue(stream.onKey(key(KeyEvent.ACTION_UP, 40)))
assertFalse(stream.holdsKey(key(KeyEvent.ACTION_UP, 41)))
send(MotionEvent.ACTION_HOVER_ENTER, Sample(50, 100f))
assertEquals(listOf(PEN_IN, PEN_IN or PEN_RIGHT, 0, PEN_IN), flags())
}
@Test fun onlyALifecycleCancelForgetsAHeldKeyAndARepeatBringsItBack() {
send(MotionEvent.ACTION_HOVER_ENTER, Sample(10, 100f))
stream.onKey(key(KeyEvent.ACTION_DOWN, 15))
stream.cancel()
send(MotionEvent.ACTION_HOVER_ENTER, Sample(20, 100f))
stream.cancel(releaseKey = true)
send(MotionEvent.ACTION_HOVER_ENTER, Sample(30, 100f))
assertFalse(stream.holdsKey(key(KeyEvent.ACTION_UP, 35)))
stream.onKey(key(KeyEvent.ACTION_DOWN, 40, repeat = 1))
stream.onKey(key(KeyEvent.ACTION_UP, 50))
val right = PEN_IN or PEN_RIGHT
assertEquals(listOf(PEN_IN, right, 0, right, 0, PEN_IN, right, PEN_IN), flags())
}
@Test fun removingTheBluetoothPenReleasesItsKeyAndForgetsIt() {
send(MotionEvent.ACTION_HOVER_ENTER, Sample(10, 100f))
stream.onKey(key(KeyEvent.ACTION_DOWN, 15))
stream.deviceRemoved(10)
assertFalse(stream.holdsKey(key(KeyEvent.ACTION_UP, 18)))
assertTrue(stream.inProximity)
stream.onKey(key(KeyEvent.ACTION_DOWN, 20))
send(MotionEvent.ACTION_HOVER_EXIT, Sample(25, 100f))
grace()
stream.deviceRemoved(10)
send(MotionEvent.ACTION_HOVER_ENTER, Sample(30, 100f))
assertEquals(listOf(PEN_IN, PEN_IN or PEN_RIGHT, PEN_IN, PEN_IN or PEN_RIGHT, 0, PEN_IN), flags())
}
@Test fun aHoverThatStopsReportingCountsAsGone() {
send(MotionEvent.ACTION_HOVER_ENTER, Sample(1_000, 100f))
send(MotionEvent.ACTION_HOVER_MOVE, Sample(2_000, 100f))
send(MotionEvent.ACTION_HOVER_MOVE, Sample(4_500, 110f))
assertEquals(listOf(PEN_IN, PEN_IN, 0, PEN_IN), flags())
records.clear()
assertTrue(stream.onKey(key(KeyEvent.ACTION_DOWN, 7_000)))
assertEquals(listOf(0), flags())
}
@Test fun aPenKeyDoesNotKeepASilentHoverNear() {
send(MotionEvent.ACTION_HOVER_ENTER, Sample(1_000, 100f))
assertTrue(stream.onKey(key(KeyEvent.ACTION_DOWN, 2_500)))
assertTrue(stream.onKey(key(KeyEvent.ACTION_UP, 3_000)))
assertEquals(listOf(PEN_IN, PEN_IN or PEN_RIGHT, 0), flags())
}
@Test fun aSilentHoverIsSentOutByTheWatchdogWithoutAnotherEvent() {
val start = SystemClock.uptimeMillis()
send(MotionEvent.ACTION_HOVER_ENTER, Sample(start, 100f), buttons = MotionEvent.BUTTON_STYLUS_PRIMARY)
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(1_500))
send(MotionEvent.ACTION_HOVER_MOVE, Sample(start + 1_500, 110f), buttons = MotionEvent.BUTTON_STYLUS_PRIMARY)
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(PenStream.HOVER_TIMEOUT_MS - 1))
assertTrue(stream.inProximity)
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(1))
assertFalse(stream.inProximity)
assertEquals(listOf(PEN_IN or PEN_RIGHT, PEN_IN or PEN_RIGHT, 0), flags())
}
@Test fun theWatchdogNeverEndsAContact() {
val start = SystemClock.uptimeMillis()
send(MotionEvent.ACTION_HOVER_ENTER, Sample(start, 100f))
send(MotionEvent.ACTION_DOWN, Sample(start + 10, 100f))
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(5))
assertTrue(stream.inProximity)
assertEquals(listOf(PEN_IN, PEN_IN or PEN_TIP), flags())
}
@Test fun aStrokeIsNeverTimedOut() {
send(MotionEvent.ACTION_DOWN, Sample(1_000, 100f))
send(MotionEvent.ACTION_MOVE, Sample(9_000, 110f))
assertEquals(listOf(PEN_IN or PEN_TIP, PEN_IN or PEN_TIP), flags())
}
@Test fun lifecycleCancelEndsEverythingOnce() {
send(MotionEvent.ACTION_DOWN, Sample(10, 100f))
stream.cancel()
stream.cancel()
assertEquals(listOf(PEN_IN or PEN_TIP, 0), flags())
}
@Test fun removingThePenDeviceEndsItsStream() {
send(MotionEvent.ACTION_HOVER_ENTER, Sample(10, 100f), device = 6)
stream.deviceRemoved(8)
assertTrue(stream.inProximity)
stream.deviceRemoved(6)
assertEquals(listOf(PEN_IN, 0), flags())
}
@Test fun aPenNextToAFingerKeepsItsOwnStroke() {
val finger = MotionEvent.TOOL_TYPE_FINGER
val stylus = MotionEvent.TOOL_TYPE_STYLUS
mixed(MotionEvent.ACTION_DOWN, 10, finger to 50f)
assertTrue(records.isEmpty())
mixed(MotionEvent.ACTION_POINTER_DOWN or (1 shl MotionEvent.ACTION_POINTER_INDEX_SHIFT), 20, finger to 50f, stylus to 400f)
mixed(MotionEvent.ACTION_MOVE, 30, finger to 60f, stylus to 410f)
mixed(MotionEvent.ACTION_POINTER_UP, 40, finger to 60f, stylus to 420f)
mixed(MotionEvent.ACTION_POINTER_UP or (1 shl MotionEvent.ACTION_POINTER_INDEX_SHIFT), 50, finger to 60f, stylus to 430f)
assertEquals(listOf(PEN_IN or PEN_TIP, PEN_IN or PEN_TIP, PEN_IN or PEN_TIP, PEN_IN), flags())
assertEquals(listOf(400f, 410f, 420f, 430f).map(::x), records.map { it.x })
}
@Test fun positionsAreClampedToThePicture() {
val event = event(MotionEvent.ACTION_HOVER_ENTER, listOf(Sample(10, 40f, y = 580f)), MotionEvent.TOOL_TYPE_STYLUS)
try { stream.onMotion(event, 0, RectF(100f, 50f, 900f, 550f), 1000, 600) } finally { event.recycle() }
assertEquals(Record(PEN_IN, x(100f), y(550f)), records.single())
}
@Test fun pensAreFoundByToolTypeFirstAndSourceSecond() {
fun index(tool: Int, source: Int): Int {
val event = event(MotionEvent.ACTION_DOWN, listOf(Sample(0, 1f)), tool, source = source)
return try { PenStream.penIndex(event) } finally { event.recycle() }
}
assertEquals(0, index(MotionEvent.TOOL_TYPE_STYLUS, InputDevice.SOURCE_MOUSE))
assertEquals(0, index(MotionEvent.TOOL_TYPE_ERASER, InputDevice.SOURCE_TOUCHSCREEN))
assertEquals(0, index(MotionEvent.TOOL_TYPE_UNKNOWN, InputDevice.SOURCE_STYLUS))
assertEquals(-1, index(MotionEvent.TOOL_TYPE_FINGER, InputDevice.SOURCE_STYLUS))
assertEquals(-1, index(MotionEvent.TOOL_TYPE_MOUSE, InputDevice.SOURCE_MOUSE or InputDevice.SOURCE_STYLUS))
assertEquals(-1, index(MotionEvent.TOOL_TYPE_UNKNOWN, InputDevice.SOURCE_TOUCHSCREEN))
}
@Test fun penButtonKeyboardsAreRecognisedByNameAndShape() {
val keyboard = InputDevice.SOURCE_KEYBOARD
assertTrue(PenStream.isPenKeyboard("OPPO AI Pen", keyboard, external = true, alphabetic = false))
assertTrue(PenStream.isPenKeyboard("Xiaomi Smart STYLUS", keyboard, external = true, alphabetic = false))
assertTrue(PenStream.isPenKeyboard("HUAWEI M-Pencil", keyboard, external = true, alphabetic = false))
assertFalse(PenStream.isPenKeyboard("OPPO AI Pen", keyboard, external = false, alphabetic = false))
assertFalse(PenStream.isPenKeyboard("OPPO AI Pen", keyboard or InputDevice.SOURCE_MOUSE, external = true, alphabetic = false))
assertFalse(PenStream.isPenKeyboard("Pen Keyboard K380", keyboard, external = true, alphabetic = true))
assertFalse(PenStream.isPenKeyboard("Open Remote", keyboard, external = true, alphabetic = false))
assertFalse(PenStream.isPenKeyboard("8BitDo Remote", keyboard, external = true, alphabetic = false))
assertFalse(PenStream.isPenKeyboard(null, keyboard, external = true, alphabetic = false))
}
@Test fun aTouchscreenCountsAsAPenDeviceOnlyWhereAndroidSetsTheStylusBitForPens() {
val screen = InputDevice.SOURCE_TOUCHSCREEN or InputDevice.SOURCE_STYLUS
assertFalse(PenStream.isPenDevice(screen, sdk = 33))
assertTrue(PenStream.isPenDevice(screen, sdk = 34))
for (sdk in listOf(26, 33, 34)) {
assertTrue(PenStream.isPenDevice(InputDevice.SOURCE_MOUSE or InputDevice.SOURCE_STYLUS, sdk))
assertTrue(PenStream.isPenDevice(InputDevice.SOURCE_BLUETOOTH_STYLUS, sdk))
assertTrue(PenStream.isPenDevice(InputDevice.SOURCE_STYLUS, sdk))
assertFalse(PenStream.isPenDevice(InputDevice.SOURCE_TOUCHSCREEN, sdk))
assertFalse(PenStream.isPenDevice(InputDevice.SOURCE_MOUSE, sdk))
}
}
private fun flags() = records.map { it.flags }
private fun x(position: Float) = InputSpace.fixedX(position, 1000)
private fun y(position: Float) = InputSpace.fixedY(position, 600)
private fun idle() = shadowOf(Looper.getMainLooper()).idle()
private fun grace() = shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(PenStream.EXIT_GRACE_MS))
private fun key(action: Int, time: Long, repeat: Int = 0) =
KeyEvent(time, time, action, KeyEvent.KEYCODE_UNKNOWN, repeat, 0, 10, 191, 0, InputDevice.SOURCE_KEYBOARD)
private fun send(action: Int, vararg samples: Sample, buttons: Int = 0, flags: Int = 0, device: Int = 6) {
val event = event(action, samples.toList(), MotionEvent.TOOL_TYPE_STYLUS, buttons, flags, device = device)
try { stream.onMotion(event, 0, area, 1000, 600) } finally { event.recycle() }
}
private fun mixed(action: Int, time: Long, vararg pointers: Pair<Int, Float>) {
val properties = Array(pointers.size) { MotionEvent.PointerProperties().apply { id = it; toolType = pointers[it].first } }
val coords = Array(pointers.size) { MotionEvent.PointerCoords().apply { x = pointers[it].second; y = 300f; pressure = 0.5f } }
val event = MotionEvent.obtain(0, time, action, pointers.size, properties, coords, 0, 0, 1f, 1f, 6, 0,
InputDevice.SOURCE_TOUCHSCREEN or InputDevice.SOURCE_STYLUS, 0)
try {
val pen = PenStream.penIndex(event)
if (pen >= 0) stream.onMotion(event, pen, area, 1000, 600)
} finally { event.recycle() }
}
private fun event(action: Int, samples: List<Sample>, tool: Int, buttons: Int = 0, flags: Int = 0,
source: Int = InputDevice.SOURCE_TOUCHSCREEN or InputDevice.SOURCE_STYLUS, device: Int = 6): MotionEvent {
val properties = arrayOf(MotionEvent.PointerProperties().apply { id = 0; toolType = tool })
fun coords(sample: Sample) = arrayOf(MotionEvent.PointerCoords().apply {
x = sample.x
y = sample.y
})
val first = samples.first()
val event = MotionEvent.obtain(0, first.time, action, 1, properties, coords(first), 0, buttons, 1f, 1f, device, 0, source, flags)
for (sample in samples.drop(1)) event.addBatch(sample.time, coords(sample), 0)
return event
}
}
@@ -0,0 +1,57 @@
package com.droiddeck.launcher.input
import android.view.InputDevice
import android.view.MotionEvent
import org.junit.Assert.*
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], manifest = Config.NONE)
class PointerSubsetTest {
@Test fun aForwardedPointerKeepsItsHistoryAndTimes() {
val properties = Array(2) { MotionEvent.PointerProperties().apply { id = it; toolType = if (it == 0) MotionEvent.TOOL_TYPE_FINGER else MotionEvent.TOOL_TYPE_STYLUS } }
fun coords(step: Int) = Array(2) { MotionEvent.PointerCoords().apply { x = 100f * it + step; y = 50f; pressure = 0.1f * step } }
val event = MotionEvent.obtain(5, 10, MotionEvent.ACTION_MOVE, 2, properties, coords(1), 0, 0, 1f, 1f, 3, 0,
InputDevice.SOURCE_TOUCHSCREEN or InputDevice.SOURCE_STYLUS, MotionEvent.FLAG_CANCELED)
event.addBatch(14, coords(2), 0)
event.addBatch(18, coords(3), 0)
val split = event.pointerSubset(1 shl 1)!!
try {
assertEquals(1, split.pointerCount)
assertEquals(MotionEvent.TOOL_TYPE_STYLUS, split.getToolType(0))
assertEquals(2, split.historySize)
assertEquals(listOf(10L, 14L), (0 until split.historySize).map { split.getHistoricalEventTime(it) })
assertEquals(listOf(101f, 102f), (0 until split.historySize).map { split.getHistoricalX(0, it) })
assertEquals(0.2f, split.getHistoricalPressure(0, 1), 1e-6f)
assertEquals(18L, split.eventTime)
assertEquals(103f, split.x, 0f)
assertEquals(5L, split.downTime)
assertEquals(MotionEvent.ACTION_MOVE, split.actionMasked)
assertEquals(event.source, split.source)
assertEquals(MotionEvent.FLAG_CANCELED, split.flags and MotionEvent.FLAG_CANCELED)
} finally {
split.recycle()
event.recycle()
}
}
@Test fun anEventWithoutHistoryStaysASingleSample() {
val properties = arrayOf(MotionEvent.PointerProperties().apply { id = 2; toolType = MotionEvent.TOOL_TYPE_FINGER })
val coords = arrayOf(MotionEvent.PointerCoords().apply { x = 7f; y = 8f })
val event = MotionEvent.obtain(0, 20, MotionEvent.ACTION_DOWN, 1, properties, coords, 0, 0, 1f, 1f, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0)
val split = event.pointerSubset(1 shl 2)!!
try {
assertEquals(0, split.historySize)
assertEquals(20L, split.eventTime)
assertEquals(MotionEvent.ACTION_DOWN, split.actionMasked)
assertEquals(7f, split.x, 0f)
assertNull(event.pointerSubset(1 shl 0))
} finally {
split.recycle()
event.recycle()
}
}
}
@@ -0,0 +1,426 @@
package com.droiddeck.launcher.input
import android.hardware.input.InputManager
import android.os.Looper
import android.view.InputDevice
import android.view.KeyEvent
import android.view.MotionEvent
import android.view.SurfaceView
import androidx.compose.runtime.MutableState
import androidx.compose.ui.geometry.Offset
import com.droiddeck.launcher.SessionActivity
import com.droiddeck.launcher.input.PenStream.Companion.PEN_IN
import com.droiddeck.launcher.input.PenStream.Companion.PEN_MIDDLE
import com.droiddeck.launcher.input.PenStream.Companion.PEN_RIGHT
import com.droiddeck.launcher.input.PenStream.Companion.PEN_TIP
import com.droiddeck.launcher.session.SessionPrefs
import com.droiddeck.launcher.session.SessionService
import com.droiddeck.launcher.session.SessionState
import com.droiddeck.launcher.wayland.WaylandCompositor
import java.time.Duration
import org.junit.After
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.Shadows.shadowOf
import org.robolectric.annotation.Config
import org.robolectric.annotation.Implementation
import org.robolectric.annotation.Implements
import org.robolectric.shadows.InputDeviceBuilder
import org.robolectric.shadows.ShadowInputDevice
import org.robolectric.util.ReflectionHelpers
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], manifest = Config.NONE, shadows = [SessionPenRoutingTest.CompositorShadow::class])
class SessionPenRoutingTest {
private lateinit var activity: SessionActivity
private val previousSize = SessionState.outputSize
private val previousMode = SessionState.mode
private val previousSteamUi = SessionState.steamUi
private val pen = MotionEvent.TOOL_TYPE_STYLUS
private val finger = MotionEvent.TOOL_TYPE_FINGER
private val stylusScreen = InputDevice.SOURCE_TOUCHSCREEN or InputDevice.SOURCE_STYLUS
@Before fun setUp() {
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(2))
activity = Robolectric.buildActivity(SessionActivity::class.java).get()
activity.window.decorView
activity.getSharedPreferences("session", 0).edit().clear().commit()
field("surfaceView", SurfaceView(activity).apply { layout(0, 0, 1000, 600) })
SessionState.outputSize = 1000 to 600
SessionState.mode = SessionService.MODE_DESKTOP
SessionState.steamUi = null
CompositorShadow.clear()
}
@After fun tearDown() {
shadowOf(Looper.getMainLooper()).idle()
SessionState.outputSize = previousSize
SessionState.mode = previousMode
SessionState.steamUi = previousSteamUi
}
@Test fun penHoverMovesThePointerAndTheCursorOnTheDesktopAndInSteam() {
assertTrue(activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 10, pen to 500f)))
assertEquals(listOf(Pen(PEN_IN, InputSpace.fixedX(500f, 1000), InputSpace.fixedY(300f, 600))), CompositorShadow.pens)
assertTrue(state<Boolean>("cursorVisible").value)
assertEquals(Offset(500f, 300f), state<Offset>("cursorPos").value)
steamDirect(SessionPrefs.PEN_MOUSE)
assertTrue(activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 20, pen to 600f)))
assertEquals(Pen(PEN_IN, InputSpace.fixedX(600f, 1000), InputSpace.fixedY(300f, 600)), CompositorShadow.pens.last())
assertEquals(Offset(600f, 300f), state<Offset>("cursorPos").value)
assertTrue(CompositorShadow.pointers.isEmpty())
assertTrue(CompositorShadow.touches.isEmpty())
}
@Test fun theSideButtonSettingDecidesWhatThePrimaryButtonSends() {
val cases = listOf(SessionPrefs.PEN_BUTTON_RIGHT to PEN_RIGHT, SessionPrefs.PEN_BUTTON_MIDDLE to PEN_MIDDLE,
SessionPrefs.PEN_BUTTON_OFF to 0)
for ((step, case) in cases.withIndex()) {
SessionPrefs.setPenSetting(activity, "penButton", case.first)
invoke("readPrefs")
CompositorShadow.pens.clear()
assertTrue(activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 10L + 10 * step, pen to 500f,
buttons = MotionEvent.BUTTON_STYLUS_PRIMARY)))
assertEquals(case.first, listOf(PEN_IN or case.second), CompositorShadow.pens.map { it.flags })
}
}
@Test fun penContactInMouseModeHoldsTheTipUntilItLifts() {
steamDirect(SessionPrefs.PEN_MOUSE)
assertTrue(activity.onTouchEvent(event(MotionEvent.ACTION_DOWN, 10, pen to 500f)))
assertTrue(activity.onTouchEvent(event(MotionEvent.ACTION_MOVE, 20, pen to 520f)))
assertTrue(activity.onTouchEvent(event(MotionEvent.ACTION_UP, 30, pen to 520f)))
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(PenStream.EXIT_GRACE_MS))
assertEquals(listOf(PEN_IN or PEN_TIP, PEN_IN or PEN_TIP, PEN_IN, 0), CompositorShadow.pens.map { it.flags })
assertTrue(CompositorShadow.touches.isEmpty())
}
@Test fun anExternalTabletTipReachesThePenInsteadOfTheMouse() {
steamDirect(SessionPrefs.PEN_MOUSE)
val source = InputDevice.SOURCE_MOUSE or InputDevice.SOURCE_STYLUS
assertTrue(activity.onTouchEvent(event(MotionEvent.ACTION_DOWN, 10, pen to 500f, source = source)))
assertEquals(listOf(PEN_IN or PEN_TIP), CompositorShadow.pens.map { it.flags })
assertTrue(CompositorShadow.pointers.isEmpty())
}
@Test fun penContactInTouchModeTakesTheFingerRouteAsBefore() {
steamDirect(SessionPrefs.PEN_TOUCH)
assertTrue(activity.onTouchEvent(event(MotionEvent.ACTION_DOWN, 10, pen to 500f)))
assertEquals(listOf(Touch(0, 0, InputSpace.x(500f, 1000), InputSpace.y(300f, 600))), CompositorShadow.touches)
activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 20, pen to 600f))
assertTrue(CompositorShadow.pens.isEmpty())
assertTrue(CompositorShadow.pointers.isEmpty())
}
@Test fun anExternalTabletStaysOnTheMousePathInTouchMode() {
steamDirect(SessionPrefs.PEN_TOUCH)
val source = InputDevice.SOURCE_MOUSE or InputDevice.SOURCE_STYLUS
assertTrue(activity.onTouchEvent(event(MotionEvent.ACTION_DOWN, 10, pen to 500f, source = source)))
assertTrue(CompositorShadow.touches.isEmpty())
assertTrue(CompositorShadow.pens.isEmpty())
}
@Test fun fingersKeepTheirRouteWhateverThePenMode() {
for (mode in listOf(SessionPrefs.PEN_MOUSE, SessionPrefs.PEN_TOUCH)) {
steamDirect(mode)
CompositorShadow.clear()
assertTrue(activity.onTouchEvent(event(MotionEvent.ACTION_DOWN, 10, finger to 500f, source = InputDevice.SOURCE_TOUCHSCREEN)))
assertEquals(listOf(Touch(0, 0, InputSpace.x(500f, 1000), InputSpace.y(300f, 600))), CompositorShadow.touches)
assertTrue(CompositorShadow.pens.isEmpty())
activity.onTouchEvent(event(MotionEvent.ACTION_CANCEL, 20, finger to 500f, source = InputDevice.SOURCE_TOUCHSCREEN))
}
}
@Test fun aFingerAndAPenInOneEventAreSplitByToolType() {
steamDirect(SessionPrefs.PEN_MOUSE)
activity.onTouchEvent(event(MotionEvent.ACTION_DOWN, 10, finger to 100f))
activity.onTouchEvent(event(MotionEvent.ACTION_POINTER_DOWN or (1 shl MotionEvent.ACTION_POINTER_INDEX_SHIFT), 20, finger to 110f, pen to 500f))
assertEquals(listOf(PEN_IN or PEN_TIP), CompositorShadow.pens.map { it.flags })
assertEquals(InputSpace.fixedX(500f, 1000), CompositorShadow.pens.last().x)
assertTrue(CompositorShadow.touches.isNotEmpty())
assertTrue(CompositorShadow.touches.all { it.id == 0 && it.x < InputSpace.x(200f, 1000) })
}
@Test fun theLowerScreenGameTakesPenHoverAndContact() {
steamDirect(SessionPrefs.PEN_MOUSE)
fun hover(event: MotionEvent) = ReflectionHelpers.callInstanceMethod<Boolean>(activity, "onBottomGameHover",
ReflectionHelpers.ClassParameter.from(MotionEvent::class.java, event))
fun touch(event: MotionEvent) = ReflectionHelpers.callInstanceMethod<Boolean>(activity, "onBottomGameTouch",
ReflectionHelpers.ClassParameter.from(MotionEvent::class.java, event))
assertTrue(hover(event(MotionEvent.ACTION_HOVER_MOVE, 10, pen to 500f)))
assertTrue(touch(event(MotionEvent.ACTION_DOWN, 20, pen to 500f, source = InputDevice.SOURCE_MOUSE or InputDevice.SOURCE_STYLUS)))
assertEquals(listOf(PEN_IN, PEN_IN or PEN_TIP), CompositorShadow.pens.map { it.flags })
SessionPrefs.setPenSetting(activity, "pen", SessionPrefs.PEN_TOUCH)
invoke("readPrefs")
assertFalse(hover(event(MotionEvent.ACTION_HOVER_MOVE, 30, pen to 500f)))
assertFalse(hover(event(MotionEvent.ACTION_HOVER_MOVE, 40, finger to 500f, source = InputDevice.SOURCE_MOUSE)))
assertEquals(listOf(PEN_IN, PEN_IN or PEN_TIP, 0), CompositorShadow.pens.map { it.flags })
}
@Test fun glassesAProgramPointerLockAndAppUiDropPenHover() {
state<Boolean>("glassesOutputActive").value = true
activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 10, pen to 500f))
state<Boolean>("glassesOutputActive").value = false
SessionState.mode = SessionService.MODE_STEAM
field("pointerLocked", true)
activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 20, pen to 500f))
field("pointerLocked", false)
state<Boolean>("achievementsOpen").value = true
activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 30, pen to 500f))
assertTrue(CompositorShadow.pens.isEmpty())
assertTrue(CompositorShadow.pointers.isEmpty())
}
@Config(sdk = [34])
@Test fun aPenNearTheDesktopReleasesTheMouseGrabUntilItLeaves() {
shadowOf(activity.getSystemService(InputManager::class.java)).addInputDevice(
InputDeviceBuilder.newBuilder().setId(11).setName("mouse").setSources(InputDevice.SOURCE_MOUSE).build())
field("desktopMousePlaced", true)
field("pointerLocked", true)
val start = android.os.SystemClock.uptimeMillis()
assertTrue(activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, start, pen to 500f)))
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(1))
assertEquals(listOf(RIGHT_CTRL to 1, RIGHT_CTRL to 0), CompositorShadow.keys)
field("pointerLocked", false)
invoke("grabDesktopMouse")
assertEquals(2, CompositorShadow.keys.size)
activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_EXIT, start + 1_000, pen to 500f))
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(PenStream.EXIT_GRACE_MS))
invoke("grabDesktopMouse")
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(1))
assertEquals(listOf(RIGHT_CTRL to 1, RIGHT_CTRL to 0, RIGHT_CTRL to 1, RIGHT_CTRL to 0), CompositorShadow.keys)
}
@Test fun openingAppUiEndsAHoveringPen() {
activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 10, pen to 500f))
state<Boolean>("achievementsOpen").value = true
activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 20, pen to 510f))
assertEquals(listOf(PEN_IN, 0), CompositorShadow.pens.map { it.flags })
}
@Test fun touchModeAndRouteChangesDeviceRemovalAndPauseEndThePen() {
invoke("readPrefs")
assertTrue(activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 10, pen to 500f)))
SessionPrefs.setTouchMode(activity, SessionPrefs.TOUCH_DIRECT)
invoke("readPrefs")
assertTrue(activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 20, pen to 500f)))
field("routedTouchMode", SessionPrefs.TOUCH_PAD)
invoke("applyTouchRouting")
assertTrue(activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 30, pen to 500f)))
ReflectionHelpers.getField<InputManager.InputDeviceListener>(activity, "deviceListener").onInputDeviceRemoved(6)
assertTrue(activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 40, pen to 500f)))
invoke("onPause")
assertEquals(listOf(PEN_IN, 0, PEN_IN, 0, PEN_IN, 0, PEN_IN, 0), CompositorShadow.pens.map { it.flags })
}
@Config(sdk = [34], shadows = [PadBridgeRoutingTest.RegisteredKeyEvent::class])
@Test fun aHeldPenKeyOutlivesATouchCancelButNotAFocusLoss() {
penKeyboard()
assertTrue(activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 10, pen to 500f)))
assertTrue(penKey(KeyEvent.ACTION_DOWN, 15))
invoke("cancelTouchGestures")
assertTrue(activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 20, pen to 500f)))
invoke("releaseHeldGuestInput")
assertTrue(activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 30, pen to 500f)))
val right = PEN_IN or PEN_RIGHT
assertEquals(listOf(PEN_IN, right, 0, right, 0, PEN_IN), CompositorShadow.pens.map { it.flags })
}
@Config(sdk = [34], shadows = [PadBridgeRoutingTest.RegisteredKeyEvent::class])
@Test fun aPenKeyIsAnOrdinaryKeyInTouchMode() {
penKeyboard()
assertTrue(activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 10, pen to 500f)))
assertTrue(penKey(KeyEvent.ACTION_DOWN, 15))
SessionPrefs.setPenSetting(activity, "pen", SessionPrefs.PEN_TOUCH)
invoke("readPrefs")
assertTrue(penKey(KeyEvent.ACTION_UP, 20))
assertFalse(penKey(KeyEvent.ACTION_DOWN, 25))
assertFalse(penKey(KeyEvent.ACTION_UP, 30))
assertEquals(listOf(PEN_IN, PEN_IN or PEN_RIGHT, 0), CompositorShadow.pens.map { it.flags })
}
@Test fun aFingerAndARelativePenOnTheTouchpadStayOneTwoPointerStream() {
state<Boolean>("glassesOutputActive").value = true
field("padMouseCheckedAt", android.os.SystemClock.uptimeMillis())
for (penFirst in listOf(false, true)) {
val pad = touchpad()
val first = if (penFirst) pen to 500f else finger to 100f
val second = if (penFirst) finger to 100f else pen to 500f
fun both(step: Int) = arrayOf(first.first to first.second + 10f * step, second.first to second.second + 10f * step)
activity.onTouchEvent(event(MotionEvent.ACTION_DOWN, 10_000, first))
activity.onTouchEvent(event(MotionEvent.ACTION_POINTER_DOWN or (1 shl MotionEvent.ACTION_POINTER_INDEX_SHIFT), 10_010, *both(0)))
for (step in 1..4) activity.onTouchEvent(event(MotionEvent.ACTION_MOVE, 10_010L + 10 * step, *both(step)))
activity.onTouchEvent(event(MotionEvent.ACTION_POINTER_UP or (1 shl MotionEvent.ACTION_POINTER_INDEX_SHIFT), 10_060, *both(4)))
activity.onTouchEvent(event(MotionEvent.ACTION_UP, 10_070, first.first to first.second + 40f))
assertTrue("penFirst=$penFirst", pad.scrolls.isNotEmpty())
assertTrue("penFirst=$penFirst ${pad.moves}", pad.moves.all { it in 450f..550f })
assertTrue(CompositorShadow.pens.isEmpty())
}
}
@Test fun aRelativePenStrokeThatAndroidCanceledDoesNotClick() {
steamDirect(SessionPrefs.PEN_MOUSE)
state<Boolean>("glassesOutputActive").value = true
val pad = touchpad()
activity.onTouchEvent(event(MotionEvent.ACTION_DOWN, 10_000, finger to 100f))
activity.onTouchEvent(event(MotionEvent.ACTION_POINTER_DOWN or (1 shl MotionEvent.ACTION_POINTER_INDEX_SHIFT), 10_010, finger to 100f, pen to 500f))
activity.onTouchEvent(event(MotionEvent.ACTION_POINTER_UP or (1 shl MotionEvent.ACTION_POINTER_INDEX_SHIFT), 10_050, finger to 100f, pen to 500f,
flags = MotionEvent.FLAG_CANCELED))
activity.onTouchEvent(event(MotionEvent.ACTION_UP, 10_060, finger to 100f))
activity.onTouchEvent(event(MotionEvent.ACTION_DOWN, 20_000, pen to 500f))
activity.onTouchEvent(event(MotionEvent.ACTION_UP, 20_050, pen to 500f, flags = MotionEvent.FLAG_CANCELED))
assertTrue(pad.presses.isEmpty())
assertTrue(CompositorShadow.touches.isNotEmpty())
activity.onTouchEvent(event(MotionEvent.ACTION_DOWN, 30_000, pen to 500f))
activity.onTouchEvent(event(MotionEvent.ACTION_UP, 30_050, pen to 500f))
assertEquals(listOf(PointerGestures.BTN_LEFT), pad.presses)
assertTrue(CompositorShadow.pens.isEmpty())
}
@Test fun aTouchCancelAfterAFingerLiftsEndsTheRelativePenStroke() {
steamDirect(SessionPrefs.PEN_MOUSE)
state<Boolean>("glassesOutputActive").value = true
val pad = touchpad()
activity.onTouchEvent(event(MotionEvent.ACTION_DOWN, 10_000, pen to 500f))
activity.onTouchEvent(event(MotionEvent.ACTION_POINTER_DOWN or (1 shl MotionEvent.ACTION_POINTER_INDEX_SHIFT), 10_010, pen to 500f, finger to 100f))
activity.onTouchEvent(event(MotionEvent.ACTION_POINTER_UP or (1 shl MotionEvent.ACTION_POINTER_INDEX_SHIFT), 10_020, pen to 500f, finger to 100f))
invoke("cancelTouchGestures")
activity.onTouchEvent(event(MotionEvent.ACTION_UP, 10_050, pen to 500f))
assertTrue(pad.presses.isEmpty())
activity.onTouchEvent(event(MotionEvent.ACTION_DOWN, 20_000, pen to 500f))
activity.onTouchEvent(event(MotionEvent.ACTION_UP, 20_050, pen to 500f))
assertEquals(listOf(PointerGestures.BTN_LEFT), pad.presses)
}
@Test fun changingAPenSettingEndsThePenAndRereadingTheSameSettingsDoesNot() {
assertTrue(activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 10, pen to 500f)))
invoke("readPrefs")
assertEquals(listOf(PEN_IN), CompositorShadow.pens.map { it.flags })
for ((step, setting) in listOf("penButton" to SessionPrefs.PEN_BUTTON_MIDDLE, "pen" to SessionPrefs.PEN_TOUCH).withIndex()) {
assertTrue(activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 20L + 10 * step, pen to 500f)))
SessionPrefs.setPenSetting(activity, setting.first, setting.second)
invoke("readPrefs")
assertEquals(setting.first, 0, CompositorShadow.pens.last().flags)
}
}
@Test fun theFirstPenEventRemembersThatThePhoneHasAPen() {
invoke("readPrefs")
assertFalse(state<Boolean>("penSeen").value)
assertTrue(activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 10, pen to 500f)))
assertTrue(state<Boolean>("penSeen").value)
assertTrue(SessionPrefs.penSeen(activity))
}
@Config(sdk = [34])
@Test fun aConnectedStylusDeviceCountsAsSeenBeforeAnyPenEvent() {
invoke("readPrefs")
assertFalse(state<Boolean>("penSeen").value)
shadowOf(activity.getSystemService(InputManager::class.java)).addInputDevice(
InputDeviceBuilder.newBuilder().setId(42).setName("digitizer").setSources(stylusScreen).build())
invoke("readPrefs")
assertTrue(state<Boolean>("penSeen").value)
assertTrue(SessionPrefs.penSeen(activity))
}
@Config(sdk = [33])
@Test fun beforeAndroid14ATouchscreenWithTheStylusBitWaitsForAPenEvent() {
shadowOf(activity.getSystemService(InputManager::class.java)).addInputDevice(
ShadowInputDevice.makeInputDeviceNamed("touchscreen").also {
ReflectionHelpers.setField(it, "mId", 42)
ReflectionHelpers.setField(it, "mSources", stylusScreen)
})
assertEquals(listOf(42), InputDevice.getDeviceIds().toList())
invoke("readPrefs")
assertFalse(state<Boolean>("penSeen").value)
assertFalse(SessionPrefs.penSeen(activity))
assertTrue(activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 10, pen to 500f)))
assertTrue(state<Boolean>("penSeen").value)
}
@Config(sdk = [34])
@Test fun aStylusDeviceIsNotAHardwareMouse() {
fun device(sources: Int) = InputDeviceBuilder.newBuilder().setId(7).setName("device").setSources(sources).build()
fun mouse(sources: Int) = ReflectionHelpers.callInstanceMethod<Boolean>(activity, "isHardwareMouse",
ReflectionHelpers.ClassParameter.from(InputDevice::class.java, device(sources)))
assertTrue(mouse(InputDevice.SOURCE_MOUSE))
assertFalse(mouse(InputDevice.SOURCE_MOUSE or InputDevice.SOURCE_STYLUS))
assertFalse(mouse(InputDevice.SOURCE_MOUSE or InputDevice.SOURCE_STYLUS or InputDevice.SOURCE_KEYBOARD))
assertFalse(mouse(stylusScreen))
}
private fun steamDirect(mode: String) {
SessionPrefs.setPenSetting(activity, "pen", mode)
invoke("readPrefs")
SessionState.mode = SessionService.MODE_STEAM
field("routedTouchMode", SessionPrefs.TOUCH_DIRECT)
field("padMouseCheckedAt", android.os.SystemClock.uptimeMillis())
field("threeFingerTap", ThreeFingerTap(8f))
field("directTouchHold", DirectTouchHold(8f, object : PointerGestures.Listener {
override fun onMove(x: Float, y: Float) {}
override fun onButton(button: Int, pressed: Boolean, x: Float, y: Float) {}
override fun onWheel(steps: Int) {}
override fun onLongPress() {}
}, ReflectionHelpers.getField(activity, "directTouchSink")).also {
it.configure(TouchGestureConfig(directHoldBehavior = TouchGestureConfig.MOUSE_BEHAVIOR_NONE))
})
}
private fun penKeyboard() = shadowOf(activity.getSystemService(InputManager::class.java)).addInputDevice(
InputDeviceBuilder.newBuilder().setId(10).setName("OPPO AI Pen").setSources(InputDevice.SOURCE_KEYBOARD).setExternal(true)
.setKeyboardType(InputDevice.KEYBOARD_TYPE_NON_ALPHABETIC).build())
private fun penKey(action: Int, time: Long) =
activity.dispatchKeyEvent(KeyEvent(time, time, action, KeyEvent.KEYCODE_UNKNOWN, 0, 0, 10, 191, 0, InputDevice.SOURCE_KEYBOARD))
private fun event(action: Int, time: Long, vararg pointers: Pair<Int, Float>, source: Int = stylusScreen, flags: Int = 0,
buttons: Int = 0): MotionEvent {
val properties = Array(pointers.size) { MotionEvent.PointerProperties().apply { id = it; toolType = pointers[it].first } }
val coords = Array(pointers.size) { MotionEvent.PointerCoords().apply { x = pointers[it].second; y = 300f; pressure = 0.5f } }
return MotionEvent.obtain(0, time, action, pointers.size, properties, coords, 0, buttons, 1f, 1f, 6, 0, source, flags)
}
private class Pad : PointerGestures.Listener {
val moves = mutableListOf<Float>()
val scrolls = mutableListOf<Float>()
val presses = mutableListOf<Int>()
override fun onMove(x: Float, y: Float) { moves += x }
override fun onButton(button: Int, pressed: Boolean, x: Float, y: Float) { if (pressed) presses += button }
override fun onWheel(steps: Int) {}
override fun onLongPress() {}
override fun onScroll(dx: Float, dy: Float) { scrolls += dx }
}
private fun touchpad() = Pad().also { field("touchpad", TouchpadGestures(8f, it)) }
private fun field(name: String, value: Any) = ReflectionHelpers.setField(activity, name, value)
private fun invoke(name: String) = ReflectionHelpers.callInstanceMethod<Any?>(activity, name)
private fun <T> state(name: String): MutableState<T> = ReflectionHelpers.getField(activity, "$name\$delegate")
private companion object { const val RIGHT_CTRL = 97 }
data class Pen(val flags: Int, val x: Int, val y: Int)
data class Touch(val action: Int, val id: Int, val x: Int, val y: Int)
@Implements(value = WaylandCompositor::class, isInAndroidSdk = false)
class CompositorShadow {
companion object {
val pens = mutableListOf<Pen>()
val touches = mutableListOf<Touch>()
val pointers = mutableListOf<Triple<Int, Int, Int>>()
val keys = mutableListOf<Pair<Int, Int>>()
fun clear() { pens.clear(); touches.clear(); pointers.clear(); keys.clear() }
@JvmStatic @Implementation fun __staticInitializer__() {}
@JvmStatic @Implementation fun nativeSendPen(flags: Int, x: Int, y: Int) { pens += Pen(flags, x, y) }
@JvmStatic @Implementation fun nativeSendTouch(action: Int, id: Int, x: Int, y: Int) { touches += Touch(action, id, x, y) }
@JvmStatic @Implementation fun nativeSendPointer(action: Int, x: Int, y: Int) { pointers += Triple(action, x, y) }
@JvmStatic @Implementation fun nativeSendSceneInput(type: Int, code: Int, value: Int) {}
@JvmStatic @Implementation fun nativeSendKey(code: Int, value: Int) { keys += code to value }
@JvmStatic @Implementation fun nativeFocusTakesTouch(): Boolean = false
}
}
}
@@ -34,6 +34,9 @@ class SettingsResetTest {
@Test fun settingsGoBackToTheirDefaults() {
SessionPrefs.setTheme(app, "ocean")
SessionPrefs.setBackDoubleTapMs(app, 100)
SessionPrefs.setPenSetting(app, "pen", SessionPrefs.PEN_TOUCH)
SessionPrefs.setPenSetting(app, "penButton", SessionPrefs.PEN_BUTTON_OFF)
SessionPrefs.setPenSeen(app)
SessionPrefs.setUnfoldedControlsWithController(app, true)
SessionPrefs.setNoXalia(app, false)
session.edit().putInt("fpsLimit.steam", 30).commit()
@@ -58,6 +61,8 @@ class SettingsResetTest {
assertEquals("graphite", SessionPrefs.theme(app))
assertEquals(500, SessionPrefs.backDoubleTapMs(app))
assertEquals(SessionPrefs.Pen(), SessionPrefs.pen(app))
assertTrue(SessionPrefs.penSeen(app))
assertFalse(SessionPrefs.unfoldedControlsWithController(app))
assertTrue(SessionPrefs.noXalia(app))
assertFalse(session.contains("fpsLimit.steam"))
@@ -82,6 +87,26 @@ class SettingsResetTest {
assertFalse(prefs("steam_touch").contains("gyro"))
}
@Test fun penSettingsKeepOnlyKnownValues() {
val settings = mapOf(
"pen" to listOf(SessionPrefs.PEN_MOUSE, SessionPrefs.PEN_TOUCH),
"penButton" to listOf(SessionPrefs.PEN_BUTTON_RIGHT, SessionPrefs.PEN_BUTTON_MIDDLE, SessionPrefs.PEN_BUTTON_OFF),
)
fun read(key: String) = if (key == "pen") SessionPrefs.penMode(app) else SessionPrefs.penButton(app)
for ((key, values) in settings) {
assertTrue(key, SettingsReset.isSessionSetting(key))
assertEquals(key, values.first(), read(key))
for (value in values.drop(1)) {
SessionPrefs.setPenSetting(app, key, value)
assertEquals(key, value, read(key))
}
session.edit().putString(key, "left").commit()
assertEquals(key, values.first(), read(key))
assertThrows(IllegalArgumentException::class.java) { SessionPrefs.setPenSetting(app, key, "left") }
}
assertFalse(SettingsReset.isSessionSetting("penSeen"))
}
@Test fun aFailedDebugOptOutDoesNotHideTheEnabledPreference() {
assertTrue(SessionPrefs.setGameDebugLogsEnabled(app, true))
val directory = java.io.File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(app),
@@ -98,6 +98,24 @@ class InputSurfaceTouchTest {
assertFalse(state().isDown(PadState.A))
}
@Test fun aPenPressesButtonsLikeAFingerAndItsMissesKeepTheirHistory() {
touch(MotionEvent.ACTION_DOWN, 1 to (800f to 240f), tool = MotionEvent.TOOL_TYPE_STYLUS)
assertTrue(state().isDown(PadState.A))
touch(MotionEvent.ACTION_UP, 1 to (800f to 240f), tool = MotionEvent.TOOL_TYPE_STYLUS)
assertFalse(state().isDown(PadState.A))
val missed = mutableListOf<List<Long>>()
view.onTouchMiss = { event -> missed += (0 until event.historySize).map { event.getHistoricalEventTime(it) } + event.eventTime }
touch(MotionEvent.ACTION_DOWN, 1 to (500f to 100f), tool = MotionEvent.TOOL_TYPE_STYLUS)
val properties = arrayOf(MotionEvent.PointerProperties().apply { id = 1; toolType = MotionEvent.TOOL_TYPE_STYLUS })
fun coords(x: Float) = arrayOf(MotionEvent.PointerCoords().apply { this.x = x; y = 100f; pressure = 0.5f })
val move = MotionEvent.obtain(1000L, 2000L, MotionEvent.ACTION_MOVE, 1, properties, coords(510f), 0, 0, 1f, 1f, 0, 0, 0, 0)
move.addBatch(2003L, coords(520f), 0)
move.addBatch(2006L, coords(530f), 0)
try { view.dispatchTouchEvent(move) } finally { move.recycle() }
assertEquals(listOf(listOf(time - 1), listOf(2000L, 2003L, 2006L)), missed)
assertFalse(state().isDown(PadState.A))
}
@Test fun keyboardShortcutOpensOnRelease() {
touch(MotionEvent.ACTION_DOWN, 1 to (450f to 510f))
assertTrue(events.isEmpty())
@@ -0,0 +1,99 @@
package com.droiddeck.launcher.ui
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.*
import com.droiddeck.launcher.R
import com.droiddeck.launcher.gpu.FrameGen
import com.droiddeck.launcher.gpu.Lossless
import com.droiddeck.launcher.input.SecondScreenMode
import com.droiddeck.launcher.session.SessionPrefs
import com.droiddeck.launcher.session.SessionService
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], qualifiers = "w800dp-h600dp")
@GraphicsMode(GraphicsMode.Mode.NATIVE)
class PenSettingsGroupTest {
@get:Rule val compose = createRobolectricComposeRule()
private val context get() = RuntimeEnvironment.getApplication()
@Test fun theDrawerHasNoPenGroupUntilAPenIsKnown() {
compose.setContent { DroidDeckTheme { SessionDrawer(true, SessionDrawerPage.CONTROLLER, false, {}, actions(pen = null)) } }
compose.onNodeWithTag("setting-touch").assertExists()
compose.onNodeWithTag("setting-pen").assertDoesNotExist()
compose.onNodeWithTag("setting-pen-button").assertDoesNotExist()
}
@Test fun theDrawerSavesPenPicks() {
val picks = mutableListOf<Pair<String, String>>()
compose.setContent {
DroidDeckTheme {
SessionDrawer(true, SessionDrawerPage.CONTROLLER, false, {}, actions(SessionPrefs.Pen()) { k, v -> picks += k to v })
}
}
compose.onNodeWithTag("setting-pen-button").performScrollTo().performClick()
compose.onNodeWithText(context.getString(R.string.gesture_middle_click)).performScrollTo().performClick()
compose.onNodeWithTag("setting-pen").performScrollTo().performClick()
compose.onNodeWithText(context.getString(R.string.mode_pen_touch)).performScrollTo().performClick()
compose.runOnIdle {
assertEquals(listOf("penButton" to SessionPrefs.PEN_BUTTON_MIDDLE, "pen" to SessionPrefs.PEN_TOUCH), picks)
}
}
@Test fun theSideButtonRowIsHiddenInTouchMode() {
val pen = mutableStateOf(SessionPrefs.Pen())
compose.setContent { DroidDeckTheme { Column { PenSettingsGroup(rememberMenuHost(), pen.value) { _, _ -> } } } }
compose.onNodeWithTag("setting-pen-button").assertExists()
compose.runOnIdle { pen.value = SessionPrefs.Pen(mode = SessionPrefs.PEN_TOUCH) }
compose.onNodeWithTag("setting-pen").assertExists()
compose.onNodeWithTag("setting-pen-button").assertDoesNotExist()
}
@Test fun theControlsTabShowsThePenGroupAfterTheTouchRowsOnceAPenIsKnown() {
val pen = mutableStateOf<SessionPrefs.Pen?>(null)
val picks = mutableListOf<Pair<String, String>>()
compose.setContent {
DroidDeckTheme {
Column(Modifier.verticalScroll(rememberScrollState())) {
ModeSheetRows(ModeSettings(mode = SessionService.MODE_DESKTOP, resolution = "auto", hdr = false, hdrReason = null,
touchMode = "auto", pen = pen.value, suspendPolicy = "auto", oscMode = "auto", directAudio = null, mic = null),
ModeSettingsActions(onResolution = {}, onHdr = {}, onTouch = {}, onPen = { k, v -> picks += k to v },
onSuspendPolicy = {}, onOsc = {}, onInputSettings = {}, onDirectAudio = {}, onMic = {}, onDismiss = {}),
SheetTab.CONTROLS)
}
}
}
compose.onNodeWithTag("setting-touch").assertExists()
compose.onNodeWithTag("setting-pen").assertDoesNotExist()
compose.runOnIdle { pen.value = SessionPrefs.Pen() }
compose.onNodeWithTag("setting-pen-button").assertExists()
assertTrue(compose.onNodeWithTag("setting-touch").fetchSemanticsNode().positionInRoot.y <
compose.onNodeWithTag("setting-pen").fetchSemanticsNode().positionInRoot.y)
compose.onNodeWithTag("setting-pen-button").performScrollTo().performClick()
compose.onNodeWithText(context.getString(R.string.gesture_middle_click)).performScrollTo().performClick()
compose.runOnIdle { assertEquals(listOf("penButton" to SessionPrefs.PEN_BUTTON_MIDDLE), picks) }
}
private fun actions(pen: SessionPrefs.Pen?, onPen: (String, String) -> Unit = { _, _ -> }) =
DrawerActions(steam = false, desktop = true, isHomeApp = false, androidApps = emptyList(), hudOn = false,
frameGen = FrameGen.Mode.OFF, lossless = Lossless.State.NONE, oscMode = "never",
suspendPolicy = "auto", backActionsInverted = false,
touchMode = "auto", touchAuto = "touchpad", pen = pen, onPen = onPen, fexPreset = "default",
secondScreenMode = SecondScreenMode.NONE, secondScreenDisplays = emptyList(), selectedSecondScreenDisplay = 1,
onHud = {}, onFrameGenPick = {}, onImportLossless = {}, onKeyboard = {}, onHardwareKeyboard = {},
onSteamMenu = null, onQam = null, onOsc = {}, onSuspendPolicy = {}, onBackActionsInverted = {},
onTouch = {}, onFexPreset = {}, onSecondScreenMode = {}, onSecondScreenDisplay = {},
onLaunchAndroidApp = { _, _ -> }, onBackground = {}, onShareLogs = {}, onStop = {}, onClose = {})
}