Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Interface: a dragged reminder, contact, file or photo is a small picture of it, never its row

Felitendo58bb4ec474c5
diff --git a/.uiverify/drag-picture.mjs b/.uiverify/drag-picture.mjs
new file mode 100644
index 0000000..a185958
--- /dev/null
+++ b/.uiverify/drag-picture.mjs
@@ -0,0 +1,87 @@
+// What a drag shows under the pointer (lib/dragPicture): a reminder, a contact or a file is
+// dragged as its name in a small capsule, a photo as a small square — never the whole row,
+// which WebKitGTK drew as wide as the pane and, on a screen at 2×, twice that. In WebKitGTK at
+// 2× the picture is painted at half, which WebKitGTK's own doubling brings back to its size.
+//
+// BASE=http://localhost:4173 node .uiverify/drag-picture.mjs
+// BASE=http://localhost:4173 ENGINE=webkit node .uiverify/drag-picture.mjs
+import { engine, engineName } from "./engine.mjs";
+import { SERVICES, installStub, openScreen } from "./stub.mjs";
+
+const BASE = process.env.BASE ?? "http://localhost:4173";
+const b = await engine.launch();
+let failures = 0;
+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${m}`); if (!p) failures++; };
+
+/** Every picture handed to setDragImage, measured as it is handed over. */
+const spy = () => {
+ window.__pictures = [];
+ const set = DataTransfer.prototype.setDragImage;
+ DataTransfer.prototype.setDragImage = function (el, x, y) {
+ const box = el.getBoundingClientRect();
+ window.__pictures.push({ w: box.width, h: box.height, transform: el.style.transform, text: el.textContent, cls: el.className });
+ return set.call(this, el, x, y);
+ };
+};
+const last = (page) => page.evaluate(() => window.__pictures.at(-1) ?? null);
+
+const fixtures = { remindersFixture: true, contactsFixture: true, driveFixture: true };
+const ctx = await b.newContext({ viewport: { width: 1280, height: 800 } });
+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null, ...fixtures });
+await ctx.addInitScript(spy);
+const page = await ctx.newPage();
+page.on("pageerror", (e) => ok(false, `page error: ${e.message}`));
+await page.goto(BASE, { waitUntil: "networkidle" });
+
+// Reminders: a row onto another row of its list.
+await openScreen(page, "Reminders");
+await page.locator(".rx-list", { hasText: "Daily" }).click();
+const rows = page.locator('.rx-row[draggable="true"]');
+await rows.nth(1).waitFor();
+const rowBox = await rows.first().boundingBox();
+await rows.first().dragTo(rows.nth(1));
+let pic = await last(page);
+ok(pic && pic.cls.includes("drag-label") && pic.text.includes("Plan tomorrow"), `a reminder is dragged as its name (${pic?.text})`);
+ok(pic && pic.w <= 280 && pic.h <= 32 && pic.w < rowBox.width / 2, `small beside its ${Math.round(rowBox.width)}-pixel row: ${pic && `${Math.round(pic.w)}×${Math.round(pic.h)}`}`);
+ok(!(await page.locator(".drag-picture").count()), "and gone from the page once the drag has its picture");
+
+// Contacts: a card onto a list.
+await openScreen(page, "Contacts");
+const card = page.locator('.contact-rows li[draggable="true"]').first();
+await card.waitFor();
+const list = page.locator(".source-row").last();
+await card.dragTo(list);
+pic = await last(page);
+ok(pic && pic.cls.includes("drag-label") && pic.w <= 280 && pic.h <= 32, `a contact is dragged as its name: ${pic && `${pic.text}, ${Math.round(pic.w)}×${Math.round(pic.h)}`}`);
+
+// Drive: a file onto a folder.
+await openScreen(page, "Drive");
+const file = page.locator('.drive-row[draggable="true"]:not(.is-folder)').first();
+await file.waitFor();
+const folder = page.locator(".drive-row.is-folder").first();
+await file.dragTo(folder);
+pic = await last(page);
+ok(pic && pic.cls.includes("drag-label") && pic.w <= 280 && pic.h <= 32, `a file is dragged as its name: ${pic && `${pic.text}, ${Math.round(pic.w)}×${Math.round(pic.h)}`}`);
+await ctx.close();
+
+// WebKitGTK on a screen at 2×: the picture painted at half. Marked as WebKitGTK here whatever
+// the engine, since only there is it scaled.
+const hi = await b.newContext({ viewport: { width: 1280, height: 800 }, deviceScaleFactor: 2 });
+await hi.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null, ...fixtures });
+await hi.addInitScript(spy);
+await hi.addInitScript(() => document.addEventListener("DOMContentLoaded", () => { document.documentElement.dataset.engine = "gtk"; }));
+const p2 = await hi.newPage();
+p2.on("pageerror", (e) => ok(false, `page error: ${e.message}`));
+await p2.goto(BASE, { waitUntil: "networkidle" });
+await openScreen(p2, "Reminders");
+await p2.locator(".rx-list", { hasText: "Daily" }).click();
+const r2 = p2.locator('.rx-row[draggable="true"]');
+await r2.nth(1).waitFor();
+await r2.first().dragTo(r2.nth(1));
+pic = await last(p2);
+ok(pic?.transform === "scale(0.5)", `in WebKitGTK at 2× it is painted at half (${pic?.transform || "not scaled"})`);
+await hi.close();
+
+await b.close();
+console.log(`${engineName}: ${failures ? `${failures} FAILED` : "all passed"}`);
+process.exit(failures ? 1 : 0);
diff --git a/check.sh b/check.sh
index fdfed57..6f48220 100755
--- a/check.sh
+++ b/check.sh
@@ -79,6 +79,7 @@ step "photos preparing" node .uiverify/photos-preparing.mjs
step "photo albums" node .uiverify/photos-albums.mjs
step "photos at scale" node .uiverify/photos-scale.mjs
step "photos drag" node .uiverify/photos-drag.mjs
+step "drag pictures" node .uiverify/drag-picture.mjs
step "photos keys" node .uiverify/photos-keys.mjs
step "photos sort" node .uiverify/photos-sort.mjs
step "slideshow" node .uiverify/photos-show.mjs
@@ -139,6 +140,7 @@ step "webkit: photos" env ENGINE=webkit node .uiverify/photos.mjs
step "webkit: albums" env ENGINE=webkit node .uiverify/photos-albums.mjs
step "webkit: at scale" env ENGINE=webkit node .uiverify/photos-scale.mjs
step "webkit: drag" env ENGINE=webkit node .uiverify/photos-drag.mjs
+step "webkit: drag pictures" env ENGINE=webkit node .uiverify/drag-picture.mjs
# As Skykeep's window is on Windows, where no drag event of the engine's reaches the page.
step "windows: photos drag" env WEBVIEW2=1 node .uiverify/photos-drag.mjs
step "windows: reminder drag" env WEBVIEW2=1 node .uiverify/reminders-drag-list.mjs
diff --git a/src/lib/dragPicture.ts b/src/lib/dragPicture.ts
new file mode 100644
index 0000000..3bee9fc
--- /dev/null
+++ b/src/lib/dragPicture.ts
@@ -0,0 +1,47 @@
+/**
+ * What a drag shows under the pointer: a small picture of what is carried — a row's name, as
+ * the Mac shows it, or a photo — never the whole row.
+ *
+ * Left to itself the engine draws the dragged element, and a reminder's, a contact's or a
+ * file's row is as wide as its pane. WebKitGTK (GTK 3) also hands GTK that picture as it made
+ * it, at the screen's scale, without saying which, and GTK draws each of its pixels as a whole
+ * point: on a screen at 2× a 664-pixel reminder row was dragged as a 1328 × 110 picture and a
+ * file's row as 1852 × 78, held where it was grabbed and running off the window's edge.
+ * Measured with a drag begun in WebKitGTK 2.54 itself and its drag icon read back from GTK.
+ *
+ * So the picture here is small, and in WebKitGTK it is drawn at one over the screen's scale,
+ * which that doubling brings back to its own size: a 240 × 32 label at 2× arrives 240 × 32.
+ * Chromium (WebView2) scales a drag picture itself, and on Windows a drag inside the page is
+ * carried by lib/drag with no picture at all, so there it is left as it is.
+ */
+export function carryPicture(e: { dataTransfer: DataTransfer | null }, picture: HTMLElement, x: number, y: number) {
+ const data = e.dataTransfer;
+ if (!data || typeof data.setDragImage !== "function") return;
+ if (document.documentElement.dataset.engine === "gtk" && window.devicePixelRatio > 1) {
+ // Scaled as it is painted, not laid out smaller (`zoom`): smaller, its words met WebKit's
+ // least font size and came out too large for their capsule.
+ picture.style.transformOrigin = "0 0";
+ picture.style.transform = `scale(${1 / window.devicePixelRatio})`;
+ }
+ // Drawn off-screen for the moment the engine takes its picture, then gone.
+ picture.classList.add("drag-picture");
+ document.body.appendChild(picture);
+ data.setDragImage(picture, x, y);
+ window.setTimeout(() => picture.remove(), 0);
+}
+
+/** A row's name in a small capsule, with how many go with it when it is more than one. */
+export function carryLabel(e: { dataTransfer: DataTransfer | null }, text: string, count = 1) {
+ const label = document.createElement("div");
+ label.className = "drag-label";
+ const name = document.createElement("span");
+ name.textContent = text.trim() || "—";
+ label.appendChild(name);
+ if (count > 1) {
+ const n = document.createElement("b");
+ n.textContent = String(count);
+ label.appendChild(n);
+ }
+ // Beside the pointer's tip rather than under the arrow, which covered the name's first letters.
+ carryPicture(e, label, -16, -4);
+}
diff --git a/src/screens/ContactsView.tsx b/src/screens/ContactsView.tsx
index b287052..2af0c76 100644
--- a/src/screens/ContactsView.tsx
+++ b/src/screens/ContactsView.tsx
@@ -39,6 +39,7 @@ import { keepSame } from "../lib/same";
import { useChosen, useIsChosen, type Chosen } from "../lib/chosen";
import { useArrivals } from "../lib/arrival";
import { copyText } from "../lib/clipboard";
+import { carryLabel } from "../lib/dragPicture";
/** The sidebar row that is every contact rather than a list. */
const ALL = "";
@@ -892,7 +893,9 @@ export function ContactsView() {
const { picked } = latest.current;
e.dataTransfer.effectAllowed = "copy";
e.dataTransfer.setData("text/plain", displayName(contact));
- setDragging(picked.includes(contact.guid) ? picked : [contact.guid]);
+ const carried = picked.includes(contact.guid) ? picked : [contact.guid];
+ carryLabel(e, displayName(contact), carried.length);
+ setDragging(carried);
},
dragEnd: () => {
setDragging(null);
diff --git a/src/screens/DriveView.tsx b/src/screens/DriveView.tsx
index 315fff3..74ae287 100644
--- a/src/screens/DriveView.tsx
+++ b/src/screens/DriveView.tsx
@@ -35,6 +35,7 @@ import { dateText, timeText } from "../lib/when";
import { Clock } from "lucide-react";
import { useReveal } from "../lib/reveal";
import { keepSame } from "../lib/same";
+import { carryLabel } from "../lib/dragPicture";
import { copyName, copyText, keepBothName } from "../lib/clipboard";
import { useChosen, useIsChosen, type Chosen } from "../lib/chosen";
@@ -1553,6 +1554,7 @@ export function DriveView() {
dragItem.current = picked.includes(item.drivewsid) ? rows.filter((r) => picked.includes(r.drivewsid)) : [item];
e.dataTransfer.effectAllowed = "move";
e.dataTransfer.setData("application/x-quince-drive", item.drivewsid);
+ carryLabel(e, driveName(item), dragItem.current.length);
},
dragEnd: () => {
dragItem.current = null;
diff --git a/src/screens/PhotosView.tsx b/src/screens/PhotosView.tsx
index 44be649..0962b45 100644
--- a/src/screens/PhotosView.tsx
+++ b/src/screens/PhotosView.tsx
@@ -49,6 +49,7 @@ import { Picker } from "../components/Picker";
import { PAGE, PhotoList, PhotoStore } from "./photos/list";
import { Periods, monthName, type Level, type Place } from "./photos/Periods";
import { same } from "../lib/same";
+import { carryPicture } from "../lib/dragPicture";
/** The library switcher's choices, named as Photos names them. */
const LIBRARIES = [
@@ -2331,7 +2332,7 @@ export function PhotosView() {
e.dataTransfer.setData("application/x-quince-photos", ids.join(","));
// A stack of photos with how many, as Photos drags them.
const img = e.currentTarget.querySelector("img");
- if (img && typeof e.dataTransfer.setDragImage === "function") {
+ if (img) {
const ghost = document.createElement("div");
ghost.className = "px-ghost";
const pic = img.cloneNode() as HTMLImageElement;
@@ -2341,9 +2342,7 @@ export function PhotosView() {
n.textContent = String(ids.length);
ghost.appendChild(n);
}
- document.body.appendChild(ghost);
- e.dataTransfer.setDragImage(ghost, 36, 36);
- window.setTimeout(() => ghost.remove(), 0);
+ carryPicture(e, ghost, 36, 36);
}
};
const dropTarget = (a: PhotoAlbum) => (a.folder ? {} : {
diff --git a/src/screens/RemindersView.tsx b/src/screens/RemindersView.tsx
index e71ff50..92c6790 100644
--- a/src/screens/RemindersView.tsx
+++ b/src/screens/RemindersView.tsx
@@ -47,6 +47,7 @@ import { useReveal } from "../lib/reveal";
import { instantIn, wallIn, zoneName, type Wall } from "./calendar/model";
import { keepSame, same } from "../lib/same";
import { useArrivals } from "../lib/arrival";
+import { carryLabel } from "../lib/dragPicture";
/** Apple's built-in views, in Apple's order, each with the glyph and system colour its app uses. */
const SMART: { kind: SmartList; title: string; glyph: GlyphName; colour: string }[] = [
@@ -2461,6 +2462,8 @@ const ReminderRow = memo(function ReminderRow({
if (!canReorder) return;
e.dataTransfer.effectAllowed = "move";
e.dataTransfer.setData("text/plain", reminder.guid);
+ // Its name under the pointer, not the whole row (lib/dragPicture).
+ carryLabel(e, reminder.title);
act.current.startDrag(reminder.guid);
}}
onDragEnd={() => act.current.endDrag()}
diff --git a/src/styles/kit.css b/src/styles/kit.css
index ee915a0..4716b2e 100644
--- a/src/styles/kit.css
+++ b/src/styles/kit.css
@@ -660,3 +660,38 @@ span.switch::after { content: ""; }
}
.receiving-line-text { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.receiving-line .progress { height: 2px; }
+
+/* ---- what a drag carries (lib/dragPicture) ------------------------------------------------ */
+
+/* Off-screen, for the moment the engine takes its picture; the pointer shows the picture. */
+.drag-picture { position: fixed; top: -400px; left: -400px; pointer-events: none; }
+/* A row's name in a capsule, as the Mac drags a reminder, a card or a file: never the row. */
+.drag-label {
+ display: inline-flex;
+ align-items: center;
+ gap: 6px;
+ max-width: 260px;
+ height: 28px;
+ padding: 0 12px;
+ border-radius: 14px;
+ background: var(--sheet);
+ box-shadow: inset 0 0 0 1px var(--glass-edge);
+ color: var(--text);
+ font-size: var(--t-13);
+ font-weight: 500;
+ line-height: 28px;
+ white-space: nowrap;
+}
+.drag-label span { overflow: hidden; text-overflow: ellipsis; }
+.drag-label b {
+ min-width: 20px;
+ height: 20px;
+ padding: 0 6px;
+ border-radius: 10px;
+ background: var(--sys-red);
+ color: #fff;
+ font-size: var(--t-12);
+ font-weight: 600;
+ line-height: 20px;
+ text-align: center;
+}