Let apps be dropped into empty rows below, keeping the rest packed

The page measures how many rows fit down to the bottom of the screen (GRID)
and app.py lays out that many, so the space below the apps is real cells.
Apps and widgets still pack in order with no holes; dragging one over another
moves it in the order as before. Dragging it over an empty cell (MOVE_CELL)
leaves it pinned there (saved as ultra.home.cx/cy, new keys so build 21's
pins are ignored); dropping it moves anything pinned underneath back into the
flow, and dragging it back over an app returns it to the order.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NYASJ6JNxhYwNNJK7ypK2V
This commit is contained in:
Claude committed 2026-10-22 06:36:25 +00:00
1 parent b031cff81e
commit d782c9c645
4 files changed
+198 -30

No files matched your search

+59 -19
View File
@@ -116,8 +116,9 @@
};
window.ultraIcons = gotIcons; // the shell calls this before ultraHome exists, too
let ready = false; // the grid code below exists and app is mounted
const app = await mount("#app", "./app.wasm", {
onRender: () => { fillIcons(); place(); watchDrawer(); },
onRender: () => { fillIcons(); place(); watchDrawer(); if (ready) measureGrid(); },
imports: ({ strs }) => ({
launch: (h) => host.launch(strs[h]),
app_info: (h) => host.appInfo(strs[h]),
@@ -131,34 +132,72 @@
}),
});
ready = true;
// Messages the shell and the gestures below send (keep in sync with app.py).
const RELOAD = 2, HOME = 3, BACK = 4, SWIPE_DOWN = 5, SWIPE_UP = 6,
WIDGET_ADDED = 7, WIDGET_MENU = 8, DRAG_TO = 35, DROP = 36, RESIZE = 40, GRAB = 42, WIDGET_COLS = 44;
WIDGET_ADDED = 7, WIDGET_MENU = 8, DRAG_TO = 35, DROP = 36, RESIZE = 40, GRAB = 42, WIDGET_COLS = 44,
GRID = 45, MOVE_CELL = 47;
// Dragging a home slot. A long press lifts it (app.py marks it .lifted); moving the
// finger then slides it to the slot under the finger, and letting go drops it there.
// The home grid: its columns, and as many rows as fit down to the bottom of the
// screen (app.py lays those out, so the empty cells there are real cells).
const grid = () => {
const slots = document.querySelector(".slots");
if (!slots) return null;
const cs = getComputedStyle(slots), r = slots.getBoundingClientRect();
const colW = parseFloat(cs.gridTemplateColumns), gap = parseFloat(cs.columnGap) || 0;
return { left: r.left, top: r.top, cols: cs.gridTemplateColumns.split(" ").length,
colW, gap, cell: parseFloat(cs.gridAutoRows) || 64, rgap: parseFloat(cs.rowGap) || 0,
rows: cs.gridTemplateRows.split(" ").length };
};
let gridSent = -1;
const measureGrid = () => {
const g = grid(), home = document.querySelector(".home");
if (!g || !home) return;
const bottom = innerHeight - parseFloat(getComputedStyle(home).paddingBottom); // of the first screen
const rows = Math.max(1, Math.floor((bottom - (g.top + scrollY) + g.rgap) / (g.cell + g.rgap)));
const v = g.cols * 4096 + rows;
if (v !== gridSent) { gridSent = v; app.dispatch(GRID, v); }
};
const cellAt = (g, x, y) => [Math.max(0, Math.round((x - g.left) / (g.colW + g.gap))),
Math.max(0, Math.round((y - g.top) / (g.cell + g.rgap)))];
// Dragging a home slot. A long press lifts it (app.py marks it .lifted). Moving the
// finger over another slot moves it there in the order (the grid stays packed);
// over an empty cell it is left in that cell (top left by where it was held), and
// letting go drops it; whatever it then covers moves on to free cells.
// Letting go without moving opens its menu instead. A widget showing resize handles
// needs no long press: pressing its body picks it up right away (GRAB), and it keeps
// its handles when let go. Native widget views take their own touches, so the shell
// reports those through widgetGrab/widgetDrag/widgetDrop.
let drag = null, dragged = false; // drag: { x, y, moved } from pointerdown
let carry = null; // { dx, dy, cell }: where the lifted slot was held, the cell sent last
const inside = (r, x, y) => x >= r.left && x <= r.right && y >= r.top && y <= r.bottom;
const slotAt = (x, y) => {
let best = -1, bestD = Infinity;
for (const li of document.querySelectorAll(".slots > li[data-slot]")) {
const r = li.getBoundingClientRect();
const dx = Math.max(r.left - x, 0, x - r.right), dy = Math.max(r.top - y, 0, y - r.bottom);
const d = dx * dx + dy * dy;
if (d < bestD) { bestD = d; best = +li.dataset.slot; }
}
return best;
for (const li of document.querySelectorAll(".slots > li[data-slot]:not(.lifted)"))
if (inside(li.getBoundingClientRect(), x, y)) return +li.dataset.slot;
return -1;
};
const dragTo = (x, y) => {
const lifted = document.querySelector(".slots > .lifted");
if (!lifted) return;
const to = slotAt(x, y);
if (to >= 0 && to !== +lifted.dataset.slot) app.dispatch(DRAG_TO, to);
const dragTo = (x, y, x0 = x, y0 = y) => { // x0, y0: where the finger went down
const lifted = document.querySelector(".slots > .lifted"), g = grid();
if (!lifted || !g) return;
if (!carry) {
const r = lifted.getBoundingClientRect();
carry = { dx: x0 - r.left, dy: y0 - r.top, cell: -1 };
}
if (inside(lifted.getBoundingClientRect(), x, y)) return;
// the cell under the finger: a slot there takes the lifted one's place in the order
const [fc, fr] = cellAt(g, x - g.colW / 2, y - g.cell / 2);
const to = slotAt(x, y) >= 0 ? slotAt(x, y)
: slotAt(g.left + fc * (g.colW + g.gap) + g.colW / 2, g.top + fr * (g.cell + g.rgap) + g.cell / 2);
if (to >= 0) { carry.cell = -1; app.dispatch(DRAG_TO, to); return; }
if (y > g.top + g.rows * (g.cell + g.rgap)) return; // below the grid
const [col, row] = cellAt(g, x - carry.dx, y - carry.dy);
const cell = row * 64 + Math.min(col, 63);
if (cell !== carry.cell) { carry.cell = cell; app.dispatch(MOVE_CELL, cell); }
};
const drop = (moved) => {
carry = null;
if (document.querySelector(".slots > .lifted")) app.dispatch(DROP, moved ? 1 : 0);
};
let grabbed = false;
@@ -175,7 +214,7 @@
if (!drag || !document.querySelector(".slots > .lifted")) return;
if (!drag.moved && Math.hypot(e.clientX - drag.x, e.clientY - drag.y) < 10) return;
drag.moved = dragged = true;
dragTo(e.clientX, e.clientY);
dragTo(e.clientX, e.clientY, drag.x, drag.y);
});
addEventListener("pointerup", () => { if (drag) drop(drag.moved); drag = null; });
addEventListener("pointercancel", () => { if (drag) drop(drag.moved); drag = null; });
@@ -266,7 +305,8 @@
for (const img of document.querySelectorAll("img.icon")) img.__icon = undefined; },
};
addEventListener("scroll", () => requestAnimationFrame(place), { passive: true });
addEventListener("resize", () => requestAnimationFrame(place));
addEventListener("resize", () => requestAnimationFrame(() => { place(); measureGrid(); }));
measureGrid();
// Swipe down on the home screen opens the drawer; swipe up closes it once its
// list is scrolled to the end (or doesn't scroll).