Skip to content

LordOS — a free, fast and secure GNU/Linux distribution based on Debian, with its own desktop environment: display server and Wayland compositor in C, a React UI engine on QuickJS, and private native apps.

Overlay scroll bars system-wide, hidden until used

Federico Pereira9aba68925173
diff --git a/apps/monitor/Processes.jsx b/apps/monitor/Processes.jsx
index d7b0a8b..1dbc727 100644
--- a/apps/monitor/Processes.jsx
+++ b/apps/monitor/Processes.jsx
@@ -461,7 +461,7 @@ function InfoSheet({ want }) {
{!ready ? <Text style={{ fontSize: 12, color: t.textDim }}>{tr('monitor.loading')}</Text>
: d.gone ? <Text style={{ fontSize: 12, color: t.textDim, textAlign: 'start' }}>{tr('monitor.proc.goneHint')}</Text>
: (
- <ScrollView style={{ flex: 1 }} gutter>
+ <ScrollView style={{ flex: 1, marginInlineEnd: -12 }} contentStyle={{ paddingInlineEnd: 12 }}>
<View style={{ paddingBottom: 4 }}>
{tab === 'memory' && <MemoryTab d={d} />}
{tab === 'stats' && <StatsTab d={d} p={live} parent={parent} />}
diff --git a/apps/settings/index.jsx b/apps/settings/index.jsx
index 3f2c88a..3b01aeb 100644
--- a/apps/settings/index.jsx
+++ b/apps/settings/index.jsx
@@ -26,7 +26,7 @@ import { CoolingSettings } from './Cooling.jsx';
import { NotificationsSettings } from './Notifications.jsx';
import { DateTimeSettings } from './DateTime.jsx';
import { DefaultAppsSettings } from './DefaultApps.jsx';
-import { Stack, Section, SettingRow, ValueRow, Badge, Note, Message, Actions, shade } from './ui.jsx';
+import { Stack, Section, SettingRow, ValueRow, Badge, Note, Message, Actions, PopUp, shade } from './ui.jsx';
export function Icon({ size: s }) {
const dark = '#3b3e46';
@@ -124,6 +124,12 @@ function Appearance() {
<Toggle small on={!!s.reduceMotion} onChange={(reduceMotion) => set({ reduceMotion })} />
</SettingRow>
</Section>
+ <Section footer={tr('settings.scrollBarsHint')}>
+ <SettingRow label={tr('settings.scrollBars')}>
+ <PopUp width={170} value={s.scrollBars || 'auto'} onChange={(scrollBars) => set({ scrollBars })}
+ options={[['auto', tr('settings.scrollBarsAuto')], ['scrolling', tr('settings.scrollBarsScrolling')], ['always', tr('settings.scrollBarsAlways')]]} />
+ </SettingRow>
+ </Section>
</Stack>
);
}
diff --git a/assets/locales/en/settings.json b/assets/locales/en/settings.json
index 2109c10..657e076 100644
--- a/assets/locales/en/settings.json
+++ b/assets/locales/en/settings.json
@@ -252,6 +252,11 @@
"keywords.cooling": "fan fans temperature cooling heat noise curve case full speed",
"reduceMotion": "Reduce motion",
"reduceMotionHint": "Stops decorative animations, like the spinning fan in Cooling.",
+ "scrollBars": "Show scroll bars",
+ "scrollBarsAuto": "Automatically",
+ "scrollBarsScrolling": "When scrolling",
+ "scrollBarsAlways": "Always",
+ "scrollBarsHint": "Automatically: a thin bar appears at the edge while you scroll or point near it. When scrolling: only while you scroll. Always: it stays visible.",
"sharing.onlyAdmins": "Only administrators",
"sharing.ssh": "Remote login (SSH)",
"sharing.sshFingerprint": "Host key fingerprint (compare it with the one ssh shows the first time you connect):",
diff --git a/assets/locales/es/settings.json b/assets/locales/es/settings.json
index cfc4050..5858b2d 100644
--- a/assets/locales/es/settings.json
+++ b/assets/locales/es/settings.json
@@ -252,6 +252,11 @@
"keywords.cooling": "ventilador ventiladores temperatura refrigeración calor ruido curva caja a tope fan cooling",
"reduceMotion": "Reducir movimiento",
"reduceMotionHint": "Detiene las animaciones decorativas, como el ventilador que gira en Refrigeración.",
+ "scrollBars": "Mostrar barras de desplazamiento",
+ "scrollBarsAuto": "Automáticamente",
+ "scrollBarsScrolling": "Al desplazarse",
+ "scrollBarsAlways": "Siempre",
+ "scrollBarsHint": "Automáticamente: aparece una barra fina en el borde mientras te desplazas o acercas el puntero. Al desplazarse: solo mientras te desplazas. Siempre: queda visible.",
"sharing.onlyAdmins": "Solo administradores",
"sharing.ssh": "Inicio de sesión remoto (SSH)",
"sharing.sshFingerprint": "Huella de la clave del equipo (comparala con la que muestra ssh la primera vez que te conectás):",
diff --git a/assets/locales/pt/settings.json b/assets/locales/pt/settings.json
index c108211..2dac00e 100644
--- a/assets/locales/pt/settings.json
+++ b/assets/locales/pt/settings.json
@@ -252,6 +252,11 @@
"keywords.cooling": "ventoinha ventoinhas temperatura resfriamento calor ruído curva gabinete máxima fan cooling",
"reduceMotion": "Reduzir movimento",
"reduceMotionHint": "Para as animações decorativas, como a ventoinha girando em Resfriamento.",
+ "scrollBars": "Mostrar barras de rolagem",
+ "scrollBarsAuto": "Automaticamente",
+ "scrollBarsScrolling": "Ao rolar",
+ "scrollBarsAlways": "Sempre",
+ "scrollBarsHint": "Automaticamente: uma barra fina aparece na borda enquanto você rola ou aproxima o ponteiro. Ao rolar: só enquanto você rola. Sempre: fica visível.",
"sharing.onlyAdmins": "Somente administradores",
"sharing.ssh": "Login remoto (SSH)",
"sharing.sshFingerprint": "Impressão digital da chave do computador (compare com a que o ssh mostra na primeira conexão):",
diff --git a/docs/DESIGN.md b/docs/DESIGN.md
index ea34064..425f814 100644
--- a/docs/DESIGN.md
+++ b/docs/DESIGN.md
@@ -153,6 +153,42 @@ the Recorder draw their empty-state icons. `↻ ⤮ ♪ ◫ ▣ ☺ ≡` render
right-aligned label column. Measure the pane: under 480 px the labels go above their controls.
Lists of editable items (key mappings, triggers, shortcuts) are inset `GroupBox` rows.
+## Scroll bars (0.8.3)
+
+Every scrolling area uses the SDK's `ScrollView`, which draws an **overlay scroll bar**
+(`sdk/components.jsx`, model in `sdk/scrollbar.js`):
+
+- **Over the content, at the very edge:** a 6 px thumb, 2 px from the end edge of the view (and from
+ its top and bottom), widening to 10 px and darkening under the pointer or while dragged. It never
+ reserves a strip: **give the content its normal padding** (`contentStyle`, or a padded first
+ child) and the bar sits in it. Content that should run to the edge of a card can bleed into the
+ card's padding: `style={{ marginHorizontal: -12 }} contentStyle={{ paddingHorizontal: 12 }}`
+ (Monitor → Network). At least 12 px of end padding keeps the widened bar off the text.
+- **Hidden until used:** it appears while the view scrolls (wheel, touchpad, a keyboard jump through
+ `scrollRef.scrollTo`, dragging the thumb) and, with *Automatically*, when the pointer comes within
+ 16 px of the edge; it fades out over 200 ms a second after the last scroll. Settings → Appearance
+ → **Show scroll bars**: *Automatically* (default), *When scrolling* (no pointer reveal), *Always*
+ (a persistent bar, for accessibility; the 0.8.1 `gutter` prop reserves an 11 px strip only in this
+ mode). With **Reduce motion** it shows and hides without the fade.
+- **Hit-testing:** while shown, a 14 px strip at the edge over the thumb takes the pointer, so the
+ thumb can be dragged; while hidden it has `pointerEvents: 'none'` and clicks reach the content.
+ The fade changes only the thumb's opacity with `lord.setStyle` (no React render per frame).
+- **Direction and themes:** the bar is on the end edge (`end`), so on the left in right-to-left
+ languages. The theme styles it with the optional tokens `scrollThumb`, `scrollThumbHover`,
+ `scrollRadius` and `scrollThumbBorder` (a pill in Lord Default; the Classic theme's is squarer and
+ solid with a hairline). `ThemeProvider` passes the setting (`scrollBars`) and `reduceMotion` with
+ the tokens, so isolated apps follow them too.
+- The Terminal's history bar (drawn in C, `term_paint.c`) uses the same size and inset and shows
+ only while you look at the history.
+
+Tests: `tests/scrollbar_model_test.mjs` (geometry, thumb hit-test and drag, show/hide per mode,
+fade timing, reduce motion) and `test_overlay_scrollbar` in `build/engine-test` (painted over the
+content, no strip reserved, never over the text, the strip takes the pointer only while shown,
+the faded opacity, RTL). Screenshots: `scrollbars-network-{light,dark}-{hidden,scrolling}.png`,
+`scrollbars-settings-{light,dark}.png`.
+
+![Monitor → Network while scrolling](scrollbars-network-light-scrolling.png)
+
## Robustness checklist
Check every pass on the VM with:
diff --git a/docs/scrollbars-settings-dark.png b/docs/scrollbars-settings-dark.png
new file mode 100644
index 0000000..197412f
Binary files /dev/null and b/docs/scrollbars-settings-dark.png differ
diff --git a/docs/scrollbars-settings-light.png b/docs/scrollbars-settings-light.png
new file mode 100644
index 0000000..4c807c3
Binary files /dev/null and b/docs/scrollbars-settings-light.png differ
diff --git a/sdk/components.jsx b/sdk/components.jsx
index 9b6233a..05bdb50 100644
--- a/sdk/components.jsx
+++ b/sdk/components.jsx
@@ -5,7 +5,8 @@ import { createContext, useContext, useEffect, useRef, useState } from 'react';
import { useTheme } from './theme.js';
import { getApp, windows, openedAt } from './windows.js';
import { useStore } from './store.js';
-import { textDirection } from './i18n.js';
+import { textDirection, direction } from './i18n.js';
+import { SCROLLBAR, scrollbarMode, thumbGeometry, offsetForThumb, nearEdge, hitThumb, barShown, barOpacity, hideTime, barWidth } from './scrollbar.js';
import { ime, useIme, Preedit } from './ime.js';
// Push button. Optional (all additive): small (22 px high), plain (no fill until hover), disabled,
@@ -85,36 +86,145 @@ export function SectionTitle({ children }) {
return <Text style={{ fontSize: 11, fontWeight: 600, color: t.textDim, marginLeft: 10, marginTop: 10, marginBottom: 4 }}>{children}</Text>;
}
-// Container with mouse-wheel scrolling and an indicator bar.
-// scrollRef (optional): { scrollTo(y), offset(), inner } to jump to a position (an index).
-// gutter (optional): keep a strip on the right for the indicator bar, so it never covers the
-// content (the bar is always on the right, in right-to-left languages too).
+// Container with mouse-wheel / touchpad scrolling and an overlay scroll bar (sdk/scrollbar.js,
+// docs/DESIGN.md "Scroll bars"): a thin bar drawn over the content at the end edge (left in RTL),
+// hidden until the view scrolls or the pointer comes near the edge, fading out a second after the
+// last scroll. It never reserves a strip: give the content its normal padding (contentStyle) and
+// the bar sits in it. Settings → Appearance → "Show scroll bars" (theme token scrollBars:
+// 'auto' | 'scrolling' | 'always'); reduce motion shows and hides it without a fade.
+// scrollRef (optional): { scrollTo(y), offset(), inner } to jump to a position (an index, a key
+// press); a jump that moves the view shows the bar like any other scroll.
+// contentStyle (optional): style of the scrolled content box (its padding).
+// gutter (0.8.1, optional): with "Always" only, keep a strip at the end for the bar.
export const SCROLL_GUTTER = 11;
-export function ScrollView({ style, children, scrollRef, gutter }) {
+export function ScrollView({ style, contentStyle, children, scrollRef, gutter }) {
const t = useTheme();
- const outer = useRef(null), inner = useRef(null);
+ const mode = scrollbarMode(t.scrollBars);
+ const reduce = !!t.reduceMotion;
+ const rtl = direction() === 'rtl';
+ const outer = useRef(null), inner = useRef(null), thumb = useRef(null);
const [offset, setOffset] = useState(0);
const [metrics, setMetrics] = useState({ view: 0, content: 0 });
+ const [ui, setUi] = useState({ near: false, hover: false, dragging: false, shown: mode === 'always' });
+ const st = useRef(null);
+ if (!st.current) st.current = { lastScroll: null, hideTimer: 0, fadeTimer: 0, grab: 0, ui };
+ st.current.ui = ui; st.current.mode = mode; st.current.reduce = reduce; st.current.metrics = metrics;
const measure = () => {
if (!outer.current || !inner.current) return null;
const view = lord.getLayout(outer.current.id)[3], content = lord.getLayout(inner.current.id)[3];
- if (view !== metrics.view || content !== metrics.content) setMetrics({ view, content });
+ const m = st.current.metrics;
+ if (view !== m.view || content !== m.content) { st.current.metrics = { view, content }; setMetrics({ view, content }); }
return { view, content };
};
useEffect(() => { const id = setTimeout(measure, 50); return () => clearTimeout(id); });
const max = Math.max(0, metrics.content - metrics.view);
const y = Math.min(offset, max);
- const bar = metrics.content > 0 ? Math.max(24, (metrics.view * metrics.view) / metrics.content) : 0;
- if (scrollRef) scrollRef.current = { scrollTo: (v) => { measure(); setOffset(Math.max(0, v)); }, offset: () => y, inner };
+ const geom = thumbGeometry(metrics.view, metrics.content, y);
+
+ // ---- showing and hiding ----
+ const setOpacity = (o) => { try { if (thumb.current) lord.setStyle(thumb.current.id, 'opacity', o); } catch (e) { /* unmounted */ } };
+ const update = (patch) => setUi((u) => {
+ const n = { ...u, ...patch };
+ return n.near === u.near && n.hover === u.hover && n.dragging === u.dragging && n.shown === u.shown ? u : n;
+ });
+ const model = () => ({ mode: st.current.mode, lastScroll: st.current.lastScroll, ...st.current.ui });
+ const stopFade = () => { clearInterval(st.current.fadeTimer); st.current.fadeTimer = 0; };
+ const schedule = () => {
+ const s = st.current;
+ clearTimeout(s.hideTimer);
+ const at = hideTime(model());
+ if (at == null) return;
+ s.hideTimer = setTimeout(() => {
+ if (!s.ui.shown) return;
+ if (barShown(model(), lord.now())) { schedule(); return; }
+ if (s.reduce) { s.ui = { ...s.ui, shown: false }; update({ shown: false }); return; }
+ const t0 = lord.now();
+ stopFade();
+ s.fadeTimer = setInterval(() => {
+ const o = barOpacity(model(), lord.now(), t0, false);
+ setOpacity(o);
+ if (o <= 0) { stopFade(); s.ui = { ...s.ui, shown: false }; update({ shown: false }); }
+ }, 33);
+ }, Math.max(0, at - lord.now()));
+ };
+ const show = (patch) => {
+ stopFade();
+ setOpacity(1);
+ st.current.ui = { ...st.current.ui, ...patch, shown: true };
+ update({ ...patch, shown: true });
+ schedule();
+ };
+ const scrolled = () => { st.current.lastScroll = lord.now(); show({}); };
+ useEffect(() => () => { clearTimeout(st.current.hideTimer); stopFade(); }, []);
+ useEffect(() => { if (mode === 'always') show({}); else schedule(); }, [mode]);
+
+ // ---- dragging the thumb ----
+ useEffect(() => {
+ const a = addListener('pointermove', (e) => {
+ const s = st.current;
+ if (!s.ui.dragging || !outer.current) return;
+ const [, oy] = lord.getLayout(outer.current.id);
+ const m = s.metrics;
+ setOffset(offsetForThumb(m.view, m.content, e.y - oy - s.grab));
+ s.lastScroll = lord.now();
+ });
+ const b = addListener('pointerup', () => {
+ const s = st.current;
+ if (!s.ui.dragging) return;
+ s.lastScroll = lord.now();
+ s.ui = { ...s.ui, dragging: false };
+ update({ dragging: false });
+ schedule();
+ });
+ return () => { a(); b(); };
+ }, []);
+
+ if (scrollRef) scrollRef.current = { scrollTo: (v) => {
+ const m = measure() || metrics;
+ const to = Math.max(0, Math.min(Math.max(0, m.content - m.view), v));
+ if (Math.round(to) !== Math.round(y)) scrolled();
+ setOffset(Math.max(0, v));
+ }, offset: () => y, inner };
+
+ const onMove = (e) => {
+ if (!outer.current) return;
+ const [ox, oy, ow] = lord.getLayout(outer.current.id);
+ const near = !!geom && nearEdge(e.x - ox, ow, rtl);
+ const hover = !!geom && st.current.ui.shown && hitThumb(e.x - ox, e.y - oy, ow, geom, rtl);
+ const u = st.current.ui;
+ if (near === u.near && hover === u.hover) return;
+ if (mode === 'auto' && near && !u.near) show({ near, hover });
+ else { st.current.ui = { ...u, near, hover }; update({ near, hover }); schedule(); }
+ };
+ const shown = mode === 'always' || ui.shown;
+ const wide = ui.hover || ui.dragging;
+ const thumbColor = wide ? (t.scrollThumbHover || (t.mode === 'dark' ? 'rgba(255,255,255,0.5)' : 'rgba(0,0,0,0.45)'))
+ : (t.scrollThumb || (t.mode === 'dark' ? 'rgba(255,255,255,0.32)' : 'rgba(0,0,0,0.3)'));
+ const w = barWidth(ui);
+ const pad = gutter && mode === 'always' ? { paddingInlineEnd: SCROLL_GUTTER } : null;
return (
<View ref={outer} onWheel={(e) => {
const m = measure() || metrics;
- setOffset((o) => Math.max(0, Math.min(Math.max(0, m.content - m.view), Math.min(o, max) + e.deltaY)));
- }} style={[{ overflow: 'hidden', flex: 1 }, style]}>
- <View ref={inner} style={gutter ? { translateY: -y, paddingRight: SCROLL_GUTTER } : { translateY: -y }}>{children}</View>
- {max > 0 && (
- <View style={{ position: 'absolute', right: 3, width: 5, borderRadius: 3, height: bar,
- top: (metrics.view - bar) * (y / max), backgroundColor: t.mode === 'dark' ? 'rgba(255,255,255,0.3)' : 'rgba(0,0,0,0.3)' }} />
+ const mx = Math.max(0, m.content - m.view);
+ if (mx > 0 && e.deltaY) scrolled();
+ setOffset((o) => Math.max(0, Math.min(mx, Math.min(o, max) + e.deltaY)));
+ }} onMouseMove={onMove} onMouseLeave={() => { st.current.ui = { ...st.current.ui, near: false, hover: false }; update({ near: false, hover: false }); schedule(); }}
+ style={[{ overflow: 'hidden', flex: 1 }, style]}>
+ <View ref={inner} style={[{ translateY: -y }, pad, contentStyle]}>{children}</View>
+ {geom && (
+ <View onMouseDown={(e) => {
+ if (!outer.current) return;
+ const [, oy] = lord.getLayout(outer.current.id);
+ e.stopPropagation();
+ st.current.grab = e.y - oy - geom.top;
+ st.current.ui = { ...st.current.ui, dragging: true };
+ show({ dragging: true });
+ }} style={{ position: 'absolute', end: 0, top: geom.top, width: SCROLLBAR.hit, height: geom.size,
+ pointerEvents: shown ? 'auto' : 'none' }}>
+ <View ref={thumb} style={{ position: 'absolute', end: SCROLLBAR.inset, top: 0, height: geom.size, width: w,
+ borderRadius: t.scrollRadius != null ? Math.min(t.scrollRadius, w / 2) : w / 2, backgroundColor: thumbColor,
+ ...(t.scrollThumbBorder ? { border: `1px solid ${t.scrollThumbBorder}` } : null), opacity: shown ? 1 : 0 }} />
+ </View>
)}
</View>
);
diff --git a/sdk/scrollbar.js b/sdk/scrollbar.js
new file mode 100644
index 0000000..6fc18ed
--- /dev/null
+++ b/sdk/scrollbar.js
@@ -0,0 +1,89 @@
+// scrollbar.js — the model of the overlay scroll bar drawn by ScrollView (sdk/components.jsx).
+// Pure functions, no engine calls, so tests/scrollbar_model_test.mjs checks them under node.
+// See docs/DESIGN.md, "Scroll bars".
+//
+// The bar is drawn over the content at the very edge (the end edge: right, or left in RTL), never
+// reserving a strip: content keeps its normal padding and the thin bar sits in it. It is hidden
+// until the view scrolls (wheel, touchpad, keyboard, dragging the thumb) or, in 'auto', until the
+// pointer comes near the edge; it fades out a second after the last scroll.
+
+export const SCROLLBAR = {
+ thin: 6, // width of the thumb at rest
+ wide: 10, // width while the pointer is over it or it is being dragged
+ inset: 2, // from the edge of the view (and from its top and bottom)
+ hit: 14, // width of the strip that takes the pointer while the bar is shown
+ edge: 16, // pointer this close to the edge shows the bar ('auto')
+ minThumb: 24, // the thumb never gets shorter
+ hideAfter: 1000, // ms after the last scroll before it starts fading
+ fade: 200, // ms of the fade out (none with reduce motion)
+};
+
+// Settings → Appearance → Show scroll bars
+export const SCROLLBAR_MODES = ['auto', 'scrolling', 'always'];
+export const scrollbarMode = (m) => (SCROLLBAR_MODES.includes(m) ? m : 'auto');
+
+// Thumb geometry for a view `view` px high showing `content` px of content scrolled by `offset`.
+// null when everything fits (no bar at all).
+export function thumbGeometry(view, content, offset) {
+ if (!(view > 0) || !(content > view)) return null;
+ const max = content - view;
+ const track = Math.max(0, view - SCROLLBAR.inset * 2);
+ const size = Math.min(track, Math.max(SCROLLBAR.minThumb, (track * view) / content));
+ const y = Math.max(0, Math.min(max, offset));
+ const top = SCROLLBAR.inset + (track - size) * (y / max);
+ return { max, track, size, top };
+}
+
+// Dragging: the offset that puts the thumb's top at `thumbTop` (view coordinates).
+export function offsetForThumb(view, content, thumbTop) {
+ const g = thumbGeometry(view, content, 0);
+ if (!g) return 0;
+ const room = g.track - g.size;
+ if (room <= 0) return 0;
+ const f = Math.max(0, Math.min(1, (thumbTop - SCROLLBAR.inset) / room));
+ return f * g.max;
+}
+
+// Distance of a point (x relative to the view's left edge) from the bar's edge.
+const fromEdge = (x, width, rtl) => (rtl ? x : width - x);
+
+// Is the pointer near the edge where the bar lives?
+export const nearEdge = (x, width, rtl) => {
+ const d = fromEdge(x, width, rtl);
+ return d >= 0 && d <= SCROLLBAR.edge;
+};
+
+// Does a point (view coordinates) fall on the thumb's hit strip?
+export function hitThumb(x, y, width, geom, rtl) {
+ if (!geom) return false;
+ const d = fromEdge(x, width, rtl);
+ return d >= 0 && d <= SCROLLBAR.hit && y >= geom.top && y <= geom.top + geom.size;
+}
+
+// Whether the bar is shown at time `now` (ms). s = { mode, lastScroll, near, hover, dragging }.
+export function barShown(s, now) {
+ const mode = scrollbarMode(s.mode);
+ if (mode === 'always' || s.dragging) return true;
+ if (s.lastScroll != null && now - s.lastScroll < SCROLLBAR.hideAfter) return true;
+ return mode === 'auto' && !!(s.near || s.hover);
+}
+
+// Opacity at `now`: 1 while shown, then a linear fade over SCROLLBAR.fade ms after the moment it
+// stopped being shown (`hiddenAt`). With reduce motion it just goes from 1 to 0.
+export function barOpacity(s, now, hiddenAt, reduceMotion) {
+ if (barShown(s, now)) return 1;
+ if (reduceMotion || hiddenAt == null) return 0;
+ const k = (now - hiddenAt) / SCROLLBAR.fade;
+ return k >= 1 ? 0 : Math.max(0, 1 - k);
+}
+
+// When the bar stops being shown if nothing else happens (ms), or null if it stays.
+export function hideTime(s) {
+ const mode = scrollbarMode(s.mode);
+ if (mode === 'always' || s.dragging) return null;
+ if (mode === 'auto' && (s.near || s.hover)) return null;
+ return s.lastScroll == null ? 0 : s.lastScroll + SCROLLBAR.hideAfter;
+}
+
+// Thumb width: wide under the pointer or while dragging.
+export const barWidth = (s) => (s.hover || s.dragging ? SCROLLBAR.wide : SCROLLBAR.thin);
diff --git a/sdk/settings.js b/sdk/settings.js
index da66572..116065c 100644
--- a/sdk/settings.js
+++ b/sdk/settings.js
@@ -7,6 +7,7 @@ const DEFAULTS = {
accent: 'azul',
effects: true, // transparency with blur
reduceMotion: false, // decorative animations off (Settings → Appearance)
+ scrollBars: 'auto', // 0.8.3, Settings → Appearance → Show scroll bars: 'auto' | 'scrolling' | 'always'
wallpaper: DEFAULT_WALLPAPER, // 0.8.2: Lumo Celestial (before: 'aurora', still available)
keyboard: 'latam', // before M5; now keyboards (see keyboard.js)
keyboards: null, // [{ layout, variant }] from xkb-data
diff --git a/sdk/theme.js b/sdk/theme.js
index 72351c8..8ad9e8e 100644
--- a/sdk/theme.js
+++ b/sdk/theme.js
@@ -49,8 +49,17 @@ function syncPortal(value) {
} catch (e) { /* no portal */ }
}
+// Settings every app's controls follow, carried with the tokens so isolated apps (which have no
+// settings file of their own) get them too: the scroll bars' mode (Settings → Appearance → Show
+// scroll bars, sdk/scrollbar.js) and reduce motion. Tokens the theme (or, in an isolated app, the
+// published tokens) already carry win.
+function settingTokens() {
+ const s = settings.get();
+ return { scrollBars: s.scrollBars || 'auto', reduceMotion: !!s.reduceMotion };
+}
+
export function ThemeProvider({ tokens, children }) {
- const value = { ...DEFAULT_TOKENS, ...tokens };
+ const value = { ...DEFAULT_TOKENS, ...settingTokens(), ...tokens };
useEffect(() => { publishTokens(value); syncPortal(value); });
return createElement(ThemeContext.Provider, { value }, children);
}
diff --git a/server/src/term/term_paint.c b/server/src/term/term_paint.c
index 33bed79..13d3967 100644
--- a/server/src/term/term_paint.c
+++ b/server/src/term/term_paint.c
@@ -754,13 +754,14 @@ void term_paint(Canvas *c, int id, float x, float y, float w, float h, float op)
}
}
- /* scroll bar while looking at the history */
+ /* scroll bar while looking at the history: an overlay like ScrollView's (docs/DESIGN.md, "Scroll
+ * bars"), 6 px wide and 2 px from the edge, only while scrolled back */
int total = t->buf->count;
if (t->view > 0 && total > t->rows) {
- float track = h - 8, bar = fmaxf(24, track * t->rows / total);
+ float track = h - 4, bar = fmaxf(24, track * t->rows / total);
float pos = (float)(total - t->rows - t->view) / (total - t->rows);
- int by = (int)(y + 4 + (track - bar) * pos);
- fill(c, (int)(x + w) - 7, by, (int)(x + w) - 3, by + (int)bar, 0x80000000u | ((lum(dbg) < 0.25f ? 0xffffff : 0x000000)));
+ int by = (int)(y + 2 + (track - bar) * pos);
+ fill(c, (int)(x + w) - 8, by, (int)(x + w) - 2, by + (int)bar, 0x80000000u | ((lum(dbg) < 0.25f ? 0xffffff : 0x000000)));
}
s->drawn_cx = t->cx;
diff --git a/server/tests/engine_test.c b/server/tests/engine_test.c
index b97736f..e065cec 100644
--- a/server/tests/engine_test.c
+++ b/server/tests/engine_test.c
@@ -199,6 +199,7 @@ static void test_ellipsis(void) {
#endif
/* ---- nodes ---- */
+static Node *text(Node *parent, const char *s, float size);
static Node *view(Node *parent) {
Node *n = node_new(NODE_VIEW);
if (parent) node_append(parent, n);
@@ -779,6 +780,83 @@ static void test_transform_paint_hit(void) {
CHECK(soft == 0, "blurry row inside the scaled bar at 150%% (%d px)", soft);
}
+/* The overlay scroll bar as ScrollView (sdk/components.jsx, sdk/scrollbar.js) builds it: an
+ * overflow-hidden view, the content translated inside it with its normal end padding, and over it a
+ * 14 px hit strip at the end edge holding the 6 px thumb 2 px from the edge. The bar is painted
+ * over the content (no strip reserved), never over the text, takes the pointer only while shown,
+ * fades by opacity and goes to the left in RTL. */
+static void test_overlay_scrollbar(void) {
+ ui_reset();
+ Node *root = view(NULL);
+ ui.root = root;
+ sn(root, "backgroundColor", 0xffffffff);
+ Node *sv = view(root); /* the ScrollView: 200 × 100 */
+ ss(sv, "position", "absolute");
+ sn(sv, "left", 20); sn(sv, "top", 10); sn(sv, "width", 200); sn(sv, "height", 100);
+ ss(sv, "overflow", "hidden");
+ Node *in = view(sv); /* content: 400 high, 12 px end padding */
+ sn(in, "backgroundColor", 0xffddeeff);
+ sn(in, "paddingEnd", 12);
+ sn(in, "translateY", -40);
+ Node *rows[8], *label = NULL;
+ for (int i = 0; i < 8; i++) {
+ rows[i] = view(in);
+ sn(rows[i], "height", 50);
+ ss(rows[i], "flexDirection", "row");
+ Node *tx = text(rows[i], "Value 1,234 MB", 12);
+ sn(tx, "flexGrow", 1); ss(tx, "textAlign", "end"); ss(tx, "whiteSpace", "nowrap");
+ if (i == 1) label = tx;
+ }
+ /* thumb geometry for view 100 / content 400 / offset 40: track 96, size 24, top 2 + 72 * 40/300 */
+ float top = 2 + (96 - 24) * (40.0f / 300.0f);
+ Node *strip = view(sv);
+ ss(strip, "position", "absolute");
+ sn(strip, "end", 0); sn(strip, "top", top); sn(strip, "width", 14); sn(strip, "height", 24);
+ Node *thumb = view(strip);
+ ss(thumb, "position", "absolute");
+ sn(thumb, "end", 2); sn(thumb, "top", 0); sn(thumb, "width", 6); sn(thumb, "height", 24);
+ sn(thumb, "borderRadius", 3); sn(thumb, "backgroundColor", 0xff808080); sn(thumb, "opacity", 1);
+ render(root, 240, 120);
+
+ int tx = (int)(sv->ax + 200 - 2 - 3), ty = (int)(sv->ay + top + 12); /* the thumb's center */
+ CHECK(in->w == 200, "the content keeps the full width (no strip reserved): %g", in->w);
+ CHECK(pix(tx, ty) == 0x808080, "thumb painted over the content: %06x", pix(tx, ty));
+ CHECK(pix((int)(sv->ax + 199), ty) == 0xddeeff, "2 px inset: the edge shows the content: %06x", pix((int)(sv->ax + 199), ty));
+ CHECK(pix((int)(sv->ax + 200 - 8 - 2), ty) == 0xddeeff, "thumb wider than 6 px: %06x", pix((int)(sv->ax + 190), ty));
+ CHECK(label && label->ax + label->w <= thumb->ax, "the text (ends at %g) runs under the thumb (starts at %g)",
+ label ? label->ax + label->w : -1, thumb->ax);
+ CHECK(fabsf(rows[1]->ay - (sv->ay + 50 - 40)) < 0.5f, "content scrolled by translateY: row at %g", rows[1]->ay);
+ /* hit testing: the strip takes the pointer (drag), just outside it the content does */
+ CHECK(hit_test(root, (float)tx, (float)ty) == thumb || hit_test(root, (float)tx, (float)ty) == strip, "thumb not hit");
+ CHECK(hit_test(root, sv->ax + 200 - 13, (float)ty) == strip, "the 14 px strip is not hit at its start");
+ CHECK(hit_test(root, sv->ax + 200 - 15, (float)ty) != strip && hit_test(root, sv->ax + 200 - 15, (float)ty) != thumb, "hit outside the strip");
+ CHECK(hit_test(root, (float)tx, sv->ay + top + 30) != strip, "hit below the thumb went to the strip");
+
+ /* fading: half opacity blends the thumb with the content */
+ sn(thumb, "opacity", 0.5);
+ render(root, 240, 120);
+ uint32_t p = pix(tx, ty);
+ int r = (int)(p >> 16 & 0xff), b = (int)(p & 0xff);
+ CHECK(r > 0x90 && r < 0xd0 && b > 0x90 && b < 0xf0, "half-faded thumb: %06x", p);
+ /* hidden: opacity 0 and pointerEvents none: nothing painted, the click goes to the content */
+ sn(thumb, "opacity", 0);
+ ss(strip, "pointerEvents", "none");
+ render(root, 240, 120);
+ CHECK(pix(tx, ty) == 0xddeeff, "hidden thumb painted: %06x", pix(tx, ty));
+ Node *h = hit_test(root, (float)tx, (float)ty);
+ CHECK(h != strip && h != thumb, "a hidden bar takes the click");
+
+ /* RTL: the bar is on the left edge */
+ sn(thumb, "opacity", 1);
+ ss(strip, "pointerEvents", "auto");
+ ss(sv, "direction", "rtl");
+ node_invalidate(sv);
+ render(root, 240, 120);
+ CHECK(fabsf(strip->ax - sv->ax) < 0.5f, "RTL strip at the left edge: %g (view at %g)", strip->ax, sv->ax);
+ CHECK(pix((int)(sv->ax + 2 + 3), ty) == 0x808080, "RTL thumb painted on the left: %06x", pix((int)(sv->ax + 5), ty));
+ CHECK(pix((int)(sv->ax + 200 - 5), ty) != 0x808080, "RTL thumb still on the right");
+}
+
#endif
/* ---- benchmark: a Files-like list and a window drag (docs/DESIGN.md, Engine notes) ---- */
@@ -980,6 +1058,7 @@ int main(int argc, char **argv) {
test_multi_damage();
test_minimize_damage();
test_grow_wrap_height();
+ test_overlay_scrollbar();
printf("engine-test: %d checks, %d failures\n", checks, fails);
return fails ? 1 : 0;
#endif
diff --git a/server/tests/run_suites.sh b/server/tests/run_suites.sh
index 89e6398..778118b 100644
--- a/server/tests/run_suites.sh
+++ b/server/tests/run_suites.sh
@@ -159,6 +159,9 @@ EOF
# the Store's "Suggested for your computer" rules (assets/store/suggestions.json)
if have node; then run "suggest-engine-test (sdk/suggestengine.js)" node tests/suggest_engine_test.mjs
else skip "suggest-engine-test" "node"; fi
+ # the overlay scroll bar's model (sdk/scrollbar.js): geometry, thumb hit-test and drag, fade timing
+ if have node; then run "scrollbar-model-test (sdk/scrollbar.js)" node tests/scrollbar_model_test.mjs
+ else skip "scrollbar-model-test" "node"; fi
}
full() {
diff --git a/server/tests/scrollbar_model_test.mjs b/server/tests/scrollbar_model_test.mjs
new file mode 100644
index 0000000..3454ad8
--- /dev/null
+++ b/server/tests/scrollbar_model_test.mjs
@@ -0,0 +1,80 @@
+// scrollbar_model_test.mjs — the overlay scroll bar's model (sdk/scrollbar.js) that ScrollView
+// (sdk/components.jsx) draws: thumb geometry at the edge, hit-testing and dragging the thumb, when it
+// shows and hides in each Settings → Appearance mode, and the fade timing (none with reduce motion).
+//
+// node tests/scrollbar_model_test.mjs (from server/; run_suites.sh runs it when node exists)
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const here = path.dirname(fileURLToPath(import.meta.url));
+const M = await import(path.join(here, '../../sdk/scrollbar.js'));
+const { SCROLLBAR: S, scrollbarMode, thumbGeometry, offsetForThumb, nearEdge, hitThumb, barShown, barOpacity, hideTime, barWidth } = M;
+
+let n = 0, bad = 0;
+const ok = (name, cond, info = '') => { n++; if (!cond) { bad++; console.log(`✗ ${name} ${info}`); } };
+const near = (a, b, eps = 1e-6) => Math.abs(a - b) <= eps;
+
+// ---- geometry ----
+ok('no bar when it fits', thumbGeometry(300, 300, 0) === null && thumbGeometry(300, 120, 0) === null && thumbGeometry(0, 500, 0) === null);
+let g = thumbGeometry(400, 1600, 0);
+ok('thumb starts at the inset', near(g.top, S.inset), JSON.stringify(g));
+ok('thumb size is the visible share of the track', near(g.size, (400 - 2 * S.inset) / 4), JSON.stringify(g));
+g = thumbGeometry(400, 1600, 1200);
+ok('at the end the thumb touches the bottom inset', near(g.top + g.size, 400 - S.inset), JSON.stringify(g));
+g = thumbGeometry(400, 1600, 99999);
+ok('offset past the end is clamped', near(g.top + g.size, 400 - S.inset));
+g = thumbGeometry(100, 100000, 0);
+ok('minimum thumb', g.size === S.minThumb, String(g.size));
+ok('the thumb is thin and sits 2 px from the edge', S.thin === 6 && S.wide === 10 && S.inset === 2);
+
+// ---- dragging ----
+for (const off of [0, 300, 600, 1200]) {
+ const gg = thumbGeometry(400, 1600, off);
+ ok(`drag round trip ${off}`, near(offsetForThumb(400, 1600, gg.top), off, 1e-6), String(offsetForThumb(400, 1600, gg.top)));
+}
+ok('drag above the track = top', offsetForThumb(400, 1600, -50) === 0);
+ok('drag below the track = end', offsetForThumb(400, 1600, 5000) === 1200);
+ok('drag with nothing to scroll', offsetForThumb(400, 200, 100) === 0);
+
+// ---- hit testing: the end edge (right; left in RTL) ----
+g = thumbGeometry(400, 1600, 0);
+ok('hit thumb LTR', hitThumb(300 - 4, g.top + 5, 300, g, false));
+ok('hit strip LTR is 14 px', hitThumb(300 - S.hit, g.top + 5, 300, g, false) && !hitThumb(300 - S.hit - 1, g.top + 5, 300, g, false));
+ok('miss below the thumb', !hitThumb(296, g.top + g.size + 1, 300, g, false));
+ok('miss on the start edge LTR', !hitThumb(4, g.top + 5, 300, g, false));
+ok('hit thumb RTL (left edge)', hitThumb(4, g.top + 5, 300, g, true) && !hitThumb(296, g.top + 5, 300, g, true));
+ok('no thumb, no hit', !hitThumb(296, 10, 300, null, false));
+ok('near edge LTR', nearEdge(290, 300, false) && !nearEdge(200, 300, false));
+ok('near edge RTL', nearEdge(10, 300, true) && !nearEdge(290, 300, true));
+
+// ---- showing, hiding and the fade ----
+const base = { mode: 'auto', lastScroll: null, near: false, hover: false, dragging: false };
+ok('auto: hidden at rest', !barShown(base, 5000));
+ok('auto: shown near the edge', barShown({ ...base, near: true }, 5000));
+ok('auto: shown while scrolling', barShown({ ...base, lastScroll: 5000 }, 5500));
+ok('auto: still shown just before 1 s', barShown({ ...base, lastScroll: 5000 }, 5000 + S.hideAfter - 1));
+ok('auto: hides 1 s after the last scroll', !barShown({ ...base, lastScroll: 5000 }, 5000 + S.hideAfter));
+ok('scrolling: not shown near the edge', !barShown({ ...base, mode: 'scrolling', near: true }, 5000));
+ok('scrolling: shown while scrolling', barShown({ ...base, mode: 'scrolling', lastScroll: 4900 }, 5000));
+ok('always: shown at rest', barShown({ ...base, mode: 'always' }, 5000));
+ok('dragging keeps it', barShown({ ...base, mode: 'scrolling', dragging: true, lastScroll: 0 }, 99999));
+ok('unknown mode = auto', scrollbarMode('x') === 'auto' && scrollbarMode('always') === 'always');
+
+const s = { ...base, lastScroll: 1000 };
+const hid = 1000 + S.hideAfter;
+ok('hide time', hideTime(s) === hid);
+ok('hide time: none when always / near in auto', hideTime({ ...s, mode: 'always' }) === null && hideTime({ ...s, near: true }) === null);
+ok('hide time: near does not hold it in scrolling', hideTime({ ...s, mode: 'scrolling', near: true }) === hid);
+ok('opacity 1 while shown', barOpacity(s, 1500, null, false) === 1);
+ok('fade starts at 1', near(barOpacity(s, hid, hid, false), 1));
+ok('fade halfway', near(barOpacity(s, hid + S.fade / 2, hid, false), 0.5));
+ok('fade ends', barOpacity(s, hid + S.fade, hid, false) === 0 && barOpacity(s, hid + 5000, hid, false) === 0);
+ok('fade is short (≤ 250 ms)', S.fade > 0 && S.fade <= 250);
+ok('reduce motion: no fade, just hidden', barOpacity(s, hid, hid, true) === 0 && barOpacity(s, hid + 1, hid, true) === 0);
+ok('reduce motion: shown is still 1', barOpacity(s, 1500, null, true) === 1);
+
+// ---- width ----
+ok('thin at rest, wide under the pointer or dragging', barWidth(base) === 6 && barWidth({ ...base, hover: true }) === 10 && barWidth({ ...base, dragging: true }) === 10);
+
+console.log(`scrollbar-model-test: ${n} checks, ${bad} failures`);
+process.exit(bad ? 1 : 0);
diff --git a/themes/README.md b/themes/README.md
index d55b6c0..90cf4d9 100644
--- a/themes/README.md
+++ b/themes/README.md
@@ -65,7 +65,11 @@ Images (`<Image src="assets/...">`) are resolved relative to the theme's folder.
(`[{ id, nameKey, name, src, thumb?, category?, variants? }]`; Settings groups them by `category` and
shows `thumb` in its grid; add `lordosWallpapers` from the SDK to offer the LordOS collection, and
draw with `wallpaperSrc(w, width, height)` so a higher-resolution variant is used where it exists,
-see `assets/wallpapers/README.md`). The theme can add any tokens of its own.
+see `assets/wallpapers/README.md`), and the overlay scroll bars' look (0.8.3, `ScrollView`):
+`scrollThumb`, `scrollThumbHover` (colors), `scrollRadius` (corner radius; a pill by default) and
+`scrollThumbBorder` (a hairline color). `ThemeProvider` adds `scrollBars` and `reduceMotion` from
+the settings, so apps (isolated ones too) follow Settings → Appearance. The theme can add any
+tokens of its own.
## Native components
diff --git a/themes/classic/index.jsx b/themes/classic/index.jsx
index af6044d..15e3ebf 100644
--- a/themes/classic/index.jsx
+++ b/themes/classic/index.jsx
@@ -28,6 +28,9 @@ function makeTheme({ mode, accent }) {
control: dark ? '#2d323d' : '#d7dae1', inputBg: dark ? '#14161c' : '#ffffff',
desktop: dark ? '#0f2537' : '#3a7ca5', bar: dark ? '#14171d' : '#e9ecf1', titleBg: dark ? '#232833' : '#dfe3ea',
gtkButtons: ':minimize,maximize,close', // GTK apps: buttons on the right, like this frame
+ // overlay scroll bars (sdk/components.jsx ScrollView): this theme's squarer, solid thumb with a hairline
+ scrollThumb: dark ? '#4a5160' : '#a9afbb', scrollThumbHover: dark ? '#5d6577' : '#8d94a2',
+ scrollThumbBorder: dark ? '#20242c' : '#eceef2', scrollRadius: 2,
};
}
diff --git a/themes/default/tokens.js b/themes/default/tokens.js
index ed3b23e..67503a9 100644
--- a/themes/default/tokens.js
+++ b/themes/default/tokens.js
@@ -48,6 +48,9 @@ export function makeTheme({ mode, accent, effects }) {
dockBg: dark ? 'rgba(46,46,56,0.42)' : 'rgba(255,255,255,0.38)',
dockBorder: dark ? 'rgba(255,255,255,0.18)' : 'rgba(255,255,255,0.55)',
lightOff: dark ? '#4a4a50' : '#c8c8cc',
+ // overlay scroll bars (sdk/components.jsx ScrollView): a soft pill
+ scrollThumb: dark ? 'rgba(255,255,255,0.32)' : 'rgba(0,0,0,0.3)',
+ scrollThumbHover: dark ? 'rgba(255,255,255,0.5)' : 'rgba(0,0,0,0.45)',
blur: effects ? 24 : 0,
};
}