Add touch screen support

A blind user can now run the desktop with the touch screen as the only
input, in the style of TalkBack, VoiceOver and NVDA touch. It is off by
default: "Use the touch screen with gestures" in preferences, the
"Touch screen" quick setting, or Cthulhu+Ctrl+Alt+T (toggle-touch-screen).

Input: internal/platform/evdev reads the touch screen from the Linux input
layer in pure Go and grabs it with EVIOCGRAB while touch is on, so no other
program sees touches until it is turned off. It needs read access to
/dev/input (the input group, as Fenrir already needs); Cthulhu never uses
sudo. internal/touch recognizes taps, double and triple taps, holds, double
tap and hold, flicks, two finger rotation and up to ten fingers.

Gestures send Cthulhu's keyboard commands through the normal command
dispatch. Modes, chosen with a three finger tap, each have their own rotor:
navigation (default: items, then scroll, windows, workspaces or
notifications), text (lines, words, characters), browse (page order, then
element types; entered automatically on web pages), object (tree) and
speech settings. Exploring speaks what is under the finger and moves object
review there; double tap activates. docs/touch-support.md has the full
gesture table, design, testing notes and open issues.

Supporting changes:
- Object review gains next and previous item in reading order, skipping
  unnamed containers, and object-activate, which runs the default action of
  the object of interest. Its results no longer need a known focus, because
  a touch user may never produce a focus event.
- browserModeController exposes Browsing for other goroutines.
- internal/i3command sends i3 commands; internal/i3ipc stays observe-only.
- X11 helpers find the client under a point and send XTest clicks and keys.
  The window lookup releases the X11 guard before the XRes fallback, which
  takes the guard itself; a native test reproduces the old deadlock.
- Mouse review stays quiet for one second after touch input.

Tested live on a Lenovo Yoga 7 2-in-1 14AKP10 (Wacom HID 53FC, ten touch
points) under i3, MATE and in Brave, Thunar and GTK dialogs. Not yet
handled: the lock screen, rotation and multiple monitors, pass-through, and
touch typing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ChaseandClaude Opus 5.5 authored and Storm Dragon committed 2026-11-24 19:09:45 -05:00
1 parent 418b72329e
commit e68d2fa440
39 files changed
+3492 -49

No files matched your search

