Touch: fingers reach apps as wl_touch, so a thumb scrolls
Deploy to the handset / build-and-deploy (push) Successful in 2m20s
CI / test (push) Failing after 2m56s

Every touch was turned into a mouse drag in the seat code, which selects text
instead of scrolling. The seat now reports raw touches and the compositor
routes them: to the app as wl_touch on its own content, and to the pointer
(tap, drag, hold for right click, as before) everywhere else and for apps that
don't listen to touches. The cursor is hidden while fingers are in use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Opus 5.5 committed 2026-11-29 22:22:14 -08:00
1 parent 98a99aaa36
commit e30d9cc71f
17 files changed
+786 -126

No files matched your search

+138
View File
@@ -0,0 +1,138 @@
///| Touch (touch.mbt): wl_touch for fingers on an app's content, the pointer everywhere else.
///|
/// A 540x1170 handset with one window, whose client has the pointer and (with `touch`) wl_touch.
fn touch_setup(tag : String, touch : Bool) -> (@host.ChandraCompositor, TestWaylandClient, UInt, UInt) raise {
let path = "/tmp/wayland-moon-touch-" + tag + "-" + @sys.getpid().to_string() + ".sock"
let comp = @host.ChandraCompositor::new(path, @scene.ThemeTokens::moon_night(), 540, 1170).unwrap()
comp.handle_input(Touch(Present), 1U)
let (c, shm, surf, xdg, _, _) = open_and_configure_client(comp, path, "T", "t")
commit_shm_frame(comp, c, shm, surf, xdg, 1UL)
let seat = bind_global(c, 2U, "wl_seat", 7U)
let get = fn(op : UInt) {
let id = c.alloc_id()
let w = @wayland.WireWriter::new()
w.u32(id)
c.send(w.finish_msg(seat, op))
id
}
let ptr = get(0U)
let t = if touch { get(2U) } else { 0U }
for _i = 0; _i < 5; _i = _i + 1 {
comp.step()
@sys.sleep_ms(2)
}
ignore(drain_msgs(c))
(comp, c, ptr, t)
}
///|
fn window_middle(comp : @host.ChandraCompositor) -> (Double, Double) {
let g = comp.windows.get(1UL).unwrap().geometry
((g.x + g.w / 2).to_double(), (g.y + g.h / 2).to_double())
}
///|
test "a finger on an app that listens goes to it as a touch, and no pointer is faked" {
let (comp, c, ptr, t) = touch_setup("client", true)
let (x, y) = window_middle(comp)
comp.handle_input(Touch(Down(0, x, y)), 10U)
comp.handle_input(Touch(Motion(0, x, y - 60.0)), 20U)
comp.handle_input(Touch(Down(1, x + 40.0, y)), 25U) // a second finger
comp.handle_input(Touch(Up(1)), 28U)
comp.handle_input(Touch(Up(0)), 30U)
let msgs = drain_msgs(c)
assert_eq(
msgs.iter().filter(m => m.0 == t).map(m => m.1).to_array(),
[0U, 3U, 2U, 3U, 0U, 3U, 1U, 3U, 1U, 3U], // down motion down up up, each with its frame
)
assert_false(msgs.iter().any(m => m.0 == ptr && m.1 != 1U))
// Holding still is the app's to time: no right click.
comp.handle_input(Touch(Down(0, x, y)), 40U)
@sys.sleep_ms(520)
comp.step()
let msgs = drain_msgs(c)
assert_false(msgs.iter().any(m => m.0 == ptr))
// The screen turning off (or rotating) cancels.
comp.handle_input(Touch(Cancel), 50U)
comp.handle_input(Touch(Up(0)), 51U)
let msgs = drain_msgs(c)
assert_true(has_msg(msgs, t, 4U))
assert_false(has_msg(msgs, t, 1U))
comp.close()
}
///|
test "an app that doesn't listen to touches gets the pointer: tap, drag and hold" {
let (comp, c, ptr, _) = touch_setup("pointer", false)
let (x, y) = window_middle(comp)
let buttons = fn() { drain_msgs(c).iter().filter(m => m.0 == ptr && m.1 == 3U).count() }
comp.handle_input(Touch(Down(0, x, y)), 10U)
assert_eq(buttons(), 0)
comp.handle_input(Touch(Up(0)), 20U)
assert_eq(buttons(), 2) // pressed and released
comp.handle_input(Touch(Down(0, x, y)), 30U)
comp.handle_input(Touch(Motion(0, x + 5.0, y)), 31U)
assert_eq(buttons(), 0)
comp.handle_input(Touch(Motion(0, x + 30.0, y)), 32U)
assert_eq(buttons(), 1)
comp.handle_input(Touch(Up(0)), 33U)
assert_eq(buttons(), 1)
comp.handle_input(Touch(Down(0, x, y)), 40U)
assert_true(comp.wake_timeout(5000) <= 500)
@sys.sleep_ms(520)
comp.step()
assert_eq(buttons(), 2) // the right button
comp.handle_input(Touch(Up(0)), 41U)
assert_eq(buttons(), 0)
comp.close()
}
///|
test "the panel takes a finger as before, and the seat says it has a touchscreen" {
let (comp, c, _, t) = touch_setup("panel", true)
comp.handle_input(Touch(Down(0, 20.0, 1160.0)), 10U)
comp.handle_input(Touch(Up(0)), 20U)
assert_false(drain_msgs(c).iter().any(m => m.0 == t))
let (out, ok) = comp.control_command("input-touch down 0 10")
assert_false(ok)
assert_true(out[0].has_prefix("error usage"))
comp.close()
}
///|
test "a window moved by its own title bar follows the finger that asked for it" {
let (comp, c, shm, surf, xdg, tl) = csd_setup("touchmove")
ignore(gtk_frame(comp, c, shm, surf, xdg, tl))
ignore(gtk_frame(comp, c, shm, surf, xdg, tl))
let seat = bind_global(c, 2U, "wl_seat", 7U)
let t = c.alloc_id()
let w = @wayland.WireWriter::new()
w.u32(t)
c.send(w.finish_msg(seat, 2U))
for _i = 0; _i < 4; _i = _i + 1 {
comp.step()
@sys.sleep_ms(2)
}
let before = comp.windows.get(1UL).unwrap().geometry
let r = comp.windows.get(1UL).unwrap().client_rect()
let (px, py) = ((r.x + r.w / 2).to_double(), (r.y + 15).to_double())
comp.handle_input(Touch(Down(0, px, py)), 10U)
ignore(drain_msgs(c))
let mv = @wayland.WireWriter::new()
mv.u32(0U)
mv.u32(1U)
c.send(mv.finish_msg(tl, 5U))
for _i = 0; _i < 4; _i = _i + 1 {
comp.step()
@sys.sleep_ms(2)
}
assert_true(comp.wm.drag is Some(_))
assert_true(has_msg(drain_msgs(c), t, 4U)) // its touch is cancelled
comp.handle_input(Touch(Motion(0, px + 60.0, py + 40.0)), 12U)
comp.handle_input(Touch(Up(0)), 13U)
let after = comp.windows.get(1UL).unwrap().geometry
assert_eq((after.x - before.x, after.y - before.y), (60, 40))
assert_true(comp.wm.drag is None)
comp.close()
}