Press and hold a home app or widget to drag it to a new spot
A long press now lifts the slot instead of opening its menu. Moving the finger slides it live to the slot under the finger and letting go drops it there; letting go without moving opens the menu as before. index.html does the dragging (and stops the page scrolling or swiping the drawer under a lifted slot). Native widget views take their own touches, so WidgetView forwards the moves after its long press as widgetDrag(x, y) and the release as widgetDrop(moved). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JfvcrzLMTeE68CpNffNDvE
This commit is contained in:
6 files changed
+167
-20
No files matched your search
+45
-13
@@ -9,6 +9,8 @@ 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).
|
||||
#
|
||||
# The native shell (android/) serves this folder in a WebView, answers
|
||||
# apps.json and widgets.json, hosts the widgets as native views over the
|
||||
@@ -68,7 +70,7 @@ BACK: Const[i32] = 4
|
||||
SWIPE_DOWN: Const[i32] = 5
|
||||
SWIPE_UP: Const[i32] = 6
|
||||
WIDGET_ADDED: Const[i32] = 7
|
||||
WIDGET_MENU: Const[i32] = 8
|
||||
WIDGET_MENU: Const[i32] = 8 # arg: widget id; a long press on a native widget lifts it
|
||||
LOADED: Const[i32] = 10
|
||||
WIDGETS_LOADED: Const[i32] = 11
|
||||
QUERY: Const[i32] = 12
|
||||
@@ -81,7 +83,6 @@ OPEN_HOME: Const[i32] = 18 # arg: home slot
|
||||
ADD_HOME: Const[i32] = 19 # arg: row in the app list (long press in the drawer)
|
||||
TOGGLE_HOME: Const[i32] = 20 # arg: row in the app list (drawer in pick mode)
|
||||
MENU: Const[i32] = 21 # long press on the empty home
|
||||
ITEM_MENU: Const[i32] = 22 # arg: home slot
|
||||
CLOSE_SHEET: Const[i32] = 23
|
||||
PICK_APPS: Const[i32] = 24
|
||||
PICK_WIDGET: Const[i32] = 25
|
||||
@@ -93,6 +94,9 @@ SETTINGS: Const[i32] = 30
|
||||
WALLPAPER: Const[i32] = 31
|
||||
NOTICE_DONE: Const[i32] = 32
|
||||
RECENTS: Const[i32] = 33
|
||||
LIFT: Const[i32] = 34 # arg: home slot (long press picks it up)
|
||||
DRAG_TO: Const[i32] = 35 # arg: home slot the lifted one is dragged over
|
||||
DROP: Const[i32] = 36 # arg: 1 if it was dragged, 0 if just held (opens its menu)
|
||||
|
||||
CAP: Const[i32] = 512
|
||||
HOME_CAP: Const[i32] = 40
|
||||
@@ -147,6 +151,7 @@ drawer: i32 = 0
|
||||
picking: i32 = 0 # drawer is in "add apps" mode: taps toggle home slots
|
||||
sheet: i32 = 0
|
||||
item: i32 = -1 # home slot the item sheet is about
|
||||
lifted: i32 = -1 # home slot picked up by a long press, being dragged
|
||||
pending: i32 = 0 # JSON handle of a request in flight
|
||||
|
||||
|
||||
@@ -365,6 +370,17 @@ def swap_slots(a: i32, b: i32) -> None:
|
||||
save_home()
|
||||
|
||||
|
||||
def move_slot(a: i32, b: i32) -> None:
|
||||
"""Take slot a out and put it back at b, shifting the slots between."""
|
||||
i: i32 = a
|
||||
while i < b:
|
||||
swap_slots(i, i + 1)
|
||||
i += 1
|
||||
while i > b:
|
||||
swap_slots(i, i - 1)
|
||||
i -= 1
|
||||
|
||||
|
||||
def slot_of_widget(wid: i32) -> i32:
|
||||
i: i32
|
||||
for i in range(nh):
|
||||
@@ -374,16 +390,17 @@ def slot_of_widget(wid: i32) -> i32:
|
||||
|
||||
|
||||
def close_all() -> None:
|
||||
global drawer, picking, sheet, item
|
||||
global drawer, picking, sheet, item, lifted
|
||||
s_clear(query)
|
||||
drawer = 0
|
||||
picking = 0
|
||||
sheet = NONE
|
||||
item = -1
|
||||
lifted = -1
|
||||
|
||||
# ---- Update
|
||||
def update(msg: i32, arg: i32) -> None:
|
||||
global loading, drawer, picking, sheet, item, pending, wloading, chosen
|
||||
global loading, drawer, picking, sheet, item, pending, wloading, chosen, lifted
|
||||
i: i32
|
||||
if msg == LOADED:
|
||||
load_apps(arg)
|
||||
@@ -423,15 +440,23 @@ def update(msg: i32, arg: i32) -> None:
|
||||
elif msg == MENU:
|
||||
haptic()
|
||||
sheet = SHEET_MENU
|
||||
elif msg == ITEM_MENU:
|
||||
haptic()
|
||||
item = arg
|
||||
sheet = SHEET_ITEM
|
||||
elif msg == LIFT:
|
||||
if drawer == 0 and sheet == NONE:
|
||||
haptic()
|
||||
lifted = arg
|
||||
elif msg == WIDGET_MENU:
|
||||
i = slot_of_widget(arg)
|
||||
if i >= 0 and drawer == 0:
|
||||
item = i
|
||||
if i >= 0 and drawer == 0 and sheet == NONE:
|
||||
lifted = i
|
||||
elif msg == DRAG_TO:
|
||||
if lifted >= 0 and arg >= 0 and arg < nh and arg != lifted:
|
||||
move_slot(lifted, arg)
|
||||
lifted = arg
|
||||
elif msg == DROP:
|
||||
if lifted >= 0 and arg == 0:
|
||||
item = lifted
|
||||
sheet = SHEET_ITEM
|
||||
lifted = -1
|
||||
elif msg == CLOSE_SHEET:
|
||||
sheet = NONE
|
||||
item = -1
|
||||
@@ -487,7 +512,9 @@ def update(msg: i32, arg: i32) -> None:
|
||||
elif msg == HOME:
|
||||
close_all()
|
||||
elif msg == BACK:
|
||||
if sheet != NONE:
|
||||
if lifted >= 0:
|
||||
lifted = -1
|
||||
elif sheet != NONE:
|
||||
sheet = NONE
|
||||
item = -1
|
||||
elif drawer == 1:
|
||||
@@ -511,6 +538,8 @@ def view_home_slot(i: i32) -> None:
|
||||
el("li")
|
||||
key(hkey[i])
|
||||
cls("widget-slot")
|
||||
cls_if("lifted", i == lifted)
|
||||
attr_num("data-slot", i)
|
||||
s_set(scratch, "height:")
|
||||
s_add_num(scratch, hh[i])
|
||||
s_add(scratch, "px")
|
||||
@@ -519,7 +548,7 @@ def view_home_slot(i: i32) -> None:
|
||||
# them while nothing covers the home screen.
|
||||
if drawer == 0 and sheet == NONE:
|
||||
attr_num("data-wid", hwid[i])
|
||||
on_longpress(ITEM_MENU, i)
|
||||
on_longpress(LIFT, i)
|
||||
el("span")
|
||||
cls("widget-label")
|
||||
text_ref(hstr[i])
|
||||
@@ -532,8 +561,10 @@ def view_home_slot(i: i32) -> None:
|
||||
el("li")
|
||||
key(hkey[i])
|
||||
cls("tile")
|
||||
cls_if("lifted", i == lifted)
|
||||
attr_num("data-slot", i)
|
||||
on_click(OPEN_HOME, i)
|
||||
on_longpress(ITEM_MENU, i)
|
||||
on_longpress(LIFT, i)
|
||||
view_icon(icons[row])
|
||||
el("span")
|
||||
cls("name")
|
||||
@@ -585,6 +616,7 @@ def view_home() -> None:
|
||||
|
||||
el("ul")
|
||||
cls("slots")
|
||||
cls_if("dragging", lifted >= 0)
|
||||
for i in range(nh):
|
||||
view_home_slot(i)
|
||||
end()
|
||||
|
||||
Binary file not shown.
+45
-2
@@ -113,7 +113,48 @@
|
||||
|
||||
// Messages the shell and the gestures below send (keep in sync with app.py).
|
||||
const TICK = 1, RELOAD = 2, HOME = 3, BACK = 4, SWIPE_DOWN = 5, SWIPE_UP = 6,
|
||||
WIDGET_ADDED = 7, WIDGET_MENU = 8;
|
||||
WIDGET_ADDED = 7, WIDGET_MENU = 8, DRAG_TO = 35, DROP = 36;
|
||||
|
||||
// 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.
|
||||
// Letting go without moving opens its menu instead. Native widget views take their
|
||||
// own touches, so the shell reports those moves through widgetDrag/widgetDrop.
|
||||
let drag = null, dragged = false; // drag: { x, y, moved } from pointerdown
|
||||
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;
|
||||
};
|
||||
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 drop = (moved) => {
|
||||
if (document.querySelector(".slots > .lifted")) app.dispatch(DROP, moved ? 1 : 0);
|
||||
};
|
||||
addEventListener("pointerdown", (e) => {
|
||||
drag = e.isPrimary && e.target.closest?.(".slots > li") ? { x: e.clientX, y: e.clientY, moved: false } : null;
|
||||
dragged = false;
|
||||
});
|
||||
addEventListener("pointermove", (e) => {
|
||||
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);
|
||||
});
|
||||
addEventListener("pointerup", () => { if (drag) drop(drag.moved); drag = null; });
|
||||
addEventListener("pointercancel", () => { if (drag) drop(drag.moved); drag = null; });
|
||||
// Keep the page from scrolling under a lifted slot.
|
||||
addEventListener("touchmove", (e) => {
|
||||
if (drag && document.querySelector(".slots > .lifted") && e.cancelable) e.preventDefault();
|
||||
}, { passive: false });
|
||||
window.ultraHome = {
|
||||
tick: () => { formats(); app.dispatch(TICK, 1); },
|
||||
reload: () => app.dispatch(RELOAD, 0),
|
||||
@@ -121,6 +162,8 @@
|
||||
back: () => app.dispatch(BACK, 0),
|
||||
widgetAdded: (id) => app.dispatch(WIDGET_ADDED, id),
|
||||
widgetMenu: (id) => app.dispatch(WIDGET_MENU, id),
|
||||
widgetDrag: (x, y) => { dragged = true; dragTo(x, y); },
|
||||
widgetDrop: (moved) => drop(moved),
|
||||
place: () => { placed = ""; place(); },
|
||||
resetIcons: () => { iconSrc.clear(); asked.clear(); tries.clear();
|
||||
for (const img of document.querySelectorAll("img.icon")) img.__icon = undefined; },
|
||||
@@ -137,7 +180,7 @@
|
||||
start = e.touches.length === 1 ? { x: t.clientX, y: t.clientY, at: Date.now() } : null;
|
||||
}, { passive: true });
|
||||
addEventListener("touchend", (e) => {
|
||||
if (!start) return;
|
||||
if (!start || dragged || document.querySelector(".slots > .lifted")) { start = null; return; }
|
||||
const t = e.changedTouches[0], dx = t.clientX - start.x, dy = t.clientY - start.y;
|
||||
const quick = Date.now() - start.at < 700;
|
||||
start = null;
|
||||
|
||||
@@ -58,6 +58,13 @@ body { margin: 0; min-height: 100vh; color: #fff; -webkit-tap-highlight-color: t
|
||||
border: 1px dashed rgb(255 255 255 / .3); }
|
||||
.widget-label { font-size: .875rem; opacity: .75; text-shadow: var(--shadow-text); }
|
||||
|
||||
/* A slot picked up by a long press, while it is dragged (index.html moves it). */
|
||||
.slots > li { transition: transform .15s ease-out; }
|
||||
.slots > .lifted { z-index: 1; transform: scale(1.12); background: rgb(255 255 255 / .16);
|
||||
box-shadow: 0 8px 24px rgb(0 0 0 / .35); }
|
||||
.slots.dragging > li:not(.lifted) { opacity: .8; }
|
||||
.slots.dragging .tile:active { background: none; }
|
||||
|
||||
.hint, .empty { text-align: center; opacity: .85; text-shadow: var(--shadow-text); }
|
||||
.hint { margin-top: 30vh; padding: 0 2rem; font-size: .9rem; line-height: 1.5; }
|
||||
|
||||
|
||||
Reference in new issue
Block a user