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
+312 -31

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
+142 -21
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,12 +134,29 @@ 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 })
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)
}
}
}
}
}
///|
fn ChandraCompositor::touch_motion(
@@ -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()
}
+19
View File
@@ -850,6 +850,25 @@ pub fn DesktopShell::scroll_popup(self : DesktopShell, x : Int, y : Int, px : Do
true
}
///| Whether (x, y) is on the launcher's popup, whose list a finger scrolls.
pub fn DesktopShell::launcher_list_at(self : DesktopShell, x : Int, y : Int) -> Bool {
!(self.menu_open && inside(self.menu_rect, x, y)) &&
(match self.popup_at(x, y) {
Some(w) => w.module_id == launcher_module
None => false
})
}
///| Scroll the open launcher's list by `px` pixels (+: down). False when it didn't move: at an
/// end, or closed.
pub fn DesktopShell::scroll_launcher(self : DesktopShell, px : Int) -> Bool {
match self.open_popup_widget() {
Some(w) if w.module_id == launcher_module =>
self.deliver(w, true, KeyDown("ScrollPx:" + px.to_string()))
_ => false
}
}
///| Close the launcher's popup if it is open.
pub fn DesktopShell::close_launcher(self : DesktopShell) -> Unit {
for w in self.widgets {
+1 -1
View File
@@ -15,7 +15,7 @@ Chandra includes KMS/libinput/compositor adaptations tailored for mainline Linux
## Touch Input & On-Screen Keyboard
- **Touch goes to apps as touch (`wl_touch`):** a finger on an app's own content is the app's: it scrolls with a thumb, flings, pinches and long-presses as that app does ([`compositor/host/touch.mbt`](../compositor/host/touch.mbt)). The seat only says it has a touchscreen when libinput finds one. If the app answers a touch with a window move, resize or drag and drop, its touch is cancelled and the finger drags from there.
- **Elsewhere a finger is a mouse:** on the panel, the on-screen keyboard, the desktop, title bars, dialogs, and apps that don't listen to touches, a tap clicks, a drag is a left-button drag, and a stationary touch held for `500 ms` is a right click.
- **Elsewhere a finger is a mouse:** on the panel, the on-screen keyboard, the desktop, title bars, dialogs, and apps that don't listen to touches, a tap clicks, a drag is a left-button drag, and a stationary touch held for `500 ms` is a right click. The launcher's list is the exception: a drag scrolls it by pixels and a flick keeps it going (`ScrollPx:N` keys to the launcher module); a tap on a moving list only stops it.
- **Cursor:** hidden while fingers are in use; moving a mouse shows it again.
- **Testing:** `chandra-ctl input-touch down ID X Y`, `motion ID X Y`, `up ID`, `cancel` act like the touchscreen.
- **Built-in OSK:** [`compositor/host/osk.mbt`](../compositor/host/osk.mbt) provides a 5-row virtual keyboard that opens automatically when Wayland text input (`zwp_text_input_v3`) gains focus and can also be toggled manually from the **`KB`** (`osk`) panel module. It sits directly above the panel, so the panel stays visible and usable while typing (a strict kiosk has no panel: there it reaches the bottom edge).
+77 -8
View File
@@ -8,7 +8,7 @@
///
/// A catalog too long for the popup gets a category column on its left ("All", then the catalog's
/// own categories: "Chrome Apps", "Games", ...) and a scrollbar; the wheel arrives as the keys
/// "ScrollUp" and "ScrollDown", one row each.
/// "ScrollUp" and "ScrollDown", one row each, and a finger as "ScrollPx:N", N pixels (+: down).
///| Which surface an event is addressed to (mirrors the WIT `surface` enum).
pub(all) enum Target {
@@ -30,6 +30,8 @@ pub struct State {
mut category : String
/// How many listed apps are scrolled off above the first row.
mut scroll : Int
/// ... and how many pixels of the first row (a finger scrolls by pixels).
mut offset : Int
/// Category row under the pointer (-1: none).
mut hover_category : Int
}
@@ -45,6 +47,7 @@ pub fn State::new() -> State {
armed: -1,
category: "",
scroll: 0,
offset: 0,
hover_category: -1,
}
}
@@ -212,6 +215,11 @@ fn first_row(n : Int, st : State) -> Int {
if st.scroll > m { m } else { st.scroll }
}
///| How many pixels of the first row are scrolled off (none at the end of the list).
fn first_part(n : Int, st : State) -> Int {
if st.scroll < max_scroll(n) { st.offset } else { 0 }
}
///| Scroll the list by `rows` (+: down). True when it moved.
fn scroll_by(apps : Array[@types.AppEntry], st : State, rows : Int) -> Bool {
let n = listed(apps, st).length()
@@ -219,19 +227,35 @@ fn scroll_by(apps : Array[@types.AppEntry], st : State, rows : Int) -> Bool {
let to = from + rows
let m = max_scroll(n)
st.scroll = if to < 0 { 0 } else if to > m { m } else { to }
if st.scroll == from {
let part = st.offset
st.offset = 0
if st.scroll == from && part == 0 {
return false
}
st.hover = -1
true
}
///| The app rows the popup draws now, at most `max_rows`. The shell publishes icons for exactly
///| Scroll the list by `px` pixels (+: down), stopping at its ends. True when it moved.
fn scroll_px(apps : Array[@types.AppEntry], st : State, px : Int) -> Bool {
let n = listed(apps, st).length()
let from = first_row(n, st) * row_h + first_part(n, st)
let end = max_scroll(n) * row_h
let to = if from + px < 0 { 0 } else if from + px > end { end } else { from + px }
st.scroll = to / row_h
st.offset = to % row_h
st.hover = -1
to != from
}
///| The app rows the popup draws now: `max_rows` at most, and one more when the first is partly
/// scrolled off. The shell publishes icons for exactly
/// these while the menu is open.
pub fn shown_rows(apps : Array[@types.AppEntry], st : State) -> Array[@types.AppEntry] {
let all = listed(apps, st)
let first = first_row(all.length(), st)
all[first:first + visible_rows(all.length())].to_owned()
let last = first + visible_rows(all.length()) + (if first_part(all.length(), st) > 0 { 1 } else { 0 })
all[first:if last > all.length() { all.length() } else { last }].to_owned()
}
///| Category row under a popup-local point, or -1.
@@ -262,7 +286,7 @@ fn scroll_thumb(n : Int, st : State) -> (Int, Int)? {
}
let track = max_rows * row_h - 8
let th = if track * max_rows / n < 24 { 24 } else { track * max_rows / n }
Some((header_h + 4 + (track - th) * first_row(n, st) / max_scroll(n), th))
Some((header_h + 4 + (track - th) * (first_row(n, st) * row_h + first_part(n, st)) / (max_scroll(n) * row_h), th))
}
///| Side of an app's icon in its row.
@@ -314,6 +338,7 @@ pub fn close(st : State) -> Unit {
st.armed = -1
st.category = ""
st.scroll = 0
st.offset = 0
st.hover_category = -1
}
@@ -404,9 +429,13 @@ pub fn render_popup(
}
let thumb = scroll_thumb(total, st)
let bar = if thumb is Some(_) { scrollbar_w - 6 } else { 0 }
let part = first_part(total, st)
if part > 0 {
ops.push(@types.DrawOp::PushClip(@ui.rect(lx, header_h, w - lx, max_rows * row_h)))
}
for i = 0; i < shown.length(); i = i + 1 {
let a = shown[i]
let y = header_h + i * row_h
let y = header_h + i * row_h - part
let hot = first + i == st.hover
if hot {
ops.push(@ui.fill_rect(@ui.rect(lx + 6, y, w - lx - 12 - bar, row_h - 2), p.accent, radius=r))
@@ -427,6 +456,9 @@ pub fn render_popup(
let about = if a.comment.length() > 0 { a.comment } else { a.category }
ops.push(@ui.text(lx + 56, y + 31, about, fs - 3, sub))
}
if part > 0 {
ops.push(@types.DrawOp::PopClip)
}
match thumb {
Some((ty, th)) => {
ops.push(@ui.fill_rect(@ui.rect(w - 11, header_h + 4, 5, max_rows * row_h - 8), p.surface, radius=2))
@@ -470,8 +502,10 @@ pub fn row_at(apps : Array[@types.AppEntry], st : State, p : @types.Point) -> In
if p.x < lx + 6 || p.x >= right || p.y < header_h {
return -1
}
let i = (p.y - header_h) / row_h
if i < visible_rows(n) { first_row(n, st) + i } else { -1 }
if p.y >= header_h + visible_rows(n) * row_h {
return -1
}
first_row(n, st) + (p.y - header_h + first_part(n, st)) / row_h
}
///| A press at a popup-local point on the scrollbar pages the list. False when it isn't on it.
@@ -545,6 +579,7 @@ pub fn handle_event(
st.category = if c == 0 { "" } else { categories(apps)[c] }
st.query = ""
st.scroll = 0
st.offset = 0
st.hover = -1
return true
}
@@ -576,11 +611,15 @@ pub fn handle_event(
}
st.hover = -1
st.scroll = 0
st.offset = 0
true
} else if k == "ScrollUp" {
scroll_by(apps, st, -1)
} else if k == "ScrollDown" {
scroll_by(apps, st, 1)
} else if k.has_prefix("ScrollPx:") {
let px = @string.parse_int(k[9:]) catch { _ => 0 }
scroll_px(apps, st, px)
} else if k == "Enter" {
if listed(apps, st).length() > 0 {
activate(apps, st, 0, launch)
@@ -590,6 +629,7 @@ pub fn handle_event(
st.query = st.query + k
st.hover = -1
st.scroll = 0
st.offset = 0
true
} else {
false
@@ -924,6 +964,35 @@ test "the list scrolls with the wheel and the scrollbar" {
assert_eq(st.scroll, 0)
}
///|
test "a finger scrolls the list by pixels" {
let apps = long_catalog()
let st = State::new()
st.open = true
let send = fn(k : String) { handle_event(apps, st, Popup, KeyDown(k), _ => Ok(())) }
assert_false(send("ScrollPx:-5"))
assert_true(send("ScrollPx:" + (row_h + 10).to_string()))
assert_eq((st.scroll, st.offset), (1, 10))
assert_eq(shown_rows(apps, st).length(), max_rows + 1)
// Rows are hit where they are drawn, and not below the list.
let x = sidebar_w + 20
assert_eq(row_at(apps, st, { x, y: header_h }), 1)
assert_eq(row_at(apps, st, { x, y: header_h + row_h - 10 }), 2)
assert_eq(row_at(apps, st, { x, y: header_h + max_rows * row_h }), -1)
let ops = render_popup(apps, test_tokens(), st)
assert_true(ops.iter().any(o => o is PushClip(_)) && ops.iter().any(o => o is PopClip))
// To the end, and no further.
assert_true(send("ScrollPx:100000"))
assert_eq((shown_rows(apps, st).last().unwrap().id, st.offset), ("app19", 0))
assert_false(send("ScrollPx:1"))
// The wheel goes back to whole rows; nonsense does nothing.
ignore(send("ScrollPx:-7"))
assert_true(st.offset > 0)
ignore(send("ScrollDown"))
assert_eq(st.offset, 0)
assert_false(send("ScrollPx:x"))
}
///|
fn test_tokens() -> @theme.Tokens {
{
+1
View File
@@ -1,4 +1,5 @@
import {
"moonbitlang/core/string",
"chandra/desktop/interface/chandra/desktop/types" @types,
"chandra/desktop/interface/chandra/desktop/theme" @theme,
"chandra/desktop/lib/ui" @ui,
+1
View File
@@ -57,6 +57,7 @@ pub struct State {
mut armed : Int32
mut category : String
mut scroll : Int32
mut offset : Int32
mut hover_category : Int32
}
pub fn State::new() -> Self