From d782c9c645c914168d47e4ee7e54047a934782c1 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 22 Oct 2026 06:36:25 +0000 Subject: [PATCH] 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) Claude-Session: https://claude.ai/code/session_01NYASJ6JNxhYwNNJK7ypK2V --- tests/e2e.cjs | 24 ++++++++++ web/app.py | 126 ++++++++++++++++++++++++++++++++++++++++++++----- web/app.wasm | Bin 14057 -> 16176 bytes web/index.html | 78 ++++++++++++++++++++++-------- 4 files changed, 198 insertions(+), 30 deletions(-) diff --git a/tests/e2e.cjs b/tests/e2e.cjs index fe6d257..08022f7 100644 --- a/tests/e2e.cjs +++ b/tests/e2e.cjs @@ -73,6 +73,30 @@ const BASE = process.env.BASE || "http://localhost:8000"; await longpress(".slots .tile:nth-child(1)"); await p.click(".sheet-item >> text=Move later"); await settle(); assert.deepEqual(await homeApps(), ["Gmail", "Chrome", "Phone"]); + // the grid runs down the screen; an app dropped in an empty cell there stays in it, + // and the rest stay packed + const rows = await p.$eval(".slots", (s) => getComputedStyle(s).gridTemplateRows.split(" ").length); + assert.ok(rows >= 5, `rows fill the screen: ${rows}`); + const tileAt = (n) => p.locator(`.slots .tile:has-text("${n}")`).boundingBox(); + const g0 = await tileAt("Gmail"), c0 = await tileAt("Chrome"), pitch = 64 + 8; + await p.mouse.move(g0.x + g0.width / 2, g0.y + g0.height / 2); + await p.mouse.down(); await p.waitForTimeout(650); await settle(); + await p.mouse.move(g0.x + g0.width / 2 + 10, g0.y + g0.height / 2 + 4 * pitch, { steps: 6 }); await settle(); + await p.mouse.up(); await settle(); + const g1 = await tileAt("Gmail"), c1 = await tileAt("Chrome"); + assert.ok(Math.abs(g1.y - g0.y - 4 * pitch) < 3, `left four rows down: ${g1.y - g0.y}`); + assert.equal(Math.round(c1.x), Math.round(g0.x), "Chrome moves up into the packed first cell"); + await p.reload(); await p.waitForSelector(".slots .tile"); + assert.ok(Math.abs((await tileAt("Gmail")).y - g1.y) < 3, "its cell is saved"); + // dragging it back over an app puts it back in the packed order + const c2 = await tileAt("Chrome"); + await p.mouse.move(g1.x + g1.width / 2, g1.y + g1.height / 2); + await p.mouse.down(); await p.waitForTimeout(650); await settle(); + await p.mouse.move(c2.x + c2.width / 2, c2.y + c2.height / 2, { steps: 6 }); await settle(); + await p.mouse.up(); await settle(); + assert.deepEqual(await homeApps(), ["Gmail", "Chrome", "Phone"]); + assert.ok(Math.abs((await tileAt("Gmail")).y - c0.y) < 3, "back in the first row"); + await p.mouse.click(5, 300); await settle(); // a tap on empty home ends the drag gesture // swipe down opens the drawer (and takes the widget off screen), search, long press adds const swipe = (y0, y1) => p.evaluate(([y0, y1]) => { const at = (y) => new Touch({ identifier: 1, target: document.body, clientX: 200, clientY: y }); diff --git a/web/app.py b/web/app.py index 34da9d8..3ca58f2 100644 --- a/web/app.py +++ b/web/app.py @@ -9,12 +9,14 @@ from ui import btn_open, input_open, alert # An Android home screen. The home starts blank: you add apps and widgets to it # with a long press. Swiping down opens the drawer with every app and a search. -# A long press on a home app or widget picks it up: drag it to move it, or let go -# without moving to get its menu (index.html does the dragging). Letting go of a -# widget that way shows resize handles on its right and bottom edges instead: +# The home grid packs apps and widgets in order with no holes, and runs on to the +# bottom of the screen. A long press on a home app or widget picks it up: drag it +# over another to move it there in the order, or into an empty cell below to +# leave it in that cell; or let go without moving to get its menu (index.html +# does the dragging). Letting go of a widget that way shows resize handles on its right and bottom edges instead: # dragging them snaps the widget to whole grid columns and rows of app tiles, # within the sizes it allows, and dragging the widget itself moves it, staying -# in that mode once let go. Apps flow into the free cells beside widgets. +# in that mode once let go. # # The native shell (android/) serves this folder in a WebView, answers # apps.json and widgets.json, hosts the widgets as native views over the @@ -103,6 +105,8 @@ RESIZE_DONE: Const[i32] = 41 GRAB: Const[i32] = 42 # arg: the widget slot showing handles, picked up by its body CHECK_UPDATES: Const[i32] = 43 WIDGET_COLS: Const[i32] = 44 # arg: columns for the widget just added (0: the whole row) +GRID: Const[i32] = 45 # arg: columns * 4096 + rows that fit on the screen +MOVE_CELL: Const[i32] = 47 # arg: row * 64 + column of the empty cell the lifted slot is over CAP: Const[i32] = 512 HOME_CAP: Const[i32] = 200 @@ -136,7 +140,13 @@ hwid: i32[512] = empty(512, dtype=int32) hh: i32[512] = empty(512, dtype=int32) hw: i32[512] = empty(512, dtype=int32) hkey: i32[512] = empty(512, dtype=int32) +# The grid cell a slot was dropped into (column hx, row hy, from 0), or -1: placed +# in order by the grid's dense flow into the first free cells that fit it. +hx: i32[512] = empty(512, dtype=int32) +hy: i32[512] = empty(512, dtype=int32) nh: i32 = 0 +ncols: i32 = 5 # grid columns, and rows that fill the screen (index.html measures them) +nrows: i32 = 0 next_key: i32 = 1 # Widget providers, for the picker. wlabels: i32[512] = empty(512, dtype=int32) @@ -185,6 +195,8 @@ def init() -> None: hwid[nh] = load_i32_at("ultra.home.wid", i, 0) hh[nh] = load_i32_at("ultra.home.h", i, 120) hw[nh] = load_i32_at("ultra.home.w", i, 0) + hx[nh] = load_i32_at("ultra.home.cx", i, -1) + hy[nh] = load_i32_at("ultra.home.cy", i, -1) hkey[nh] = next_key next_key += 1 nh += 1 @@ -202,6 +214,8 @@ def save_home() -> None: store_i32_at("ultra.home.wid", i, hwid[i]) store_i32_at("ultra.home.h", i, hh[i]) store_i32_at("ultra.home.w", i, hw[i]) + store_i32_at("ultra.home.cx", i, hx[i]) + store_i32_at("ultra.home.cy", i, hy[i]) def say(msg: str) -> None: @@ -342,6 +356,8 @@ def push_slot(kind: i32, s: i32, wid: i32, h: i32) -> None: hwid[nh] = wid hh[nh] = h hw[nh] = 0 + hx[nh] = -1 + hy[nh] = -1 hkey[nh] = next_key next_key += 1 nh += 1 @@ -370,6 +386,8 @@ def remove_slot(at: i32) -> None: hwid[j] = hwid[j + 1] hh[j] = hh[j + 1] hw[j] = hw[j + 1] + hx[j] = hx[j + 1] + hy[j] = hy[j + 1] hkey[j] = hkey[j + 1] nh -= 1 save_home() @@ -392,6 +410,12 @@ def swap_slots(a: i32, b: i32) -> None: t = hw[a] hw[a] = hw[b] hw[b] = t + t = hx[a] + hx[a] = hx[b] + hx[b] = t + t = hy[a] + hy[a] = hy[b] + hy[b] = t t = hkey[a] hkey[a] = hkey[b] hkey[b] = t @@ -409,6 +433,50 @@ def move_slot(a: i32, b: i32) -> None: i -= 1 +def slot_w(i: i32) -> i32: + """Columns slot i spans.""" + if hkind[i] == APP: + return 1 + if hw[i] <= 0 or hw[i] > ncols: + return ncols + return hw[i] + + +def slot_h(i: i32) -> i32: + """Rows slot i spans.""" + if hkind[i] == APP: + return 1 + return widget_rows(hh[i]) + + +def clear_cells(i: i32) -> None: + """Unpin the slots under pinned slot i, so they flow into free cells.""" + j: i32 + for j in range(nh): + if j != i and hx[j] >= 0 and hx[j] < hx[i] + slot_w(i) and hx[i] < hx[j] + slot_w(j) \ + and hy[j] < hy[i] + slot_h(i) and hy[i] < hy[j] + slot_h(j): + hx[j] = -1 + hy[j] = -1 + + +def pin_slot(i: i32, col: i32, row: i32) -> None: + """Pin slot i with its top left at col, row (kept on the screen's grid). It may + cover others while it is carried; clear_cells moves them off once it is put down.""" + x: i32 = col + y: i32 = row + if x + slot_w(i) > ncols: + x = ncols - slot_w(i) + if nrows > 0 and y + slot_h(i) > nrows: + y = nrows - slot_h(i) + if x < 0: + x = 0 + if y < 0: + y = 0 + hx[i] = x + hy[i] = y + save_home() + + def slot_of_widget(wid: i32) -> i32: i: i32 for i in range(nh): @@ -430,7 +498,7 @@ def close_all() -> None: # ---- Update def update(msg: i32, arg: i32) -> None: - global loading, drawer, picking, sheet, item, pending, wloading, chosen, lifted, resizing, regrab + global loading, drawer, picking, sheet, item, pending, wloading, chosen, lifted, resizing, regrab, ncols, nrows i: i32 if msg == LOADED: load_apps(arg) @@ -495,9 +563,20 @@ def update(msg: i32, arg: i32) -> None: lifted = arg elif msg == DRAG_TO: if lifted >= 0 and arg >= 0 and arg < nh and arg != lifted: + hx[lifted] = -1 # back into the flow, at that place in the order + hy[lifted] = -1 move_slot(lifted, arg) lifted = arg + elif msg == MOVE_CELL: + if lifted >= 0 and (hx[lifted] != arg % 64 or hy[lifted] != arg // 64): + pin_slot(lifted, arg % 64, arg // 64) + elif msg == GRID: + ncols = arg // 4096 + nrows = arg % 4096 elif msg == DROP: + if lifted >= 0 and hx[lifted] >= 0: + clear_cells(lifted) + save_home() if lifted >= 0 and (arg == 0 or regrab == 1): if hkind[lifted] == WIDGET: resizing = lifted @@ -510,6 +589,9 @@ def update(msg: i32, arg: i32) -> None: if resizing >= 0: hw[resizing] = arg // 4096 hh[resizing] = arg % 4096 + if hx[resizing] >= 0: + pin_slot(resizing, hx[resizing], hy[resizing]) + clear_cells(resizing) save_home() elif msg == RESIZE_DONE: resizing = -1 @@ -635,6 +717,24 @@ def widget_rows(h: i32) -> i32: return k +def view_cell(i: i32) -> None: + """Slot i's place on the grid: its pinned cell if it fits, and its span.""" + s_clear(scratch) + if hx[i] >= 0 and hx[i] + slot_w(i) <= ncols: + s_add(scratch, "grid-column:") + s_add_num(scratch, hx[i] + 1) + s_add(scratch, ";grid-row:") + s_add_num(scratch, hy[i] + 1) + s_add(scratch, "/") + else: + s_add(scratch, "grid-row:") + s_add(scratch, "span ") + s_add_num(scratch, slot_h(i)) + s_add(scratch, ";grid-column-end:span ") + s_add_num(scratch, slot_w(i)) + attr_ref("style", scratch) + + def view_home_slot(i: i32) -> None: row: i32 if hkind[i] == WIDGET: @@ -645,12 +745,7 @@ def view_home_slot(i: i32) -> None: cls_if("resizing", i == resizing) attr_num("data-slot", i) # Its height spans whole rows of app tiles (64px rows, 8px gaps; style.css). - s_set(scratch, "grid-row:span ") - s_add_num(scratch, widget_rows(hh[i])) - if hw[i] > 0: - s_add(scratch, ";grid-column:span ") - s_add_num(scratch, hw[i]) - attr_ref("style", scratch) + view_cell(i) # The native widget view is laid over slots marked live, so only mark # them while nothing covers the home screen. While one is resized the # others step aside, so nothing native covers its handles. @@ -675,6 +770,8 @@ def view_home_slot(i: i32) -> None: cls("tile") cls_if("lifted", i == lifted) attr_num("data-slot", i) + if hx[i] >= 0: + view_cell(i) on_click(OPEN_HOME, i) on_longpress(LIFT, i) view_icon(icons[row]) @@ -715,6 +812,13 @@ def view_home() -> None: el("ul") cls("slots") cls_if("dragging", lifted >= 0) + if nrows > 0 and nh > 0: + # Rows down to the bottom of the screen, so empty cells there take apps too + # (4rem: the row height in style.css). + s_set(scratch, "grid-template-rows:repeat(") + s_add_num(scratch, nrows) + s_add(scratch, ",4rem)") + attr_ref("style", scratch) for i in range(nh): view_home_slot(i) end() diff --git a/web/app.wasm b/web/app.wasm index 367832906f593a78a686d5f2d42bde84af152685..9e2264d2ee3c446e8fbdf35eeae489e4d6f93bf3 100644 GIT binary patch literal 16176 zcmeHOU5r%Kmfoj+x~n+_bwET^)Ki`UQD~4qMMUKYLfi5W^5;)cbf507rn;-FsusDq z_tIBeZ56%f1JeUcYA-POKGR(wD$b<)S!vhaIFgHAq2@jo#lkh+?^L=Zd zbE;02+#&aQ(AvG%&t7})wbovH?^U~0p*CVDrHucM|L6F)I%phI2NTEe&p0M^!b<*c z)BqERgG(KZMGF!H<+Gy>Nnxp5hG0lC$VGvEx0=I8DC3v+?FNiZ9SS6}v;coJBDB$g z@~h2**OMWC^QSS4V7i*Gp%LlKR|v5X%}+C03j|U|rv-?Lbzc!}O1nlOEu?64L2*9h zSJ^LR1^wz#|M?OPgdz4n$v?pEbB+{h#e8kFP^k@->-kF6`>^O8S=LplmizMFN5#6j zA4_VWKYyfJtb59c4cDd>`T-XE2fezA0ZtVvm3(n@pseD6ruPkbeTVa7mHtBAtEmJ~ z9Ycj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!`Om@ Giu2!VXP|Qc diff --git a/web/index.html b/web/index.html index dfc91d7..b04ba64 100644 --- a/web/index.html +++ b/web/index.html @@ -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).