Harden touch device recovery and input lifecycle

This commit is contained in:
Storm Dragon committed 2026-11-24 19:17:26 -05:00
1 parent e4ba4d9882
commit 03066b2abe
16 files changed
+323 -66

No files matched your search

+41 -3
View File
@@ -5,7 +5,7 @@ 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 subsystem with its own gestures, bindings and modes. It shares only the
"what is at this point" hit test with mouse review. "what is at this point" hit test with mouse review.
Branch: `touch-support`, based on `testing`. Requested by Storm Dragon. Integrated into `testing` from Chase Cichorz's three-commit touch patch.
## Design ## Design
@@ -138,10 +138,10 @@ test stopped. Chromium stopped at tables, so cells were never reached.
## Testing ## 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`. - Automated: `python3 tests/native_test_session.py 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 `internal/app` tests read the real session bus, so run them under
`dbus-run-session` or they fail while a screen lock is active. `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` - Native X11: `python3 tests/native_test_session.py env CTHULHU_NATIVE_X11=1 go test ./internal/platform/xorg -run "TestNativeWindowLocator|TestNativeTouchKey" -count=1`
(needs xterm, xdotool and xprop). Real touch device discovery: (needs xterm, xdotool and xprop). Real touch device discovery:
`CTHULHU_NATIVE_EVDEV=1 go test ./internal/platform/evdev -run TestNativeFindTouchScreens`. `CTHULHU_NATIVE_EVDEV=1 go test ./internal/platform/evdev -run TestNativeFindTouchScreens`.
- Live: run `build/cthulhu --replace --config <copy of your settings> --debug-file <log>` - Live: run `build/cthulhu --replace --config <copy of your settings> --debug-file <log>`
@@ -223,3 +223,41 @@ test stopped. Chromium stopped at tables, so cells were never reached.
- 2026-11-24: MATE testing: the 24 pixel panels were too thin to find by - 2026-11-24: MATE testing: the 24 pixel panels were too thin to find by
touch (the tester's MATE panels were raised to 64). Explore now says touch (the tester's MATE panels were raised to 64). Explore now says
"Blank" over empty space and names the window a finger crosses into. "Blank" over empty space and names the window a finger crosses into.
## Integration review and acceptance
The integration fixes device retry starvation; uses scalar EVIOCGRAB arguments
for acquisition and release; decodes native input-event sizes and byte order;
rejects unsupported descriptors and slots; and cancels lost input instead of
turning it into a tap. After overflow the service releases and reopens the
device after five seconds to discard unknown slot state. Disable, lock and
device loss clear the activation point and retire pending exploration results.
Wayland sessions never grab a device. Synthesized keys preserve keys already
held by the user. Item traversal has an explicit ascent limit. Empty i3 replies
are failures and cancellation closes an outstanding command connection.
Before pushing, build from testing and check on the touchscreen:
1. Toggle with Cthulhu+Ctrl+Alt+T; explore, tap, double tap, rotate, and flick
through each mode. Check speech and Braille, including window boundaries.
2. Unplug/reconnect or enable before connecting the device. It should become
available after the retry interval. Toggle off/on; a double tap must not
activate an old point. Lock/unlock using the keyboard and repeat.
3. Hold either physical Shift while issuing touch Shift+Tab. Shift must remain
held until physically released; normal keyboard navigation must still work.
4. Check mouse review, GTK notebook pages, browser tables, browse navigation,
object navigation, and activation. Keep the reader responsive while moving
a finger rapidly over a large page.
5. Tab and Shift+Tab through the touch preferences checkbox, Apply, reopen,
and restart using the saved test configuration to verify persistence.
Private automated tests do not establish physical touch, audible speech,
Braille, or preferences keyboard acceptance. The original contributor's live
results above are historical evidence, not verification of these review fixes.
Validation for this integration: the full Go suite passed in a private
Xvfb/D-Bus session; focused touch/review/app race checks and focused go vet
passed; native mouse hit testing, XRes window lookup, and held-key preservation
passed. The reader, input helper, and BrlAPI-tagged Braille helper built.
Translation catalog checks and git diff whitespace checks passed. No running
reader was replaced and no physical touchscreen acceptance was performed.
+8 -4
View File
@@ -10,6 +10,7 @@ import (
"time" "time"
"git.stormux.org/storm/cthulhu/internal/atspi" "git.stormux.org/storm/cthulhu/internal/atspi"
"git.stormux.org/storm/cthulhu/internal/i18n"
"git.stormux.org/storm/cthulhu/internal/review" "git.stormux.org/storm/cthulhu/internal/review"
) )
@@ -36,12 +37,12 @@ func chooseDefaultAction(actions []atspi.AccessibleAction) (string, bool) {
// review, or focus when nothing is under explicit review. It runs off the // review, or focus when nothing is under explicit review. It runs off the
// command loop so a slow provider never delays other commands. // command loop so a slow provider never delays other commands.
func activateObjectOfInterest(ctx context.Context, logger *slog.Logger, worker *review.Worker, func activateObjectOfInterest(ctx context.Context, logger *slog.Logger, worker *review.Worker,
source accessibleActionSource, speech speechEnqueuer) { source accessibleActionSource, speech speechEnqueuer, gate *focusGate) {
say := func(text string) { say := func(text string) {
speech.Enqueue(speechRequest{Text: text, Role: "system", Cause: "object-activate"}) speech.Enqueue(speechRequest{Text: text, Role: "system", Cause: "object-activate"})
} }
if worker == nil || source == nil { if worker == nil || source == nil {
say("Activation unavailable.") say(i18n.T("Activation unavailable."))
return return
} }
lookup, cancel := context.WithTimeout(ctx, 2*time.Second) lookup, cancel := context.WithTimeout(ctx, 2*time.Second)
@@ -55,14 +56,17 @@ func activateObjectOfInterest(ctx context.Context, logger *slog.Logger, worker *
if err != nil || !ok { if err != nil || !ok {
if ctx.Err() == nil { if ctx.Err() == nil {
logger.Debug("object activation unavailable", "error", err) logger.Debug("object activation unavailable", "error", err)
say("No action available.") say(i18n.T("No action available."))
} }
return return
} }
if ctx.Err() != nil || (gate != nil && gate.Locked()) {
return
}
if err := source.PerformAccessibleAction(lookup, actions.Target, name); err != nil { if err := source.PerformAccessibleAction(lookup, actions.Target, name); err != nil {
if ctx.Err() == nil { if ctx.Err() == nil {
logger.Warn("object activation failed", "action", name, "error", err) logger.Warn("object activation failed", "action", name, "error", err)
say("Could not activate.") say(i18n.T("Could not activate."))
} }
return return
} }
+1 -1
View File
@@ -327,7 +327,7 @@ func (worker commandRuntime) run(ctx context.Context) error {
case input.ObjectPreviousItem: case input.ObjectPreviousItem:
queueObjectReviewMove(logger, objectReview, review.PreviousItem) queueObjectReviewMove(logger, objectReview, review.PreviousItem)
case input.ObjectActivate: case input.ObjectActivate:
go activateObjectOfInterest(ctx, logger, objectReview, worker.actionSource, speechOutput) go activateObjectOfInterest(ctx, logger, objectReview, worker.actionSource, speechOutput, focusGate)
case input.DocumentActivate: case input.DocumentActivate:
if objectReview != nil { if objectReview != nil {
if err := objectReview.ActivateDocumentCaret(); err != nil { if err := objectReview.ActivateDocumentCaret(); err != nil {
+48 -19
View File
@@ -10,10 +10,12 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"git.stormux.org/storm/cthulhu/internal/i18n"
"git.stormux.org/storm/cthulhu/internal/i3command" "git.stormux.org/storm/cthulhu/internal/i3command"
"git.stormux.org/storm/cthulhu/internal/input" "git.stormux.org/storm/cthulhu/internal/input"
"git.stormux.org/storm/cthulhu/internal/lifecycle" "git.stormux.org/storm/cthulhu/internal/lifecycle"
"git.stormux.org/storm/cthulhu/internal/platform/evdev" "git.stormux.org/storm/cthulhu/internal/platform/evdev"
"git.stormux.org/storm/cthulhu/internal/platform/session"
"git.stormux.org/storm/cthulhu/internal/platform/xorg" "git.stormux.org/storm/cthulhu/internal/platform/xorg"
"git.stormux.org/storm/cthulhu/internal/review" "git.stormux.org/storm/cthulhu/internal/review"
"git.stormux.org/storm/cthulhu/internal/touch" "git.stormux.org/storm/cthulhu/internal/touch"
@@ -54,6 +56,7 @@ func (activity *touchActivity) recent(window time.Duration) bool {
type touchPoint struct { type touchPoint struct {
x, y int x, y int
force, commit bool force, commit bool
generation uint64
} }
// touchReviewer speaks what is under the finger. It owns its own last spoken // touchReviewer speaks what is under the finger. It owns its own last spoken
@@ -69,11 +72,13 @@ type touchReviewer struct {
gate *focusGate gate *focusGate
review *review.Worker review *review.Worker
// browsing reports whether browse mode is active on a web page. // browsing reports whether browse mode is active on a web page.
browsing func() bool browsing func() bool
points chan touchPoint points chan touchPoint
generation atomic.Uint64
} }
func (reviewer *touchReviewer) request(point touchPoint) { func (reviewer *touchReviewer) request(point touchPoint) {
point.generation = reviewer.generation.Load()
for { for {
select { select {
case reviewer.points <- point: case reviewer.points <- point:
@@ -82,8 +87,10 @@ func (reviewer *touchReviewer) request(point touchPoint) {
} }
select { select {
case old := <-reviewer.points: case old := <-reviewer.points:
point.force = point.force || old.force if old.generation == point.generation {
point.commit = point.commit || old.commit point.force = point.force || old.force
point.commit = point.commit || old.commit
}
default: default:
} }
} }
@@ -105,6 +112,7 @@ func (reviewer *touchReviewer) run(ctx context.Context) {
// slides off one app always knows where it landed. // slides off one app always knows where it landed.
var lastWindow uint64 var lastWindow uint64
windowKnown := false windowKnown := false
var lastGeneration uint64
entered := "" entered := ""
withWindow := func(text string) string { withWindow := func(text string) string {
if entered == "" { if entered == "" {
@@ -114,6 +122,9 @@ func (reviewer *touchReviewer) run(ctx context.Context) {
return text return text
} }
sayBlank := func(reason string, point touchPoint) { sayBlank := func(reason string, point touchPoint) {
if ctx.Err() != nil || point.generation != reviewer.generation.Load() || !reviewer.live.Load().Reading.EnableTouchScreen || reviewer.gate.Locked() {
return
}
reviewer.logger.Debug("touch review blank", "reason", reason, "x", point.x, "y", point.y) reviewer.logger.Debug("touch review blank", "reason", reason, "x", point.x, "y", point.y)
state.clearItem(xorg.PointerPosition{}) state.clearItem(xorg.PointerPosition{})
lastName = "" lastName = ""
@@ -121,7 +132,7 @@ func (reviewer *touchReviewer) run(ctx context.Context) {
return return
} }
blank = true blank = true
text := withWindow("Blank") text := withWindow(i18n.T("Blank"))
reviewer.speech.Interrupt() reviewer.speech.Interrupt()
reviewer.speech.Enqueue(speechRequest{Text: text, Role: "system", Cause: "touch-review"}) reviewer.speech.Enqueue(speechRequest{Text: text, Role: "system", Cause: "touch-review"})
reviewer.braille.EnqueueMessage(text) reviewer.braille.EnqueueMessage(text)
@@ -133,12 +144,20 @@ func (reviewer *touchReviewer) run(ctx context.Context) {
return return
case point = <-reviewer.points: case point = <-reviewer.points:
} }
if point.generation != reviewer.generation.Load() || ctx.Err() != nil || !reviewer.live.Load().Reading.EnableTouchScreen || reviewer.gate.Locked() {
continue
}
if point.generation != lastGeneration {
state.clearItem(xorg.PointerPosition{})
lastName, entered, blank, windowKnown = "", "", false, false
lastGeneration = point.generation
}
pid, window := locator.WindowAt(point.x, point.y) pid, window := locator.WindowAt(point.x, point.y)
if !windowKnown || window != lastWindow { if !windowKnown || window != lastWindow {
title := "Desktop" title := i18n.T("Desktop")
if window != 0 { if window != 0 {
if title = locator.WindowTitle(window); title == "" { if title = locator.WindowTitle(window); title == "" {
title = "Window" title = i18n.T("Window")
} }
} }
// The first touch after starting has no window to leave. // The first touch after starting has no window to leave.
@@ -176,7 +195,7 @@ func (reviewer *touchReviewer) run(ctx context.Context) {
continue continue
} }
settings := reviewer.live.Load() settings := reviewer.live.Load()
if !settings.Reading.EnableTouchScreen || reviewer.gate.Locked() { if point.generation != reviewer.generation.Load() || ctx.Err() != nil || !settings.Reading.EnableTouchScreen || reviewer.gate.Locked() {
continue continue
} }
snapshot := hit.Snapshot snapshot := hit.Snapshot
@@ -238,7 +257,7 @@ func (reviewer *touchReviewer) run(ctx context.Context) {
} }
} }
// touchService owns the XInput2 touch grab while the touch screen setting is // touchService owns the evdev touch grab while the touch screen setting is
// on and the session is not locked. When it is off, touches go to applications. // on and the session is not locked. When it is off, touches go to applications.
func touchService(logger *slog.Logger, adapter pointReviewAdapter, speech speechEnqueuer, func touchService(logger *slog.Logger, adapter pointReviewAdapter, speech speechEnqueuer,
braille interface{ EnqueueMessage(string) bool }, live *liveSettings, gate *focusGate, braille interface{ EnqueueMessage(string) bool }, live *liveSettings, gate *focusGate,
@@ -287,6 +306,10 @@ func touchService(logger *slog.Logger, adapter pointReviewAdapter, speech speech
// arriving. Activation clicks use this loop's own X connection. // arriving. Activation clicks use this loop's own X connection.
func runTouchScreen(ctx context.Context, logger *slog.Logger, reviewer *touchReviewer, func runTouchScreen(ctx context.Context, logger *slog.Logger, reviewer *touchReviewer,
speech speechEnqueuer, activity *touchActivity, commands chan<- input.CommandEvent) { speech speechEnqueuer, activity *touchActivity, commands chan<- input.CommandEvent) {
if session.Wayland() {
logger.Info("touch screen requires an X11 session")
return
}
var screen *evdev.TouchScreen var screen *evdev.TouchScreen
var locator *xorg.WindowLocator var locator *xorg.WindowLocator
defer func() { defer func() {
@@ -314,12 +337,16 @@ func runTouchScreen(ctx context.Context, logger *slog.Logger, reviewer *touchRev
var sentAt time.Time var sentAt time.Time
release := func() { release := func() {
reviewer.generation.Add(1)
if screen != nil { if screen != nil {
screen.Close() screen.Close()
screen = nil screen = nil
logger.Info("touch screen released") logger.Info("touch screen released")
} }
exploreWaiting = false exploreWaiting = false
haveExplored = false
nav = newTouchNavigation()
sentAt = time.Time{}
if recognizer != nil { if recognizer != nil {
recognizer.Reset() recognizer.Reset()
} }
@@ -345,8 +372,7 @@ func runTouchScreen(ctx context.Context, logger *slog.Logger, reviewer *touchRev
if denied && !toldDenied { if denied && !toldDenied {
toldDenied = true toldDenied = true
logger.Warn("touch screen unreadable: add the user to the input group") logger.Warn("touch screen unreadable: add the user to the input group")
speech.Enqueue(speechRequest{Text: "Touch screen needs input group access. " + speech.Enqueue(speechRequest{Text: i18n.T("Touch screen needs input group access. Add your user to the input group and log in again."), Cause: "touch-screen"})
"Add your user to the input group and log in again.", Cause: "touch-screen"})
} }
return false return false
} }
@@ -360,17 +386,14 @@ func runTouchScreen(ctx context.Context, logger *slog.Logger, reviewer *touchRev
return false return false
} }
screen = opened screen = opened
if recognizer == nil { recognizer = touch.New(touch.DefaultConfig(width))
recognizer = touch.New(touch.DefaultConfig(width))
}
recognizer.Reset()
logger.Info("touch screen grabbed", "device", screen.Device.Path, "name", screen.Device.Name, logger.Info("touch screen grabbed", "device", screen.Device.Path, "name", screen.Device.Name,
"slots", screen.Device.Slots, "width", width, "height", height) "slots", screen.Device.Slots, "width", width, "height", height)
return true return true
} }
for ctx.Err() == nil { for ctx.Err() == nil {
settings := reviewer.live.Load() settings := reviewer.live.Load()
if !settings.Reading.EnableTouchScreen || reviewer.gate.Locked() { if ctx.Err() != nil || !settings.Reading.EnableTouchScreen || reviewer.gate.Locked() {
release() release()
if !idle() { if !idle() {
return return
@@ -378,10 +401,12 @@ func runTouchScreen(ctx context.Context, logger *slog.Logger, reviewer *touchRev
continue continue
} }
if screen == nil { if screen == nil {
if time.Now().Before(retryAt) || !open() { if !time.Now().Before(retryAt) {
if screen == nil { if !open() {
retryAt = time.Now().Add(touchRetryInterval) retryAt = time.Now().Add(touchRetryInterval)
} }
}
if screen == nil {
if !idle() { if !idle() {
return return
} }
@@ -396,6 +421,10 @@ func runTouchScreen(ctx context.Context, logger *slog.Logger, reviewer *touchRev
retryAt = time.Now().Add(touchRetryInterval) retryAt = time.Now().Add(touchRetryInterval)
continue continue
} }
if ctx.Err() != nil || !reviewer.live.Load().Reading.EnableTouchScreen || reviewer.gate.Locked() {
release()
continue
}
now := time.Since(epoch) now := time.Since(epoch)
var outputs []touch.Output var outputs []touch.Output
if ok { if ok {
@@ -457,7 +486,7 @@ func runTouchScreen(ctx context.Context, logger *slog.Logger, reviewer *touchRev
defer cancel() defer cancel()
if err := i3command.Run(runCtx, xorg.I3Socket(), name); err != nil && ctx.Err() == nil { if err := i3command.Run(runCtx, xorg.I3Socket(), name); err != nil && ctx.Err() == nil {
logger.Debug("touch desktop command", "command", name, "error", err) logger.Debug("touch desktop command", "command", name, "error", err)
speech.Enqueue(speechRequest{Text: "Not available", Role: "system", Cause: "touch-mode"}) speech.Enqueue(speechRequest{Text: i18n.T("Not available"), Role: "system", Cause: "touch-mode"})
} }
}(action.i3) }(action.i3)
case action.command != "": case action.command != "":
+6 -5
View File
@@ -4,6 +4,7 @@
package app package app
import ( import (
"git.stormux.org/storm/cthulhu/internal/i18n"
"git.stormux.org/storm/cthulhu/internal/input" "git.stormux.org/storm/cthulhu/internal/input"
"git.stormux.org/storm/cthulhu/internal/touch" "git.stormux.org/storm/cthulhu/internal/touch"
) )
@@ -38,8 +39,8 @@ const (
) )
func (mode touchMode) label() string { func (mode touchMode) label() string {
return [...]string{"Navigation mode", "Text mode", "Browse mode", "Object mode", return i18n.T([...]string{"Navigation mode", "Text mode", "Browse mode", "Object mode",
"Speech settings mode"}[mode] "Speech settings mode"}[mode])
} }
// touchFlick names one flick. // touchFlick names one flick.
@@ -225,14 +226,14 @@ func (nav *touchNavigation) turn(clockwise bool) touchAction {
} }
rotor := touchModes[nav.mode].rotor rotor := touchModes[nav.mode].rotor
if len(rotor) == 0 { if len(rotor) == 0 {
return touchAction{announce: nav.mode.label() + " has no rotor"} return touchAction{announce: i18n.Format("{0} has no rotor", nav.mode.label())}
} }
step := 1 step := 1
if !clockwise { if !clockwise {
step = len(rotor) - 1 step = len(rotor) - 1
} }
nav.rotor[nav.mode] = (nav.rotor[nav.mode] + step) % len(rotor) nav.rotor[nav.mode] = (nav.rotor[nav.mode] + step) % len(rotor)
return touchAction{announce: rotor[nav.rotor[nav.mode]].label} return touchAction{announce: i18n.T(rotor[nav.rotor[nav.mode]].label)}
} }
// flick finds a flick in the current rotor unit, then in the mode itself. // flick finds a flick in the current rotor unit, then in the mode itself.
@@ -278,7 +279,7 @@ func (nav *touchNavigation) gesture(gesture touch.Gesture, browsing bool) touchA
case touchLastObject: case touchLastObject:
return touchCmd(input.ObjectActivate) return touchCmd(input.ObjectActivate)
} }
return touchAction{announce: "Nothing to activate"} return touchAction{announce: i18n.T("Nothing to activate")}
case touch.DoubleTapHold: case touch.DoubleTapHold:
if nav.last == touchLastPoint { if nav.last == touchLastPoint {
return touchAction{rightClickPoint: true} return touchAction{rightClickPoint: true}
+43
View File
@@ -76,3 +76,46 @@ func TestBehaviorEmptySpaceSaysBlankOnce(t *testing.T) {
reviewer.request(touchPoint{x: 20, y: 20, force: true}) reviewer.request(touchPoint{x: 20, y: 20, force: true})
expect("Blank") expect("Blank")
} }
func TestTouchReviewerDropsDisabledAndRetiredRequests(t *testing.T) {
t.Setenv("DISPLAY", "")
settings := config.DefaultSettings()
live := &liveSettings{}
live.Store(settings)
speech := blankSpeech{said: make(chan string, 8)}
reviewer := &touchReviewer{logger: slog.New(slog.DiscardHandler), speech: speech, braille: blankBraille{}, live: live, gate: &focusGate{}, points: make(chan touchPoint, 1)}
ctx, cancel := context.WithCancel(t.Context())
done := make(chan struct{})
go func() { defer close(done); reviewer.run(ctx) }()
defer func() { cancel(); <-done }()
reviewer.request(touchPoint{force: true})
select {
case got := <-speech.said:
t.Fatalf("disabled touch said %q", got)
case <-time.After(100 * time.Millisecond):
}
settings.Reading.EnableTouchScreen = true
live.Store(settings)
reviewer.generation.Add(1)
reviewer.points <- touchPoint{force: true, generation: 0}
select {
case got := <-speech.said:
t.Fatalf("retired touch said %q", got)
case <-time.After(100 * time.Millisecond):
}
reviewer.request(touchPoint{force: true})
select {
case got := <-speech.said:
if got != "Blank" {
t.Fatalf("fresh touch said %q", got)
}
case <-time.After(time.Second):
t.Fatal("fresh touch was lost")
}
}
func TestWaylandDoesNotOpenTouchDevice(t *testing.T) {
t.Setenv("XDG_SESSION_TYPE", "wayland")
// No reader dependencies: unsupported sessions must return before opening hardware.
runTouchScreen(t.Context(), slog.New(slog.DiscardHandler), nil, nil, nil, nil)
}
+1
View File
@@ -33,6 +33,7 @@ func TestStoreSaveAndLoadRoundTrip(t *testing.T) {
settings.Reading.SayAllContextPanel = false settings.Reading.SayAllContextPanel = false
settings.Reading.PresentTooltips = true settings.Reading.PresentTooltips = true
settings.Reading.EnableMouseReview = true settings.Reading.EnableMouseReview = true
settings.Reading.EnableTouchScreen = true
settings.EnableBraille = true settings.EnableBraille = true
settings.EnableContractedBraille = true settings.EnableContractedBraille = true
settings.BrailleContractionTable = "en-us-g2.ctb" settings.BrailleContractionTable = "en-us-g2.ctb"
+40
View File
@@ -13,14 +13,30 @@ msgstr ""
msgid "1 character" msgid "1 character"
msgstr "" msgstr ""
#: internal/app/object_activate.go:45
msgid "Activation unavailable."
msgstr ""
#: internal/app/touch.go:135
msgid "Blank"
msgstr ""
#: screenreader-common/internalui #: screenreader-common/internalui
msgid "Copy and cut are unavailable for password fields" msgid "Copy and cut are unavailable for password fields"
msgstr "" msgstr ""
#: internal/app/object_activate.go:69
msgid "Could not activate."
msgstr ""
#: screenreader-common/internalui #: screenreader-common/internalui
msgid "Deleted {0}" msgid "Deleted {0}"
msgstr "" msgstr ""
#: internal/app/touch.go:157
msgid "Desktop"
msgstr ""
#: screenreader-common/internalui #: screenreader-common/internalui
msgid "End of text" msgid "End of text"
msgstr "" msgstr ""
@@ -37,10 +53,22 @@ msgstr ""
msgid "Invalid text" msgid "Invalid text"
msgstr "" msgstr ""
#: internal/app/object_activate.go:59
msgid "No action available."
msgstr ""
#: screenreader-common/internalui #: screenreader-common/internalui
msgid "No matches" msgid "No matches"
msgstr "" msgstr ""
#: internal/app/touch.go:489
msgid "Not available"
msgstr ""
#: internal/app/touch_navigation.go:282
msgid "Nothing to activate"
msgstr ""
#: screenreader-common/internalui #: screenreader-common/internalui
msgid "Only single-line text is accepted" msgid "Only single-line text is accepted"
msgstr "" msgstr ""
@@ -65,6 +93,14 @@ msgstr ""
msgid "Text limit reached" msgid "Text limit reached"
msgstr "" msgstr ""
#: internal/app/touch.go:375
msgid "Touch screen needs input group access. Add your user to the input group and log in again."
msgstr ""
#: internal/app/touch.go:160
msgid "Window"
msgstr ""
#: screenreader-common/internalui screenreader-common/quicksettings/menu.go #: screenreader-common/internalui screenreader-common/quicksettings/menu.go
msgid "checked" msgid "checked"
msgstr "" msgstr ""
@@ -101,6 +137,10 @@ msgstr ""
msgid "{0} grid. {1}" msgid "{0} grid. {1}"
msgstr "" msgstr ""
#: internal/app/touch_navigation.go:229
msgid "{0} has no rotor"
msgstr ""
#: screenreader-common/internalui #: screenreader-common/internalui
msgid "{0} is required" msgid "{0} is required"
msgstr "" msgstr ""
+5
View File
@@ -35,6 +35,8 @@ func Run(ctx context.Context, path, command string) error {
return err return err
} }
defer conn.Close() defer conn.Close()
stop := context.AfterFunc(ctx, func() { conn.Close() })
defer stop()
deadline := time.Now().Add(timeout) deadline := time.Now().Add(timeout)
if d, ok := ctx.Deadline(); ok && d.Before(deadline) { if d, ok := ctx.Deadline(); ok && d.Before(deadline) {
deadline = d deadline = d
@@ -59,6 +61,9 @@ func Run(ctx context.Context, path, command string) error {
if err := json.Unmarshal(body, &replies); err != nil { if err := json.Unmarshal(body, &replies); err != nil {
return fmt.Errorf("i3 reply: %w", err) return fmt.Errorf("i3 reply: %w", err)
} }
if len(replies) == 0 {
return errors.New("empty i3 command reply")
}
for _, reply := range replies { for _, reply := range replies {
if !reply.Success { if !reply.Success {
return fmt.Errorf("i3 %q: %s", command, reply.Error) return fmt.Errorf("i3 %q: %s", command, reply.Error)
+7
View File
@@ -65,3 +65,10 @@ func TestBehaviorRunReportsI3Failure(t *testing.T) {
t.Fatal("a missing socket must return an error") t.Fatal("a missing socket must return an error")
} }
} }
func TestEmptyReplyIsNotSuccess(t *testing.T) {
path, _ := fakeI3(t, `[]`)
if err := Run(t.Context(), path, "workspace next"); err == nil {
t.Fatal("empty reply accepted")
}
}
+37 -22
View File
@@ -57,6 +57,7 @@ const (
Begin = 0 Begin = 0
Update = 1 Update = 1
End = 2 End = 2
Cancel = 3 // Lost events invalidate the whole gesture.
) )
// Contact is one finger change in screen pixels. // Contact is one finger change in screen pixels.
@@ -157,15 +158,16 @@ func Open(device Device, screenWidth, screenHeight int) (*TouchScreen, error) {
return nil, err return nil, err
} }
fd := int(file.Fd()) fd := int(file.Fd())
one := int32(1) if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), ioc(iocWrite, 0x90, 4), 1); err != 0 {
if err := ioctl(fd, ioc(iocWrite, 0x90, 4), unsafe.Pointer(&one)); err != nil {
file.Close() file.Close()
return nil, fmt.Errorf("grab %s: %w", device.Path, err) return nil, fmt.Errorf("grab %s: %w", device.Path, err)
} }
return &TouchScreen{Device: device, file: file, fd: fd, return &TouchScreen{Device: device, file: file, fd: fd,
tracker: NewTracker(device, screenWidth, screenHeight), buffer: make([]byte, 24*64)}, nil tracker: NewTracker(device, screenWidth, screenHeight), buffer: make([]byte, inputEventSize*64)}, nil
} }
const inputEventSize = int(unsafe.Sizeof(syscall.Timeval{})) + 8
// Next waits up to timeout for one contact change. failed reports that the // Next waits up to timeout for one contact change. failed reports that the
// device went away, for example when it was unplugged. // device went away, for example when it was unplugged.
func (screen *TouchScreen) Next(timeout time.Duration) (contact Contact, ok, failed bool) { func (screen *TouchScreen) Next(timeout time.Duration) (contact Contact, ok, failed bool) {
@@ -174,7 +176,11 @@ func (screen *TouchScreen) Next(timeout time.Duration) (contact Contact, ok, fai
return contact, true, false return contact, true, false
} }
var set syscall.FdSet var set syscall.FdSet
set.Bits[screen.fd/64] |= 1 << (uint(screen.fd) % 64) bits := int(unsafe.Sizeof(set.Bits[0])) * 8
if screen.fd < 0 || screen.fd >= len(set.Bits)*bits {
return Contact{}, false, true
}
set.Bits[screen.fd/bits] |= 1 << (uint(screen.fd) % uint(bits))
tv := syscall.NsecToTimeval(timeout.Nanoseconds()) tv := syscall.NsecToTimeval(timeout.Nanoseconds())
n, err := syscall.Select(screen.fd+1, &set, nil, nil, &tv) n, err := syscall.Select(screen.fd+1, &set, nil, nil, &tv)
if err != nil { if err != nil {
@@ -196,10 +202,17 @@ func (screen *TouchScreen) Next(timeout time.Duration) (contact Contact, ok, fai
if count == 0 { if count == 0 {
return Contact{}, false, true return Contact{}, false, true
} }
for offset := 0; offset+24 <= count; offset += 24 { for offset := 0; offset+inputEventSize <= count; offset += inputEventSize {
record := screen.buffer[offset : offset+24] record := screen.buffer[offset+inputEventSize-8 : offset+inputEventSize]
screen.pending = screen.tracker.Event(binary.LittleEndian.Uint16(record[16:]), screen.pending = screen.tracker.Event(binary.NativeEndian.Uint16(record),
binary.LittleEndian.Uint16(record[18:]), int32(binary.LittleEndian.Uint32(record[20:])), screen.pending) binary.NativeEndian.Uint16(record[2:]), int32(binary.NativeEndian.Uint32(record[4:])), screen.pending)
}
for _, event := range screen.pending {
if event.Phase == Cancel {
// Reopen after overflow to discard unknown kernel slot state.
screen.pending = nil
return Contact{}, false, true
}
} }
if len(screen.pending) == 0 { if len(screen.pending) == 0 {
return Contact{}, false, false return Contact{}, false, false
@@ -213,8 +226,7 @@ func (screen *TouchScreen) Close() {
if screen == nil || screen.file == nil { if screen == nil || screen.file == nil {
return return
} }
zero := int32(0) _, _, _ = syscall.Syscall(syscall.SYS_IOCTL, uintptr(screen.fd), ioc(iocWrite, 0x90, 4), 0)
_ = ioctl(screen.fd, ioc(iocWrite, 0x90, 4), unsafe.Pointer(&zero))
screen.file.Close() screen.file.Close()
screen.file = nil screen.file = nil
} }
@@ -225,6 +237,7 @@ type Tracker struct {
device Device device Device
width, height float64 width, height float64
slot int slot int
dropped bool
slots []slotState slots []slotState
} }
@@ -253,12 +266,19 @@ func (tracker *Tracker) screen(x, y int32) (float64, float64) {
// Event handles one input event and appends finished contact changes, which // Event handles one input event and appends finished contact changes, which
// are only emitted at SYN_REPORT so each frame is consistent. // are only emitted at SYN_REPORT so each frame is consistent.
func (tracker *Tracker) Event(kind, code uint16, value int32, out []Contact) []Contact { func (tracker *Tracker) Event(kind, code uint16, value int32, out []Contact) []Contact {
if tracker.dropped {
if kind == evSyn && code == synReport {
tracker.dropped = false
}
return out
}
switch kind { switch kind {
case evAbs: case evAbs:
if code == absMTSlot { if code == absMTSlot {
if value >= 0 && int(value) < len(tracker.slots) { tracker.slot = int(value)
tracker.slot = int(value) return out
} }
if tracker.slot < 0 || tracker.slot >= len(tracker.slots) {
return out return out
} }
state := &tracker.slots[tracker.slot] state := &tracker.slots[tracker.slot]
@@ -286,15 +306,10 @@ func (tracker *Tracker) Event(kind, code uint16, value int32, out []Contact) []C
case synReport: case synReport:
out = tracker.flush(out) out = tracker.flush(out)
case synDropped: case synDropped:
// Events were lost. End every contact; the recognizer resets cleanly. // Never turn incomplete input into taps or activation.
for index := range tracker.slots { clear(tracker.slots)
state := &tracker.slots[index] tracker.slot, tracker.dropped = 0, true
if state.active { out = append(out, Contact{Phase: Cancel})
x, y := tracker.screen(state.x, state.y)
out = append(out, Contact{Phase: End, ID: state.id, X: x, Y: y})
}
*state = slotState{}
}
} }
} }
return out return out
+31 -3
View File
@@ -85,7 +85,7 @@ func TestBehaviorTouchWithinOneFrameIsNotReported(t *testing.T) {
} }
} }
func TestBehaviorDroppedEventsEndEveryContact(t *testing.T) { func TestBehaviorDroppedEventsCancelEveryContact(t *testing.T) {
tracker := NewTracker(testDevice, 1920, 1200) tracker := NewTracker(testDevice, 1920, 1200)
var out []Contact var out []Contact
for _, e := range [][3]int32{abs(absMTSlot, 0), abs(absMTTrackingID, 1), abs(absMTSlot, 1), abs(absMTTrackingID, 2)} { for _, e := range [][3]int32{abs(absMTSlot, 0), abs(absMTTrackingID, 1), abs(absMTSlot, 1), abs(absMTTrackingID, 2)} {
@@ -93,8 +93,8 @@ func TestBehaviorDroppedEventsEndEveryContact(t *testing.T) {
} }
out = tracker.Event(evSyn, synReport, 0, out) out = tracker.Event(evSyn, synReport, 0, out)
out = tracker.Event(evSyn, synDropped, 0, out[:0]) out = tracker.Event(evSyn, synDropped, 0, out[:0])
if len(out) != 2 || out[0].Phase != End || out[1].Phase != End { if len(out) != 1 || out[0].Phase != Cancel {
t.Fatalf("want both contacts ended, got %+v", out) t.Fatalf("want gesture cancelled, got %+v", out)
} }
out = tracker.Event(evSyn, synReport, 0, out[:0]) out = tracker.Event(evSyn, synReport, 0, out[:0])
if len(out) != 0 { if len(out) != 0 {
@@ -122,3 +122,31 @@ func TestNativeFindTouchScreens(t *testing.T) {
t.Fatal("no touch screen found") t.Fatal("no touch screen found")
} }
} }
func TestDroppedFrameIgnoresEventsUntilReport(t *testing.T) {
tracker := NewTracker(testDevice, 1920, 1200)
tracker.Event(evSyn, synDropped, 0, nil)
tracker.Event(evAbs, absMTTrackingID, 42, nil)
if got := tracker.Event(evSyn, synReport, 0, nil); len(got) != 0 {
t.Fatalf("incomplete frame emitted %+v", got)
}
tracker.Event(evAbs, absMTTrackingID, 43, nil)
if got := tracker.Event(evSyn, synReport, 0, nil); len(got) != 1 || got[0].ID != 43 {
t.Fatalf("fresh frame = %+v", got)
}
}
func TestInvalidSlotDoesNotModifyPreviousFinger(t *testing.T) {
got := run(t, frame{[][3]int32{abs(absMTTrackingID, 7), abs(absMTPositionX, 200)}},
frame{[][3]int32{abs(absMTSlot, 100), abs(absMTTrackingID, -1), abs(absMTPositionX, 3000)}})
if len(got) != 1 || got[0].Phase != Begin {
t.Fatalf("invalid slot changed valid finger: %+v", got)
}
}
func TestHighDescriptorFailsWithoutPanic(t *testing.T) {
screen := &TouchScreen{fd: 100000}
if _, _, failed := screen.Next(0); !failed {
t.Fatal("unsupported descriptor must fail")
}
}
+17 -6
View File
@@ -106,13 +106,24 @@ int cthulhu_touch_key(Display *display, unsigned long keysym, int shift) {
KeyCode shiftCode = XKeysymToKeycode(display, XK_Shift_L); KeyCode shiftCode = XKeysymToKeycode(display, XK_Shift_L);
if (!code || (shift && !shiftCode)) return 0; if (!code || (shift && !shiftCode)) return 0;
cthulhu_x11_begin_read(display); cthulhu_x11_begin_read(display);
int ok = 1; char keys[32];
if (shift) ok = XTestFakeKeyEvent(display, shiftCode, True, CurrentTime); XQueryKeymap(display, keys);
if (ok) { // Do not release a physical key or modifier the user is already holding.
ok = XTestFakeKeyEvent(display, code, True, CurrentTime) && if (keys[code / 8] & (1 << (code % 8))) {
XTestFakeKeyEvent(display, code, False, CurrentTime); cthulhu_x11_end_read(display);
return 0;
} }
if (shift) XTestFakeKeyEvent(display, shiftCode, False, CurrentTime); KeyCode rightShift = XKeysymToKeycode(display, XK_Shift_R);
int ownShift = shift && !(keys[shiftCode / 8] & (1 << (shiftCode % 8))) &&
!(rightShift && (keys[rightShift / 8] & (1 << (rightShift % 8))));
int ok = 1;
if (ownShift) ok = XTestFakeKeyEvent(display, shiftCode, True, CurrentTime);
if (ok) {
int pressed = XTestFakeKeyEvent(display, code, True, CurrentTime);
int released = XTestFakeKeyEvent(display, code, False, CurrentTime);
ok = pressed && released;
}
if (ownShift) XTestFakeKeyEvent(display, shiftCode, False, CurrentTime);
XSync(display, False); XSync(display, False);
if (cthulhu_x11_end_read(display)) ok = 0; if (cthulhu_x11_end_read(display)) ok = 0;
return ok; return ok;
+35 -1
View File
@@ -25,7 +25,7 @@ func TestNativeWindowLocatorFallbackReleasesGuard(t *testing.T) {
} }
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel() defer cancel()
client := exec.CommandContext(ctx, "xterm", "-geometry", "40x10+100+100", "-class", "CthulhuTouchFixture") client := exec.CommandContext(ctx, "xterm", "-T", "Touch fixture", "-geometry", "40x10+100+100", "-class", "CthulhuTouchFixture")
if err := client.Start(); err != nil { if err := client.Start(); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -75,3 +75,37 @@ func TestNativeWindowLocatorFallbackReleasesGuard(t *testing.T) {
t.Fatal("window lookup left the X11 guard held") t.Fatal("window lookup left the X11 guard held")
} }
} }
func TestNativeTouchKeyPreservesHeldKeys(t *testing.T) {
if os.Getenv("CTHULHU_NATIVE_X11") != "1" {
t.Skip("requires isolated X11 display")
}
target, err := openRemoteKeyTarget()
if err != nil {
t.Fatal(err)
}
defer target.close()
locator := OpenWindowLocator()
if locator == nil {
t.Fatal("no locator")
}
defer locator.Close()
for _, name := range []string{"Shift_L", "Shift_R", "Tab"} {
code, err := target.backend.Resolve(name)
if err != nil {
t.Fatal(err)
}
if err := target.backend.Set(code, true); err != nil {
t.Fatal(err)
}
ok := locator.Key(KeyTab, true)
held, err := target.backend.Held(code)
target.backend.Set(code, false)
if err != nil || !held {
t.Fatalf("touch released held %s: %v", name, err)
}
if ok == (name == "Tab") {
t.Fatalf("key result for held %s = %v", name, ok)
}
}
}
+2 -1
View File
@@ -50,7 +50,7 @@ func (cursor *Cursor) adjacentLocked(reference atspi.ObjectReference, forward bo
if child, ok, err := tree.FirstChild(reference); err != nil || ok { if child, ok, err := tree.FirstChild(reference); err != nil || ok {
return child, ok, err return child, ok, err
} }
for node := reference; ; { for node, depth := reference, 0; depth < maxItemSteps; depth++ {
top, err := cursor.topLevelLocked(node) top, err := cursor.topLevelLocked(node)
if err != nil || top { if err != nil || top {
return atspi.ObjectReference{}, false, err return atspi.ObjectReference{}, false, err
@@ -64,6 +64,7 @@ func (cursor *Cursor) adjacentLocked(reference atspi.ObjectReference, forward bo
} }
node = parent node = parent
} }
return atspi.ObjectReference{}, false, nil
} }
top, err := cursor.topLevelLocked(reference) top, err := cursor.topLevelLocked(reference)
if err != nil || top { if err != nil || top {
+1 -1
View File
@@ -21,7 +21,7 @@ import "strings"
const Name = "Cthulhu" const Name = "Cthulhu"
const Version = "2026.11.19" const Version = "2026.11.24"
const Channel = "testing" const Channel = "testing"
var Build = Version var Build = Version