diff --git a/docs/touch-support.md b/docs/touch-support.md index 39be00d..715ae58 100644 --- a/docs/touch-support.md +++ b/docs/touch-support.md @@ -52,7 +52,10 @@ 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. + unnamed containers). Lifting moves object review there. Empty space says + "Blank" once until the finger reaches something; testers found silence + sounded broken. Crossing into another window, or off every window, says + that window's title (or "Desktop") first, once per crossing. - 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 @@ -217,3 +220,6 @@ test stopped. Chromium stopped at tables, so cells were never reached. 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. +- 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 + "Blank" over empty space and names the window a finger crosses into. diff --git a/internal/app/touch.go b/internal/app/touch.go index 20956e4..17e8538 100644 --- a/internal/app/touch.go +++ b/internal/app/touch.go @@ -98,6 +98,34 @@ func (reviewer *touchReviewer) run(ctx context.Context) { var state mouseReviewState state.clearItem(xorg.PointerPosition{}) lastName := "" + // Silence over empty space sounds like a broken screen reader, so empty + // space says "Blank" once, until the finger reaches something again. + blank := false + // Crossing into another window says its title first, so a finger that + // slides off one app always knows where it landed. + var lastWindow uint64 + windowKnown := false + entered := "" + withWindow := func(text string) string { + if entered == "" { + return text + } + text, entered = entered+", "+text, "" + return text + } + sayBlank := func(reason string, point touchPoint) { + reviewer.logger.Debug("touch review blank", "reason", reason, "x", point.x, "y", point.y) + state.clearItem(xorg.PointerPosition{}) + lastName = "" + if blank && !point.force && entered == "" { + return + } + blank = true + text := withWindow("Blank") + reviewer.speech.Interrupt() + reviewer.speech.Enqueue(speechRequest{Text: text, Role: "system", Cause: "touch-review"}) + reviewer.braille.EnqueueMessage(text) + } for { var point touchPoint select { @@ -105,11 +133,24 @@ func (reviewer *touchReviewer) run(ctx context.Context) { return case point = <-reviewer.points: } - pid, _ := locator.WindowAt(point.x, point.y) - if pid <= 0 { - reviewer.logger.Debug("touch review silent", "reason", "no window", "x", point.x, "y", point.y) + pid, window := locator.WindowAt(point.x, point.y) + if !windowKnown || window != lastWindow { + title := "Desktop" + if window != 0 { + if title = locator.WindowTitle(window); title == "" { + title = "Window" + } + } + // The first touch after starting has no window to leave. + if windowKnown { + entered = title + } + lastWindow, windowKnown = window, true state.clearItem(xorg.PointerPosition{}) lastName = "" + } + if pid <= 0 { + sayBlank("no window", point) continue } if point.force { @@ -140,9 +181,7 @@ func (reviewer *touchReviewer) run(ctx context.Context) { } snapshot := hit.Snapshot if !snapshot.ID().Valid() { - reviewer.logger.Debug("touch review silent", "reason", "no object", "pid", pid, "x", point.x, "y", point.y) - state.clearItem(xorg.PointerPosition{}) - lastName = "" + sayBlank("no object", point) continue } if review.ItemSkips(snapshot) { @@ -150,15 +189,19 @@ func (reviewer *touchReviewer) run(ctx context.Context) { // finger does: exploring is for reading what is there. if line := strings.TrimSpace(hit.Line); line != "" && line != state.spoken { state.spoken, state.last = line, hit + text := withWindow(line) reviewer.speech.Interrupt() - reviewer.speech.Enqueue(speechRequest{Text: line, Cause: "touch-review"}) - reviewer.braille.EnqueueMessage(line) + reviewer.speech.Enqueue(speechRequest{Text: text, Cause: "touch-review"}) + reviewer.braille.EnqueueMessage(text) + blank = false reviewer.logger.Debug("touch review line", "role", snapshot.Role, "x", point.x, "y", point.y, "speech", line) continue } + if strings.TrimSpace(hit.Line) == "" { + sayBlank("empty "+snapshot.Role, point) + continue + } if !point.force { - reviewer.logger.Debug("touch review silent", "reason", "container", "role", snapshot.Role, - "x", point.x, "y", point.y) continue } } else if point.commit && reviewer.review != nil { @@ -181,8 +224,13 @@ func (reviewer *touchReviewer) run(ctx context.Context) { if name != "" { lastName = name } + blank = false + chunks := spoken.Chunks + if entered != "" { + spoken.Text, chunks = withWindow(spoken.Text), nil + } reviewer.speech.Interrupt() - reviewer.speech.Enqueue(speechRequest{Text: spoken.Text, Chunks: spoken.Chunks, + reviewer.speech.Enqueue(speechRequest{Text: spoken.Text, Chunks: chunks, Role: snapshot.Role, Cause: "touch-review"}) reviewer.braille.EnqueueMessage(spoken.Text) reviewer.logger.Debug("touch review presentation", "bus", snapshot.BusName, diff --git a/internal/app/touch_test.go b/internal/app/touch_test.go index 08e92cf..0dabd9d 100644 --- a/internal/app/touch_test.go +++ b/internal/app/touch_test.go @@ -4,8 +4,12 @@ package app import ( + "context" + "log/slog" "testing" "time" + + "git.stormux.org/storm/cthulhu/internal/config" ) func TestBehaviorTouchActivityQuietsMouseReviewBriefly(t *testing.T) { @@ -26,3 +30,49 @@ func TestBehaviorTouchActivityQuietsMouseReviewBriefly(t *testing.T) { t.Fatal("nil activity must never quiet mouse review") } } + +type blankSpeech struct{ said chan string } + +func (speech blankSpeech) Enqueue(request speechRequest) { speech.said <- request.Text } +func (blankSpeech) Interrupt() {} + +type blankBraille struct{} + +func (blankBraille) EnqueueMessage(string) bool { return true } + +func TestBehaviorEmptySpaceSaysBlankOnce(t *testing.T) { + t.Setenv("DISPLAY", "") // no X display: every point has no window under it + settings := config.DefaultSettings() + settings.Reading.EnableTouchScreen = true + 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()) + defer cancel() + go reviewer.run(ctx) + expect := func(want string) { + t.Helper() + select { + case got := <-speech.said: + if got != want { + t.Fatalf("said %q, want %q", got, want) + } + case <-time.After(time.Second): + if want != "" { + t.Fatalf("said nothing, want %q", want) + } + } + } + reviewer.request(touchPoint{x: 10, y: 10}) + expect("Blank") + reviewer.request(touchPoint{x: 20, y: 20}) + select { + case got := <-speech.said: + t.Fatalf("moving over more empty space must stay quiet, said %q", got) + case <-time.After(200 * time.Millisecond): + } + reviewer.request(touchPoint{x: 20, y: 20, force: true}) + expect("Blank") +} diff --git a/internal/platform/xorg/touch.go b/internal/platform/xorg/touch.go index c1d81b4..d830add 100644 --- a/internal/platform/xorg/touch.go +++ b/internal/platform/xorg/touch.go @@ -46,6 +46,18 @@ func (locator *WindowLocator) WindowAt(x, y int) (pid int, window uint64) { return pid, uint64(native) } +// WindowTitle reports a window's title, or "" when it has none. +func (locator *WindowLocator) WindowTitle(window uint64) string { + if locator == nil || locator.display == nil || window == 0 { + return "" + } + var title [512]C.char + if C.cthulhu_window_title(locator.display, C.ulong(window), &title[0], C.int(len(title))) == 0 { + return "" + } + return C.GoString(&title[0]) +} + // Click presses and releases a mouse button (1 left, 3 right, 4 and 5 the // wheel) at a point and returns the pointer to where it was. func (locator *WindowLocator) Click(x, y, button int) bool { diff --git a/internal/platform/xorg/touch_native.c b/internal/platform/xorg/touch_native.c index a7a291f..fef26af 100644 --- a/internal/platform/xorg/touch_native.c +++ b/internal/platform/xorg/touch_native.c @@ -11,6 +11,7 @@ #include #include #include +#include Display *cthulhu_window_locator_open(void) { return XOpenDisplay(NULL); } @@ -57,6 +58,45 @@ int cthulhu_window_locator_pid(Display *display, int xres, int x, int y, unsigne return pid > 0 ? pid : 0; } +static int cthulhu_window_title_once(Display *display, Window window, char *title, int size) { + Atom netName = XInternAtom(display, "_NET_WM_NAME", False); + Atom utf8 = XInternAtom(display, "UTF8_STRING", False); + Atom type = None; int format = 0; unsigned long items = 0, after = 0; + unsigned char *data = NULL; + if (XGetWindowProperty(display, window, netName, 0, 256, False, utf8, &type, &format, + &items, &after, &data) == Success && data && type == utf8 && format == 8) { + snprintf(title, size, "%s", (char *)data); + } + if (data) XFree(data); + if (!title[0]) { + char *name = NULL; + if (XFetchName(display, window, &name) && name) { + snprintf(title, size, "%s", name); + XFree(name); + } + } + return title[0] != 0; +} + +// Copy a window's title into title, preferring the UTF-8 _NET_WM_NAME. An +// inner window without a title takes the nearest titled ancestor's. +int cthulhu_window_title(Display *display, unsigned long window, char *title, int size) { + if (!window || size < 1) return 0; + title[0] = 0; + Window root = DefaultRootWindow(display), current = (Window)window; + cthulhu_x11_begin_read(display); + for (int depth = 0; depth < 16 && current != None && current != root; depth++) { + if (cthulhu_window_title_once(display, current, title, size)) break; + Window queryRoot, parent = None, *children = NULL; + unsigned int count = 0; + if (!XQueryTree(display, current, &queryRoot, &parent, &children, &count)) break; + if (children) XFree(children); + current = parent; + } + if (cthulhu_x11_end_read(display)) title[0] = 0; + return title[0] != 0; +} + // Press and release one key, optionally with Shift, for touch desktop // gestures such as Tab and Escape. int cthulhu_touch_key(Display *display, unsigned long keysym, int shift) { diff --git a/internal/platform/xorg/touch_native.h b/internal/platform/xorg/touch_native.h index 17386b8..4326532 100644 --- a/internal/platform/xorg/touch_native.h +++ b/internal/platform/xorg/touch_native.h @@ -14,4 +14,7 @@ int cthulhu_touch_click(Display *display, int x, int y, int button); // Takes and releases the X11 guard; the caller must not hold it. int cthulhu_touch_key(Display *display, unsigned long keysym, int shift); +// Takes and releases the X11 guard; the caller must not hold it. +int cthulhu_window_title(Display *display, unsigned long window, char *title, int size); + #endif diff --git a/internal/platform/xorg/touch_native_test.go b/internal/platform/xorg/touch_native_test.go index ac4321a..48118ac 100644 --- a/internal/platform/xorg/touch_native_test.go +++ b/internal/platform/xorg/touch_native_test.go @@ -50,20 +50,27 @@ func TestNativeWindowLocatorFallbackReleasesGuard(t *testing.T) { } defer pointer.Close() - type result struct{ pid int } + type result struct { + pid int + title string + } done := make(chan result, 1) go func() { - pid, _ := locator.WindowAt(140, 130) + pid, window := locator.WindowAt(140, 130) + title := locator.WindowTitle(window) // Another guarded reader must still get the guard afterwards. pointer.Read() - done <- result{pid} + done <- result{pid, title} }() select { case got := <-done: if locator.xres != 0 && got.pid != client.Process.Pid { t.Fatalf("XRes fallback found pid %d, want xterm %d", got.pid, client.Process.Pid) } - t.Logf("xres=%d pid=%s", locator.xres, strconv.Itoa(got.pid)) + if got.title == "" { + t.Fatal("the window under the point has no title; the nearest titled ancestor was not found") + } + t.Logf("xres=%d pid=%s title=%q", locator.xres, strconv.Itoa(got.pid), got.title) case <-time.After(3 * time.Second): t.Fatal("window lookup left the X11 guard held") }