Repository navigation
Game controllers, mouse look and held keys for Linux games (refs #163) - #314
Open
szymonkucko wants to merge 1 commit into
Open
szymonkucko wants to merge 1 commit into
szymonkucko wants to merge 1 commit into
Conversation
…becomes an Xbox 360 pad in the guest, found through /dev/input and udev's records (SDL, gilrs, RetroArch), a game that locks the pointer gets the mouse captured to look around with, and a physical keyboard's held keys stay held instead of turning into taps Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linux games can only be played by touch today. This PR lets them use what's connected to the phone: a game controller becomes a real evdev pad in the guest, a game that locks the pointer gets the mouse captured with relative motion, and a physical keyboard's held keys stay held. Programs that use none of this see no change, and a pad still moves around the launcher whenever no Linux program has it open.
Refs #163 (mouse and pointer capture for desktop use). Here the game asks for capture through pointer-constraints and lets go the same way; there's no shortcut to toggle it.
How it works
linux/Gamepads.kt,linux/PadLayout.kt,patches/proot/gamepads/gamepads.c): the app can't create devices in /dev/input, so each pad Android sees is a unix socketfiles/input/eventN, bound over the guest's/dev/input.libgamepads.sois a freestanding library like the fast lane, built byfetch-proot.shand preloaded ahead of it. It turnsopen("/dev/input/eventN")into a connect and reads a description of an Xbox 360 pad (xpad's layout, 045e:028e). It answers evdev's ioctls (EVIOCGBIT,EVIOCGABS,EVIOCGNAME,EVIOCGID, …) from that description, andstat/fstatreport a character device 13:(64+N). The program reads realinput_events from the socket. SDL and gilrs find pads by watching /dev/input (SDL_JOYSTICK_DISABLE_UDEV=1,GILRS_DISABLE_UDEV=1), including hotplug.UdevRecordswrites udev's record of each pad into the /sys stand-in and into/run/udev/data, a new bind offiles/udev. systemd 262's libudev refuses entries that aren't on a real sysfs, so the guest getsSYSTEMD_DEVICE_VERIFY_SYSFS=0. No udev daemon runs, so these programs see the pads that are there when they start.Gamepads.isPad, unit-tested; a Razer Ornata V3 reports KEYBOARD | DPAD | JOYSTICK).wayland/PointerConstraints.kt,wayland/Input.kt,ui/WindowManager.kt,LinuxWindowActivity):zwp_pointer_constraints_v1andzwp_relative_pointer_manager_v1. A lock captures the mouse for the window's SurfaceView (requestPointerCapture) and sends relative motion. The pointer stays where it was locked and doesn't leave the surface, because winit only unlocks a pointer that is over its window. Android lets go of the capture when the window loses focus.ui/Keyboard.kt,KeyboardBridge.preIme): while the soft keyboard is wanted, Samsung Keyboard turned a held physical key into an instant press and release, so W in a game was a tap. Keys from a physical alphabetic keyboard are now taken indispatchKeyEventPreIme, before the keyboard app. AltGr, Super and characters the US layout types differently still go the old way. In a window that locked the pointer, Android's key repeat is no longer replayed as release and press.Limitations
EVIOCSFFfails and the pad reports 0 effects.statxisn't hooked, so coreutilsstatstill shows a socket. SDL and RetroArch usefstatandstat.Relation to open PRs
None of the open PRs adds controllers or pointer locking. I applied every open PR that touches these files on top of this branch. The conflicts this branch adds are all neighbouring lines: imports (#153, #222), the locked-pointer check at the top of
Input.pointerMotionnext to the drag handling (#220, #221), new fields side by side inWindowManager(#40, #128), and paragraphs in ARCHITECTURE.md (#313). I'm happy to rebase on whichever lands first.Tested
./gradlew :owl:test :app:testFossDebugUnitTest :owl:owlJar :app:assembleFossDebug :app:lintFossDebugpasses, and:app:lintPlayDebug(locally: 342 app tests, 238 owl tests, 0 lint errors). New tests:PadLayoutTest,GamepadsTest,UdevRecordsTest.libgamepads.sois a new managed file in/usr/local/lib(Policy.Owned).files/inputandfiles/udevare new directories bound into the guest and created on every start; sockets and records of an earlier run are cleared at start. Nothing to migrate.On the phone (Snapdragon 8 Gen 3):
/dev/input/event0, libudev lists it, andstatgives char 13:64.Trying it
Pair a controller, open a Linux terminal and
ls /dev/input: there's aneventNper pad. Then e.g.sudo pacman -S supertuxkartand play with the pad, or with mouse and keyboard in any game that locks the pointer.🤖 Generated with Claude Code