From 9278de14aa7729d03f1efb1c15574350e969e42e Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 22 Oct 2026 00:26:34 +0000 Subject: [PATCH] Move a widget by dragging it while it shows resize handles Holding a widget and letting go puts it in edit mode (resize handles). Now pressing the widget's body in that mode picks it up right away, without another long press: drag it to a new spot and it drops back into edit mode so it can be resized or moved again. The handles still resize. Natively, the page marks the widget in edit mode in placeWidgets, and its WidgetView takes the press as a drag (widgetGrab) instead of passing it to the widget. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_0126xtn5CLB47ph1Njd7frgW --- .../java/dev/ultra/launcher/MainActivity.java | 18 ++++++++++++- tests/e2e.cjs | 12 +++++++++ web/app.py | 25 +++++++++++++----- web/app.wasm | Bin 13755 -> 13861 bytes web/index.html | 23 +++++++++++----- 5 files changed, 65 insertions(+), 13 deletions(-) diff --git a/android/app/src/main/java/dev/ultra/launcher/MainActivity.java b/android/app/src/main/java/dev/ultra/launcher/MainActivity.java index 60b2135..c1f6ece 100644 --- a/android/app/src/main/java/dev/ultra/launcher/MainActivity.java +++ b/android/app/src/main/java/dev/ultra/launcher/MainActivity.java @@ -98,6 +98,7 @@ public class MainActivity extends Activity { private final Map widgetViews = new HashMap<>(); private final Map widgetSizes = new HashMap<>(); // last size told to each widget private int pendingWidget = -1; + private int editingWidget = -1; // showing resize handles: a press on it moves it private boolean ready; private int insetTop, insetBottom; // CSS px private LauncherApps launcher; @@ -522,14 +523,19 @@ public class MainActivity extends Activity { web.setSystemGestureExclusionRects(rects); } - /** Lay widget views over the page's live slots: [[id, x, y, w, h], ...] in CSS px. */ + /** + * Lay widget views over the page's live slots: [[id, x, y, w, h, editing], ...] in CSS + * px, where editing is 1 for the one showing resize handles. + */ private void placeWidgets(String json) { float d = getResources().getDisplayMetrics().density; Map want = new HashMap<>(); + int editing = -1; try { JSONArray a = new JSONArray(json); for (int i = 0; i < a.length(); i++) { JSONArray r = a.getJSONArray(i); + if (r.optInt(5) == 1) editing = r.getInt(0); want.put(r.getInt(0), new int[] { Math.round(r.getInt(1) * d), Math.round(r.getInt(2) * d), Math.round(r.getInt(3) * d), Math.round(r.getInt(4) * d), @@ -538,6 +544,7 @@ public class MainActivity extends Activity { } catch (JSONException e) { return; } + editingWidget = editing; for (Map.Entry e : widgetViews.entrySet()) { if (!want.containsKey(e.getKey())) e.getValue().setVisibility(View.GONE); } @@ -576,6 +583,7 @@ public class MainActivity extends Activity { * Widget views that report a long press to the page instead of to the widget. The press * lifts the widget's slot; the moves and the release that follow go to the page as * widgetDrag(x, y) in CSS px and widgetDrop(moved), so it can be dragged to a new place. + * A widget showing resize handles is picked up by any press on it (widgetGrab(id)). */ static final class Host extends AppWidgetHost { Host(MainActivity a) { super(a, HOST_ID); } @@ -615,6 +623,14 @@ public class MainActivity extends Activity { longPressed = false; downX = e.getX(); downY = e.getY(); + if (home.editingWidget == id) { + // Being resized: the press moves it, without a long press first. + longPressed = true; + moved = false; + setAlpha(.85f); + home.js("widgetGrab(" + id + ")"); + return true; + } postDelayed(fire, ViewConfiguration.getLongPressTimeout()); break; case MotionEvent.ACTION_MOVE: diff --git a/tests/e2e.cjs b/tests/e2e.cjs index 135b957..6b7bcb0 100644 --- a/tests/e2e.cjs +++ b/tests/e2e.cjs @@ -116,7 +116,19 @@ const BASE = process.env.BASE || "http://localhost:8000"; assert.ok(!(await p.$(".resize-handle"))); await p.reload(); await p.waitForSelector(".widget-slot"); assert.deepEqual(await size(), [w1, h1], "the size is saved"); + // while it shows handles, dragging the widget itself moves it, without another long press await longpress(".widget-slot"); + const order = () => p.$$eval(".slots > li", (ls) => ls.map((l) => l.classList.contains("widget-slot") ? "W" : "a")); + assert.notEqual((await order())[0], "W"); + const wb = await p.locator(".widget-slot").boundingBox(), first = await p.locator(".slots > li").first().boundingBox(); + await p.mouse.move(wb.x + wb.width / 2, wb.y + wb.height / 2); + await p.mouse.down(); await settle(); + assert.ok(await p.$(".widget-slot.lifted"), "pressing a widget with handles picks it up"); + await p.mouse.move(first.x + first.width / 2, first.y + first.height / 2, { steps: 8 }); await settle(); + await p.mouse.up(); await settle(); + assert.equal((await order())[0], "W", "dragged to the front"); + assert.ok(await p.$(".widget-slot.resizing"), "it keeps its handles after the move"); + assert.ok(!(await p.$(".sheet"))); await p.click(".resize-bar >> text=Remove"); await settle(); assert.ok(!(await p.$(".widget-slot"))); await p.evaluate(() => { window.ultraHome.reload(); }); await settle(); diff --git a/web/app.py b/web/app.py index e45624c..9332c1f 100644 --- a/web/app.py +++ b/web/app.py @@ -12,7 +12,8 @@ from ui import btn_open, input_open, alert # 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: -# dragging them snaps the widget to the grid, within the sizes it allows. +# dragging them snaps the widget to the grid, within the sizes it allows, and +# dragging the widget itself moves it, staying 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 @@ -93,6 +94,7 @@ WCLEAR: Const[i32] = 38 CHOOSE_FIRST_WIDGET: Const[i32] = 39 RESIZE: Const[i32] = 40 # arg: columns * 4096 + height in px for the widget being resized RESIZE_DONE: Const[i32] = 41 +GRAB: Const[i32] = 42 # arg: the widget slot showing handles, picked up by its body CAP: Const[i32] = 512 HOME_CAP: Const[i32] = 40 @@ -151,6 +153,7 @@ 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 resizing: i32 = -1 # widget slot showing resize handles +regrab: i32 = 0 # the lifted slot was grabbed while showing handles: drop it back into them pending: i32 = 0 # JSON handle of a request in flight @@ -407,7 +410,7 @@ def slot_of_widget(wid: i32) -> i32: def close_all() -> None: - global drawer, picking, sheet, item, lifted, resizing + global drawer, picking, sheet, item, lifted, resizing, regrab s_clear(query) drawer = 0 picking = 0 @@ -415,10 +418,11 @@ def close_all() -> None: item = -1 lifted = -1 resizing = -1 + regrab = 0 # ---- Update def update(msg: i32, arg: i32) -> None: - global loading, drawer, picking, sheet, item, pending, wloading, chosen, lifted, resizing + global loading, drawer, picking, sheet, item, pending, wloading, chosen, lifted, resizing, regrab i: i32 if msg == LOADED: load_apps(arg) @@ -465,27 +469,35 @@ def update(msg: i32, arg: i32) -> None: haptic() sheet = SHEET_MENU elif msg == LIFT: - if drawer == 0 and sheet == NONE: + if drawer == 0 and sheet == NONE and arg != lifted: haptic() resizing = -1 + regrab = 0 lifted = arg elif msg == WIDGET_MENU: i = slot_of_widget(arg) if i >= 0 and drawer == 0 and sheet == NONE: resizing = -1 + regrab = 0 lifted = i + elif msg == GRAB: + if arg >= 0 and arg == resizing and drawer == 0 and sheet == NONE: + resizing = -1 + regrab = 1 + lifted = arg 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: + if lifted >= 0 and (arg == 0 or regrab == 1): if hkind[lifted] == WIDGET: resizing = lifted else: item = lifted sheet = SHEET_ITEM lifted = -1 + regrab = 0 elif msg == RESIZE: if resizing >= 0: hw[resizing] = arg // 4096 @@ -551,6 +563,7 @@ def update(msg: i32, arg: i32) -> None: elif msg == BACK: if lifted >= 0: lifted = -1 + regrab = 0 elif resizing >= 0: resizing = -1 elif sheet != NONE: @@ -586,7 +599,7 @@ def view_resize_bar() -> None: attr("role", "toolbar") el("span") cls("resize-hint") - text("Drag the handles to resize") + text("Drag to move, or drag the handles to resize") end() btn_open("ghost", REMOVE, resizing) cls("sm") diff --git a/web/app.wasm b/web/app.wasm index 028dc46a9daa4d1b44298e6f50125f2a03fcef76..010cdaf6d014851d9f5372484b1418c45ecaeb5d 100644 GIT binary patch delta 4925 zcmai1YfN0n6}|&3zV-!n7FY~x9(S2*{KD7}VjE&RJBBO^82pNZNvgKnu(q+WAq#1f z{83?3CHpnDdm( z{){{npe0`cj8$Yddi!orwc zNWtyT1(XOx;wfo>?@PBM%UOq2DCn&8QmkJc2(ByM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GKH-%*!E_jCIqn0X^X3NIPk<`A%_j+?#cd2TNOE9(^^=jx|mp*aG*%k9$VEvwR4cUo6;#QzV-*gJm! diff --git a/web/index.html b/web/index.html index a302c33..f5afffd 100644 --- a/web/index.html +++ b/web/index.html @@ -43,7 +43,8 @@ const place = () => { const slots = [...document.querySelectorAll(".widget-slot[data-wid]")].map((s) => { const r = s.getBoundingClientRect(); - return [+s.dataset.wid, Math.round(r.left), Math.round(r.top), Math.round(r.width), Math.round(r.height)]; + return [+s.dataset.wid, Math.round(r.left), Math.round(r.top), Math.round(r.width), Math.round(r.height), + s.classList.contains("resizing") ? 1 : 0]; // its body moves it instead of taking touches }); const j = JSON.stringify(slots); if (j !== placed) { placed = j; host.placeWidgets(j); } @@ -130,12 +131,14 @@ // 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; + WIDGET_ADDED = 7, WIDGET_MENU = 8, DRAG_TO = 35, DROP = 36, RESIZE = 40, GRAB = 42; // 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. + // 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 const slotAt = (x, y) => { let best = -1, bestD = Infinity; @@ -156,6 +159,12 @@ const drop = (moved) => { if (document.querySelector(".slots > .lifted")) app.dispatch(DROP, moved ? 1 : 0); }; + let grabbed = false; + const grab = (li) => { grabbed = true; app.dispatch(GRAB, +li.dataset.slot); }; + addEventListener("pointerdown", (e) => { + const li = e.isPrimary && !e.target.closest?.(".resize-handle") && e.target.closest?.(".slots > li.resizing"); + if (li) grab(li); + }, true); addEventListener("pointerdown", (e) => { drag = e.isPrimary && e.target.closest?.(".slots > li") ? { x: e.clientX, y: e.clientY, moved: false } : null; dragged = false; @@ -220,10 +229,10 @@ host.haptic(); app.dispatch(RESIZE, (cols >= n ? 0 : cols) * 4096 + h); }, true); - const endResize = () => { if (rs) { rs = null; swallowClick = true; setTimeout(() => swallowClick = false, 0); } }; + const endResize = () => { if (rs || grabbed) { rs = null; grabbed = false; swallowClick = true; setTimeout(() => swallowClick = false, 0); } }; addEventListener("pointerup", endResize, true); addEventListener("pointercancel", endResize, true); - addEventListener("click", (e) => { // the click that ends a handle drag isn't a tap beside the widget + addEventListener("click", (e) => { // the click that ends a handle drag or a move isn't a tap beside the widget if (swallowClick || e.target.closest?.(".resize-handle")) { swallowClick = false; e.stopPropagation(); e.preventDefault(); } }, true); addEventListener("touchmove", (e) => { if (rs && e.cancelable) e.preventDefault(); }, { passive: false }); @@ -234,6 +243,8 @@ back: () => app.dispatch(BACK, 0), widgetAdded: (id) => app.dispatch(WIDGET_ADDED, id), widgetMenu: (id) => app.dispatch(WIDGET_MENU, id), + widgetGrab: (id) => { const li = document.querySelector(`.widget-slot.resizing[data-wid="${id}"]`); + if (li) app.dispatch(GRAB, +li.dataset.slot); }, widgetDrag: (x, y) => { dragged = true; dragTo(x, y); }, widgetDrop: (moved) => drop(moved), place: () => { placed = ""; place(); },