Compare commits

...
Author SHA1 Message Date
jaredandClaude Opus 5.5 18a6b0d7ff feat: v0.12.1 touch-screen scrolling (#64)
build-deb / Deploy to CT 126 (push) Successful in 37s
build-deb / Lint, test, package (push) Successful in 6m7s
build-deb / Notify on failure (push) Skipped
- Terminal: a one-finger vertical swipe becomes wheel reports at the touch
  point, so tmux scrolls its history like the mouse wheel; a flick keeps
  going and eases out. Taps still focus and reach tmux's status bar; swipes
  never land on the status line. Without mouse tracking it scrolls xterm's
  own buffer. touch-action: none on the terminal.
- Resize handles: touch-action: none and wider grab areas on touch screens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rk7Hm4Ti8HuDkb7CTQhWhH
2026-11-26 12:53:02 -05:00
3 changed files with 127 additions and 1 deletions

No files matched your search

+10
View File
@@ -1,3 +1,13 @@
devdesk (0.12.1) bookworm; urgency=medium
* Touch screens (#64):
- A swipe on the terminal scrolls tmux's history like the mouse wheel;
a flick keeps going. Taps still focus and switch windows.
- Resize handles can be dragged with a finger and are wider on
touch screens.
-- Jared Vititoe <jjvititoe1@gmail.com> Thu, 26 Nov 2026 12:55:00 -0500
devdesk (0.12.0) bookworm; urgency=medium
* Settings window, from the ⋯ menu or the palette (#61):
+109
View File
@@ -90,6 +90,113 @@ export async function loadFonts(size) {
}
}
// Touch scrolling (devdesk#64). xterm.js has none, and tmux owns the mouse, so
// a finger swipe did nothing. A one-finger vertical swipe now scrolls the way
// the mouse wheel does: with mouse tracking on (tmux) it becomes wheel reports
// at the touch point, and tmux scrolls WHEEL_LINES lines per report (entering
// copy mode, leaving it at the bottom); without it, xterm's own buffer scrolls.
// The content follows the finger, and a flick keeps going and slows down.
const WHEEL_LINES = 5; // tmux copy mode: send -N5 -X scroll-up per wheel report
const SLOP = 8; // px before a touch counts as a scroll rather than a tap
function wireTouchScroll(term, container) {
let touch = null;
let carry = 0; // finger travel not yet turned into lines
let fling = 0;
const screen = () => container.querySelector('.xterm-screen');
// Scroll by finger travel px (positive = finger down = back into history).
const scrollBy = (px, at) => {
const rect = screen()?.getBoundingClientRect();
if (!rect || !term.rows) return false;
const cell = rect.height / term.rows;
const mouse = term.modes.mouseTrackingMode !== 'none';
const per = mouse ? cell * WHEEL_LINES : cell;
carry += px;
const steps = Math.trunc(carry / per);
if (!steps) return true;
carry -= steps * per;
if (!mouse) {
term.scrollLines(-steps);
return true;
}
// Inside the pane the swipe started on, and never on tmux's status line
// (a wheel there switches windows).
const clientX = Math.min(Math.max(at.x, rect.left + 1), rect.right - 1);
const clientY = Math.min(Math.max(at.y, rect.top + cell / 2), rect.bottom - cell * 1.5);
for (let i = 0; i < Math.abs(steps); i++) {
screen().dispatchEvent(new WheelEvent('wheel', {
bubbles: true, cancelable: true, view: window, clientX, clientY,
deltaMode: WheelEvent.DOM_DELTA_LINE, deltaY: steps > 0 ? -1 : 1,
}));
}
return true;
};
const stopFling = () => {
cancelAnimationFrame(fling);
fling = 0;
};
container.addEventListener('touchstart', (event) => {
stopFling();
if (event.touches.length !== 1) {
touch = null;
return;
}
const t = event.touches[0];
touch = { id: t.identifier, start: { x: t.clientX, y: t.clientY }, y: t.clientY, scrolling: false, samples: [[event.timeStamp, t.clientY]] };
carry = 0;
}, { passive: true });
container.addEventListener('touchmove', (event) => {
if (!touch) return;
if (event.touches.length !== 1) {
touch = null;
return;
}
const t = [...event.changedTouches].find((c) => c.identifier === touch.id);
if (!t) return;
if (!touch.scrolling) {
const dx = t.clientX - touch.start.x;
const dy = t.clientY - touch.start.y;
if (Math.abs(dy) < SLOP || Math.abs(dy) < Math.abs(dx)) return;
touch.scrolling = true;
touch.y = t.clientY;
}
if (event.cancelable) event.preventDefault();
scrollBy(t.clientY - touch.y, touch.start);
touch.y = t.clientY;
touch.samples.push([event.timeStamp, t.clientY]);
while (touch.samples.length > 2 && event.timeStamp - touch.samples[0][0] > 100) touch.samples.shift();
}, { passive: false });
const end = (event) => {
const done = touch;
touch = null;
if (!done?.scrolling) return;
if (event.cancelable) event.preventDefault(); // no click after a swipe
if (event.type !== 'touchend') return;
// Flick: keep scrolling at the release speed, easing out.
const [t0, y0] = done.samples[0];
const [t1, y1] = done.samples[done.samples.length - 1];
let speed = t1 > t0 && event.timeStamp - t1 < 80 ? (y1 - y0) / (t1 - t0) : 0; // px/ms
if (Math.abs(speed) < 0.3) return;
let last = performance.now();
const frame = (now) => {
const dt = Math.min(now - last, 50);
last = now;
if (!scrollBy(speed * dt, done.start)) return stopFling();
speed *= 0.95 ** (dt / 16);
fling = Math.abs(speed) > 0.05 ? requestAnimationFrame(frame) : 0;
return undefined;
};
fling = requestAnimationFrame(frame);
};
container.addEventListener('touchend', end, { passive: false });
container.addEventListener('touchcancel', end, { passive: false });
}
export function createTerminal(container, { fontSize, theme = 'dark', onShiftEnter, onCopied }) {
const term = new Terminal({
fontFamily: FONT_FAMILY,
@@ -176,6 +283,8 @@ export function createTerminal(container, { fontSize, theme = 'dark', onShiftEnt
}, 0);
});
wireTouchScroll(term, container);
// Touch devices: the DOM renderer is more reliable at high DPR than WebGL.
if (window.matchMedia?.('(pointer: coarse)').matches) return { term, fit };
try {
+8 -1
View File
@@ -186,6 +186,7 @@ body.dd-app::after {
.dd-terminal .xterm {
height: 100%;
touch-action: none; /* swipes scroll tmux (term.js wireTouchScroll), not the page */
}
.dd-terminal .xterm-viewport {
@@ -749,6 +750,7 @@ body.dd-resizing .dd-md-frame { pointer-events: none; }
left: calc(-1 * var(--dd-gap) - 2px);
width: calc(var(--dd-gap) + 6px);
cursor: col-resize;
touch-action: none; /* a finger drag resizes instead of scrolling */
z-index: 3;
}
.dd-files-resizer:hover,
@@ -796,7 +798,12 @@ body.dd-resizing .dd-files-resizer { background: linear-gradient(90deg, transpar
.dd-files.explorer-hidden .dd-explorer,
.dd-files.explorer-hidden .dd-explorer-resizer,
.dd-files.is-narrow .dd-explorer-resizer { display: none; }
.dd-explorer-resizer { flex: 0 0 4px; margin-left: -2px; margin-right: -2px; cursor: col-resize; z-index: 2; }
.dd-explorer-resizer { flex: 0 0 4px; margin-left: -2px; margin-right: -2px; cursor: col-resize; touch-action: none; z-index: 2; }
/* Touch screens (devdesk#64): wider grab areas for a finger. */
@media (any-pointer: coarse) {
.dd-explorer-resizer { flex-basis: 14px; margin-left: -7px; margin-right: -7px; }
.dd-files-resizer { left: calc(-1 * var(--dd-gap) - 6px); width: calc(var(--dd-gap) + 14px); }
}
.dd-explorer-resizer:hover { background: var(--accent-cyan); }
.dd-explorer-views { display: flex; border-bottom: 1px solid var(--border-dim); }
.dd-explorer-views button[role="tab"] {