+219
View File
@@ -0,0 +1,219 @@
# Touch Screen Support
Goal: a blind user can run the whole Linux desktop with the touch screen as the
only input, the way TalkBack, VoiceOver and NVDA touch work. Touch is its own
subsystem with its own gestures, bindings and modes. It shares only the
"what is at this point" hit test with mouse review.
Branch: `touch-support`, based on `testing`. Requested by Storm Dragon.
## Design
- `internal/platform/evdev`: reads the touch screen directly from the Linux
input layer, pure Go with no cgo. It finds direct multitouch devices
(`INPUT_PROP_DIRECT` with `ABS_MT_SLOT`, positions and tracking IDs), grabs
the device with `EVIOCGRAB` while touch is on, and turns multitouch
protocol B frames into begin, update and end contacts in screen pixels. While
grabbed, the X server and every other program get no touches; releasing the
grab gives them back. Requires read access to `/dev/input`: the user must be
in the `input` group (or an equivalent udev rule), as Fenrir already needs.
Cthulhu speaks a message once if access is denied.
- `internal/platform/xorg/touch.go`, `touch_native.c`, `touch_native.h`: the
only X11 parts. A `WindowLocator` on its own X connection finds the client
PID under a point (`_NET_WM_PID`, then XRes) and clicks with XTest for
activation. No XInput2 touch grab is used.
- `internal/touch`: pure Go gesture recognizer, no native code. Callers feed
timestamped contacts and call `Tick`. Recognizes 1 to 4 finger tap, double
tap, triple tap, hold, flicks in four directions, double tap and hold, two
finger rotation, and up to ten fingers. One finger held past 200 ms explores
instead of gesturing, so quick flicks never speak. Taps wait 350 ms for more
taps. Contact state is bounded at 64 and lifted slots are reused, so finger
bounces can never lose a lift.
- `internal/app/touch.go`: lifecycle service. Grabs only while
`Reading.EnableTouchScreen` is on and the focus gate is not locked. Hit tests
run in a separate worker that keeps only the latest point.
- Setting: `enable-touch-screen` in `[profiles.<name>.presentation.reading]`,
default off. Preferences checkbox "Use the touch screen with gestures" and
quick toggle "Touch screen".
- Keyboard: `toggle-touch-screen`, Cthulhu+Ctrl+Alt+T (as NVDA+Ctrl+Alt+T),
flips the quick toggle for the session and says "Touch screen on" or "off".
Saving speech settings keeps it.
## Current gestures
Gestures map to Cthulhu's keyboard commands, so touch and keyboard users
reach the same features. The mapping lives in `internal/app/touch_navigation.go`
as one table per mode, and every row below is tested in
`touch_navigation_test.go`. Rules from testers: within a mode every gesture
does one thing; shared gestures mean the same in every mode; every mode has
its own rotor and no two modes share a rotor list. Each mode remembers its
own rotor position.
Shared by every mode:
- One finger rest or drag: speak what is under the finger (line of text over
unnamed containers). Lifting moves object review there.
- One finger tap: speak it again. Double tap: activate what was last moved
(click an explored point, `object-activate` after an object move or Tab,
`document-activate` after a browse move). In speech settings mode, double
tap saves.
- Double tap and hold: right click an explored point, or press the context
menu key after an object move.
- Two finger tap: stop speech. Two finger triple tap: Escape. Two finger
rotate: the current mode's rotor.
- Three finger tap: next mode. Three finger flick right and left: Tab and
Shift+Tab. Down: `read-all`. Up: `present-window-title`.
- Four finger tap: `present-last-notification`. Double tap:
`show-notification-list`.
Modes, in three finger tap order:
- Navigation mode (default, like TalkBack): flick right and left
`object-next-item` and `object-previous-item`. Rotor chooses flick down and
up: Scroll (mouse wheel at the last touch), Windows and Workspaces (i3), or
Notifications (next and previous).
- Text mode: rotor chooses Lines, Words or Characters. Flick right and left
move by the unit, down reads the current one, up spells it (phonetic for
characters). Flat review commands.
- Browse mode: flick right and left move the browse cursor by line in page
order, like the Down and Up arrows. Rotor chooses headings, links,
buttons, form fields, landmarks, tables, lists, list items, paragraphs,
images, check boxes, combo boxes, radio buttons or clickables; flick down
and up move by it. Entered by itself on a
web page and left again with it, unless chosen by hand.
- Object mode: flick right and left siblings, up parent, down first child.
No rotor.
- Speech settings mode: flick right and left choose a setting, up and down
change it; the rotor changes category.
Touch commands enter the keyboard command dispatch through
`commandRuntime.touchCommands`, so gestures behave exactly like the bound
keys. The three new commands have no default keys yet.
Hit testing (`internal/atspi/mouse_review_native.go`, shared with mouse
review) now scans the children of the object where the provider's own hit
test stopped. Chromium stopped at tables, so cells were never reached.
## Roadmap
1. Done: direct touch screen input, recognizer, explore by touch, activate, stop speech.
2. Done: item navigation, rotor, web mode, Tab, Shift+Tab and Escape.
Still to add: Enter outside web mode.
3. Rotor done. Later: continuous rotation while turning, and per mode lists.
4. Desktop gestures through i3: switch windows and workspaces, launcher,
notifications.
5. Touch typing: an on-screen keyboard explored by finger, lift to type.
Braille screen input later.
6. Pass-through mode and double tap and hold pass-through for sliders and
drags; gesture remapping in preferences.
## Open issues
- Lock screen: Stormux enables I38lock by default on new installs. Touch is
turned off while the focus gate is locked, so a touch-only user cannot
unlock. Needs touch on the lock screen plus touch typing for the password.
- Activation clicks at the explored point. AT-SPI actions may be better for
some widgets.
- Only X11 is supported. Wayland needs a compositor protocol and is deferred.
- Coordinates map the whole touch range onto the X screen. Rotation (tablet
mode) and multiple monitors are not handled yet.
- Pass-through could use uinput to replay touches to the desktop as a virtual
touch screen. Not built yet.
- Packaging must tell users to join the `input` group.
- App survey on the test laptop (32 point hit test grid per window):
Shelly (Avalonia) exposes nothing; Mousepad reports one text object with no
text at the point; PCManFM list view and Thunar list view find file names;
GTK dialogs (Thunar preferences, Mumble wizard, preferred applications)
find labels, check boxes and combo boxes; qv4l2, qvidcap and tkremind opened
no window in time.
- Thunar's icon view exposes one empty panel and no items, so files cannot
be explored by touch there. Thunar's detailed list view exposes table rows
and cells. Hit testing now also searches up to three levels below where the
provider stops (GTK notebooks report page tabs as only their label).
- Tests in `internal/app` read the real session bus. When I38lock is active
they fail on an unchanged tree too. Run them under `dbus-run-session --`.
## Testing
- Automated: `dbus-run-session -- go test ./internal/touch ./internal/platform/evdev ./internal/i3command ./internal/review ./internal/app ./internal/config ./internal/preferences ./internal/platform/xorg -count=1`.
`internal/app` tests read the real session bus, so run them under
`dbus-run-session` or they fail while a screen lock is active.
- Native X11: `CTHULHU_NATIVE_X11=1 xvfb-run -a -s "-screen 0 1280x800x24" go test ./internal/platform/xorg -run TestNativeWindowLocator`
(needs xterm, xdotool and xprop). Real touch device discovery:
`CTHULHU_NATIVE_EVDEV=1 go test ./internal/platform/evdev -run TestNativeFindTouchScreens`.
- Live: run `build/cthulhu --replace --config <copy of your settings> --debug-file <log>`
with `enable-touch-screen = true` in the copy, and keep a way back to the
installed reader. Use a separate settings file: the testing branch writes
settings schema 3, which master refuses to load. Touch gestures are logged
at debug level as `touch gesture`; silent explore points as
`touch review silent` with a reason.
- Testers used local helper scripts (switching between the test and
installed builds, a spoken gesture trainer, an app hit test survey). They
are not part of this repository.
- Test hardware: Lenovo Yoga 7 2-in-1 14AKP10, touch screen
"Wacom HID 53FC Finger", 10 touch points, 1920x1200, Stormux on XLibre
with i3, MATE and SonicDE.
## Log
- 2026-11-24: Spoken trainer passed all 29 gestures on the Yoga, including ten
fingers at once. Recognizer, X11 grab, explore by touch, double tap
activation and two finger stop speech added. Automated tests pass. Live
testing started with `cthulhu-switch test`.
- 2026-11-24: First live test in Brave. Explore by touch worked but was chatty
about unnamed containers and repeated link text. About a minute in, AT-SPI
speech stopped and the touch service later hung on shutdown; a reboot was
needed. The X server touch class on the core pointer had grown from 10 to 41,
so sequences may have leaked. Changes: touch accepts are flushed at once,
window lookups moved off the touch loop to the reviewer's own X connection,
explore hit tests limited to one per 40 ms and 3 px, mouse review stays quiet
for one second after touch input, unnamed containers and repeated names are
skipped. `cthulhu-switch` now records native and Go stacks of a test build
that does not hand over, and runs `touchcount` to log touch class sizes.
- 2026-11-24: Root cause of the freeze found with gdb: the window lookup held
the X11 guard and then called the XRes helpers, which take the same
non-recursive guard. The lookup deadlocked and every other X11 reader blocked
behind it, so AT-SPI speech stopped. It happened when the point had no
`_NET_WM_PID`, for example the screen edge. Fixed by running the XRes fallback
after releasing the guard and checking XRes support once per connection.
`TestNativeWindowLocatorFallbackReleasesGuard` reproduces it with an xterm
whose `_NET_WM_PID` is removed: it fails on the old code and passes now.
- 2026-11-24: Switched touch input from the XInput2 grab to evdev with
`EVIOCGRAB`, at the tester's request, so touch no longer depends on X11
input handling. The test user was added to the `input` group. Tracker tests
cover one and two fingers, slot reuse, one-frame touches and `SYN_DROPPED`.
- 2026-11-24: Live test of direct input passed: explore, tap, double tap and
two finger stop speech work in Brave. Added item navigation (flick right
and left), explore committing to object review, and `object-activate` with
a preferred default action (click, press, activate, jump, open, toggle,
select). Item walk tests cover reading order, skipped containers, window
edges and `Cursor.Set`.
- 2026-11-24: Live test passed: flick right and left item navigation and double
tap activation after a flick work in Brave.
- 2026-11-24: Explore in Brave said only "Files, table" over a file list:
Chromium's hit test stopped at the table. Added the child scan fallback to
the shared hit test and line reading over unnamed containers. Added the
rotor, web mode, three finger mode switch, three finger Tab, and two finger
triple tap Escape. The native mouse review test still passes.
- 2026-11-24: Rotor works live. Tester feedback: web mode duplicated flicks
and rotor units. Removed modes; flicks are always items, the rotor picks
browse or flat review commands automatically, and the three finger tap is
free.
- 2026-11-24: Desktop mode (arrow key flicks) was hard to discover and was
dropped. Rebuilt the mapping on Cthulhu's keyboard commands and NVDA's touch
modes: object, text, speech settings and automatic browse mode; four finger
flicks for windows and workspaces; four finger taps for notifications.
- 2026-11-24: Switched the tester's Thunar to the detailed list view; a hit
test probe now finds file names (git, Projects, Videos). Browse mode can be
chosen by hand in any app.
- 2026-11-24: Added `toggle-touch-screen` (Cthulhu+Ctrl+Alt+T) and surveyed
twelve installed apps.
- 2026-11-24: Tester found object mode odd as a default and text mode weird.
Navigation mode is now the default; every mode has its own rotor, as one
table per mode; scrolling added. Four finger flicks were moved into the
navigation rotor so windows and workspaces live in one place.
- 2026-11-24: Settings saved in the test build were lost on restart because
`cthulhu-switch` copied the installed settings over them each time. The
test settings file is now kept.
- 2026-11-24: Browse mode flicks swapped at the tester's request: right and
left read in page order, down and up follow the rotor.