Launcher: a thumb scrolls the app list
Deploy to the handset / build-and-deploy (push) Successful in 2m21s
CI / test (push) Failing after 2m49s

On a touchscreen a drag over the launcher's list scrolls it by pixels, a flick
keeps it going, and a tap still launches (or stops a moving list).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Opus 5.5 committed 2026-11-29 22:40:32 -08:00
1 parent cb0ff0715e
commit 7029c92e6e
8 files changed
+313 -32

No files matched your search

+2 -1
View File
@@ -1094,7 +1094,8 @@ pub fn ChandraCompositor::has_timed_work(self : ChandraCompositor) -> Bool {
self.shell.animating() ||
self.shell.face_busy() ||
self.shell.gamelib_busy() ||
self.kiosk_waiting()
self.kiosk_waiting() ||
self.touch.fling != 0.0
}
///| How long an idle main loop may sleep: `idle_ms` (until the wall clock's next second), or
+143 -22
View File
@@ -1,7 +1,8 @@
///| Touch. Fingers on an app's own content go to the app (wl_touch), which scrolls, pinches and
/// long-presses as it knows how. Everywhere else (the panel, the on-screen keyboard, the desktop,
/// title bars, dialogs, apps that don't listen to touches) one finger works like a mouse: a tap
/// clicks, a drag is a left-button drag, and holding still is a right click.
/// clicks, a drag is a left-button drag, and holding still is a right click. Only the launcher's
/// list scrolls: a drag moves it with the finger, and a quick lift keeps it going.
///| Holding still this long is a right click (apps time their own).
let touch_long_ms : UInt64 = 500UL
@@ -26,12 +27,19 @@ struct TouchPointer {
y0 : Double
since : UInt64
mut phase : TouchPhase
/// The press is on the launcher's list: a drag scrolls it.
list : Bool
/// Where the list was last scrolled to, and the finger's last moves (time, y).
mut y : Double
moves : Array[(UInt, Double)]
}
///|
enum TouchPhase {
Pending
Dragging
/// Scrolling the launcher's list.
Scrolling
/// The right click was made: the rest of the touch does nothing.
Held
} derive(Eq)
@@ -53,11 +61,16 @@ struct TouchClient {
///|
struct TouchState {
mut mode : TouchMode
/// The launcher's list still moving after a lift: pixels per ms, when last moved, and the part
/// of a pixel left over.
mut fling : Double
mut fling_at : UInt64
mut fling_rest : Double
}
///|
fn TouchState::new() -> TouchState {
{ mode: NoTouch }
{ mode: NoTouch, fling: 0.0, fling_at: 0UL, fling_rest: 0.0 }
}
///|
@@ -121,8 +134,25 @@ fn ChandraCompositor::touch_down(
self.server.touch_down(win, time_ms, id, lx, ly, sub~)
}
None => {
self.touch.mode = AsPointer({ id, x0: x, y0: y, since: @sys.monotonic_ms(), phase: Pending })
self.handle_input_inner(PointerMove(x, y), time_ms)
let list = self.touch_list_at(x, y)
// A finger on a moving list holds it; that isn't a tap on what went by.
let held = list && self.touch.fling != 0.0
self.touch.fling = 0.0
self.touch.mode = AsPointer({
id,
x0: x,
y0: y,
since: @sys.monotonic_ms(),
phase: if held { Scrolling } else { Pending },
list,
y,
moves: [(time_ms, y)],
})
if held {
self.note_activity(@sys.monotonic_ms())
} else {
self.handle_input_inner(PointerMove(x, y), time_ms)
}
}
}
}
@@ -139,6 +169,22 @@ fn ChandraCompositor::touch_motion(
match self.touch.mode {
AsPointer(t) =>
if t.id == id {
t.moves.push((time_ms, y))
if t.moves.length() > 16 {
ignore(t.moves.remove(0))
}
if t.list && t.phase == Pending && moved(x - t.x0, y - t.y0) {
t.phase = Scrolling
}
if t.phase == Scrolling {
self.note_activity(@sys.monotonic_ms())
let px = (t.y - y).to_int()
if px != 0 {
t.y = t.y - px.to_double()
ignore(self.scroll_list(px))
}
return
}
if t.phase == Pending && moved(x - t.x0, y - t.y0) {
t.phase = Dragging
self.handle_input_inner(PointerMove(t.x0, t.y0), time_ms)
@@ -179,6 +225,7 @@ fn ChandraCompositor::touch_up(self : ChandraCompositor, id : Int, time_ms : UIn
self.handle_input_inner(PointerButton(272U, false), time_ms)
}
Dragging => self.handle_input_inner(PointerButton(272U, false), time_ms)
Scrolling => self.fling_list(t.moves, time_ms)
Held => ()
}
}
@@ -212,8 +259,75 @@ fn ChandraCompositor::touch_cancel(self : ChandraCompositor, time_ms : UInt) ->
}
}
///| Long presses that are due.
///| Whether a finger at (x, y) is on the launcher's list, with nothing over it.
fn ChandraCompositor::touch_list_at(self : ChandraCompositor, x : Double, y : Double) -> Bool {
let xi = x.to_int()
let yi = y.to_int()
!self.touch_taken(xi, yi) && self.shell.launcher_list_at(xi, yi)
}
///|
fn ChandraCompositor::scroll_list(self : ChandraCompositor, px : Int) -> Bool {
let moved = self.shell.scroll_launcher(px)
if moved {
self.run_shell_actions()
self.damage.mark_full()
}
moved
}
///| The finger left the list: keep it going at the speed of the last 100 ms, if that is a flick.
fn ChandraCompositor::fling_list(
self : ChandraCompositor,
moves : Array[(UInt, Double)],
time_ms : UInt,
) -> Unit {
let recent = moves.filter(m => time_ms - m.0 <= 100U)
guard recent.length() >= 2 else { return }
let (t0, y0) = recent[0]
let (t1, y1) = recent[recent.length() - 1]
guard t1 > t0 else { return }
let v = (y0 - y1) / (t1 - t0).to_double()
if v.abs() >= fling_min {
self.touch.fling = if v > fling_max { fling_max } else if v < -fling_max { -fling_max } else { v }
self.touch.fling_at = @sys.monotonic_ms()
self.touch.fling_rest = 0.0
}
}
///| Move the list on and slow it down; it stops at an end, or when the launcher closes.
fn ChandraCompositor::fling_tick(self : ChandraCompositor) -> Unit {
if self.touch.fling == 0.0 {
return
}
let now = @sys.monotonic_ms()
let dt = (now - self.touch.fling_at).to_double()
if dt <= 0.0 {
return
}
self.touch.fling_at = now
let keep = @math.exp(-dt / fling_ms)
let d = self.touch.fling * fling_ms * (1.0 - keep) + self.touch.fling_rest
let px = d.to_int()
self.touch.fling_rest = d - px.to_double()
self.touch.fling = self.touch.fling * keep
if self.touch.fling.abs() < 0.02 || (px != 0 && !self.scroll_list(px)) {
self.touch.fling = 0.0
}
}
///| Flicks slower than this (pixels per ms) don't keep the list going; none goes faster than that.
let fling_min : Double = 0.15
///|
let fling_max : Double = 5.0
///| How long the list takes to slow to about a third.
let fling_ms : Double = 325.0
///| Long presses that are due, and the list's movement.
fn ChandraCompositor::touch_tick(self : ChandraCompositor) -> Unit {
self.fling_tick()
guard self.touch.mode is AsPointer(t) && t.phase == Pending else { return }
let now = @sys.monotonic_ms()
if now - t.since < touch_long_ms {
@@ -238,6 +352,25 @@ fn ChandraCompositor::touch_wake_ms(self : ChandraCompositor, now : UInt64) -> I
}
}
///| Something other than the apps and the shell has the input at (x, y).
fn ChandraCompositor::touch_taken(self : ChandraCompositor, x : Int, y : Int) -> Bool {
self.screen_off ||
self.manual_screen_off ||
self.locked ||
self.auth is Some(_) ||
self.auth_notice is Some(_) ||
self.shell.face.window is Some(_) ||
self.osk_hit_any(x, y) ||
self.dnd ||
self.emoji_ui is Some(_) ||
self.shot is Some(_) ||
self.shot_edit is Some(_) ||
(self.rec is Some(_) && self.rec_pill().contains(x, y)) ||
self.shell.inspecting() ||
self.wm.drag is Some(_) ||
self.split_drag is Some(_)
}
///| The client's surface a first finger at (x, y) belongs to: (window or popup, subsurface,
/// surface-local position). None: it works the pointer.
fn ChandraCompositor::touch_target(
@@ -247,25 +380,10 @@ fn ChandraCompositor::touch_target(
) -> (UInt64, UInt, Double, Double)? {
let xi = x.to_int()
let yi = y.to_int()
// Something other than the apps has the input, or the press.
if self.screen_off ||
self.manual_screen_off ||
self.locked ||
self.auth is Some(_) ||
self.auth_notice is Some(_) ||
self.shell.face.window is Some(_) ||
self.osk_hit_any(xi, yi) ||
self.dnd ||
self.emoji_ui is Some(_) ||
self.shot is Some(_) ||
self.shot_edit is Some(_) ||
(self.rec is Some(_) && self.rec_pill().contains(xi, yi)) ||
if self.touch_taken(xi, yi) ||
self.ptr_grab ||
self.overview is Some(_) ||
self.shell.inspecting() ||
self.shell.popup_open() ||
self.wm.drag is Some(_) ||
self.split_drag is Some(_) {
self.shell.popup_open() {
return None
}
match self.popup_at(xi, yi) {
@@ -341,6 +459,9 @@ fn ChandraCompositor::touch_handover(self : ChandraCompositor, win : UInt64, act
y0: t.y0,
since: @sys.monotonic_ms(),
phase: Dragging,
list: false,
y: t.y0,
moves: [],
})
}
}
+69
View File
@@ -136,3 +136,72 @@ test "a window moved by its own title bar follows the finger that asked for it"
assert_true(comp.wm.drag is None)
comp.close()
}
///|
test "a finger scrolls the launcher's list: a drag moves it, a flick keeps it going, a tap launches" {
let comp = osk_comp("touchlist", enable_osk=false)
load_handset_modules(comp)
let data = "/tmp/chandra-touch-apps-" + @sys.getpid().to_string()
ignore(@sys.mkdir_p(data + "/applications"))
for i in 0..<30 {
ignore(
@sys.write_file_bytes(
data + "/applications/touch" + i.to_string() + ".desktop",
@sys.str_to_utf8_bytes(
"[Desktop Entry]\nType=Application\nName=Touch " + i.to_string() + "\nExec=true\n",
),
),
)
}
comp.shell.xdg_dirs = { ..comp.shell.xdg_dirs, data_home: data, data_dirs: [] }
comp.shell.toggle_launcher()
comp.shell.toggle_launcher()
comp.shell.toggle_launcher()
for _ in 0..<10 {
@sys.sleep_ms(30)
ignore(comp.compose_frame())
}
let pr = comp.shell.slot_popup_rect(comp.shell.slot_of("launcher"))
let st = comp.shell.launcher_state
assert_eq(comp.shell.apps.length(), 30)
let x = (pr.x + pr.w - 120).to_double()
let y = (pr.y + 300).to_double()
// Past the threshold the list follows the finger by pixels.
comp.handle_input(Touch(Down(0, x, y)), 10U)
comp.handle_input(Touch(Motion(0, x, y - 10.0)), 20U)
assert_eq((st.scroll, st.offset), (0, 0))
comp.handle_input(Touch(Motion(0, x, y - 60.0)), 30U)
assert_eq(st.scroll * 46 + st.offset, 60)
comp.handle_input(Touch(Motion(0, x, y - 50.0)), 300U)
assert_eq(st.scroll * 46 + st.offset, 50)
// Held still, then up: it stays, and nothing was launched.
comp.handle_input(Touch(Motion(0, x, y - 50.0)), 900U)
comp.handle_input(Touch(Up(0)), 910U)
assert_true(st.open)
assert_eq(st.scroll * 46 + st.offset, 50)
// A flick goes on after the lift, and a finger stops it without launching.
comp.handle_input(Touch(Down(0, x, y)), 1000U)
comp.handle_input(Touch(Motion(0, x, y - 40.0)), 1020U)
comp.handle_input(Touch(Motion(0, x, y - 80.0)), 1040U)
comp.handle_input(Touch(Up(0)), 1045U)
let at = st.scroll * 46 + st.offset
assert_eq(at, 130)
assert_true(comp.has_timed_work())
@sys.sleep_ms(30)
comp.step()
assert_true(st.scroll * 46 + st.offset > at)
comp.handle_input(Touch(Down(0, x, y)), 1100U)
let at = st.scroll * 46 + st.offset
comp.handle_input(Touch(Up(0)), 1120U)
@sys.sleep_ms(30)
comp.step()
assert_eq(st.scroll * 46 + st.offset, at)
assert_true(st.open)
// Never past the ends.
comp.handle_input(Touch(Down(0, x, y)), 2000U)
comp.handle_input(Touch(Motion(0, x, y + 5000.0)), 2010U)
comp.handle_input(Touch(Motion(0, x, y + 5000.0)), 2900U)
comp.handle_input(Touch(Up(0)), 2910U)
assert_eq((st.scroll, st.offset), (0, 0))
comp.close()
}