repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

feat(clipboard): redesign popup — thumbnails, type icons, recency sort

257b4cdf05aec48602bcb81e1abc7370aff77ec8

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Replace the text-only, alphabetically-sorted clipboard list with a
graphical history card list.

Architecture (mirrors clip of sysinfo.js/caldav.js):
- clip.js: pure, node-tested logic (detectKind/parseColor/sortRows/
  filterRows/ageLabel/cloneRow + dual-mode export). clip.test.js ALL PASS.
- Clipboard.qml: thin I/O over clip.js (wl-paste watch, FileView persist,
  wl-copy/wtype actions). Trimmed stateObject to {privateMode,rows,
  lastAction}; deleted clipboardPanelContract/scrollableListChrome/rowsById
  narration. Added selfTest() (10/10). launcherRows shape preserved.
- PopoutHost ClipboardPanel: rewritten card list — leading image
  thumbnail / color swatch / type-icon, title + "kind · age" meta,
  hover-revealed icon action rail (copy/paste/pin/delete). Dropped the
  state-driven edge-fade chrome.

Fixes:
- sort is now pinned-first then recency (was alphabetical — the bug).
- looksLikePath allows spaces so screenshot paths thumbnail.
- Image source encodeURI'd so "/tmp/Screenshot from ….png" loads.

SurfaceManager: taller clipboard popup; trimmed catalog narration.
shell.qml: clipboard selfTest IPC.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Changed files (6)

quickshell/nuguland/Clipboard.qml

Modified
1 1 import QtQuick
2 2 import Quickshell
3 3 import Quickshell.Io
4 +import "clip.js" as Clip
5 6 Item {
6 7 id: root
13 14 readonly property int maxRows: 40
14 15 readonly property string historyPath: Quickshell.statePath("clipboard-history.json")
16 - function normalize(text) {
17 - return String(text || "").toLowerCase();
18 - }
20 - function isReadableText(text) {
21 - const value = String(text || "");
22 - if (value.length === 0 || value.length > 65536)
23 - return false;
25 - let bad = 0;
26 - for (let i = 0; i < value.length; i++) {
27 - const code = value.charCodeAt(i);
28 - if ((code >= 0 && code < 9) || (code > 13 && code < 32) || code === 65533)
29 - bad++;
31 - }
32 - return bad <= Math.max(2, Math.floor(value.length / 100));
33 - }
35 - function isTempImagePath(text) {
36 - const value = String(text || "");
37 - return value.indexOf("/tmp/") === 0 && /\.(png|jpg|jpeg|webp|gif)$/i.test(value);
38 - }
40 - function hashText(text) {
41 - const value = String(text || "");
42 - let hash = 2.16614e+09;
43 - for (let i = 0; i < value.length; i++) {
44 - hash ^= value.charCodeAt(i);
45 - hash = Math.imul(hash, 1.67776e+07);
46 - }
47 - return (hash >>> 0).toString(16);
48 - }
50 - function firstLine(text) {
51 - return String(text || "").split(/\r?\n/)[0].trim();
52 - }
54 - function rowTitle(text) {
55 - if (isTempImagePath(text))
56 - return "Image";
58 - const line = firstLine(text);
59 - if (line.length === 0)
60 - return "Clipboard";
62 - return line.length > 64 ? `${line.slice(0, 61)}…` : line;
63 - }
65 - function displayTitle(row) {
66 - if (isTempImagePath(row.title) || isTempImagePath(row.body))
67 - return "Image";
69 - return String(row.title || "Clipboard");
70 - }
72 - function displayBody(row) {
73 - const raw = String(row.body || row.title || "");
74 - if (isTempImagePath(raw))
75 - return raw.replace(/^.*\.([^.]+)$/, "$1").toUpperCase() + " clipboard item";
77 - return raw;
78 - }
80 - function persistedRow(row) {
81 - return {
82 - "id": String(row.id || ""),
83 - "title": String(row.title || "Clipboard"),
84 - "body": String(row.body || ""),
85 - "pinned": !!row.pinned,
86 - "createdAt": Number(row.createdAt || Date.now())
87 - };
88 - }
90 - function cloneRow(row) {
91 - return {
92 - "id": row.id,
93 - "title": displayTitle(row),
94 - "body": displayBody(row),
95 - "pinned": !!row.pinned,
96 - "provider": "clipboard",
97 - "route": "clipboard",
98 - "backend": "Clipboard.qml"
99 - };
100 - }
17 + // --- linear lookup over the raw persisted rows (id, title, body, pinned, createdAt) ---
102 18 function rawRowById(id) {
103 19 const needle = String(id);
104 20 for (let i = 0; i < rows.length; i++) if (rows[i].id === needle) {
110 26 function captureClipboard(text) {
111 27 const body = String(text || "");
112 - if (privateMode || !isReadableText(body))
28 + if (privateMode || !Clip.isReadableText(body))
113 29 return ;
115 - const id = `clip-${hashText(body)}`;
31 + const id = `clip-${Clip.hashText(body)}`;
116 32 const next = [];
117 33 let existingPin = false;
118 34 for (let i = 0; i < rows.length; i++) {
125 41 next.unshift({
126 42 "id": id,
127 - "title": rowTitle(body),
43 + "title": Clip.rowTitle(body),
128 44 "body": body,
129 45 "pinned": existingPin,
130 46 "createdAt": Date.now()
133 49 saveHistory();
136 - function filteredRows(query) {
137 - const q = normalize(query);
138 - const result = [];
139 - for (let i = 0; i < rows.length; i++) {
140 - const row = rows[i];
141 - if (q.length === 0 || normalize(row.title).indexOf(q) >= 0 || normalize(row.body).indexOf(q) >= 0)
142 - result.push(cloneRow(row));
144 - }
145 - result.sort((a, b) => {
146 - return (b.pinned ? 1 : 0) - (a.pinned ? 1 : 0) || a.title.localeCompare(b.title);
147 - });
148 - return result;
149 - }
151 - function rowsById(sourceRows) {
152 - const result = ({
153 - });
154 - for (let i = 0; i < sourceRows.length; i++) result[sourceRows[i].id] = sourceRows[i]
155 - return result;
156 - }
158 - function clipboardPanelContract() {
159 - return {
160 - "source": "wl-paste --watch service backend plus Nuguland ClipWrapper.qml ScrollEdgeFade.qml",
161 - "ownedBy": "PopoutHost.qml inline ClipboardPanel",
162 - "clipboardHistoryPanel": true,
163 - "privateModeChip": true,
164 - "searchField": true,
165 - "pinnedFirstRows": true,
166 - "maskedActionRail": true,
167 - "launcherRowParity": true,
168 - "serviceActionsOnly": true,
169 - "actionRows": ["copy", "paste", "pin", "delete"],
170 - "realClipboardSource": "wl-paste --watch",
171 - "noExternalClipboardHelpersInWidget": true
172 - };
173 - }
175 - function scrollableListChrome(rowCount) {
176 - const count = Math.max(0, Number(rowCount));
177 - const scrollable = count > 2;
178 - return {
179 - "source": "Nuguland ScrollEdgeFade.qml plus Nuguland FlickMonitor.qml",
180 - "scrollEdgeFade": true,
181 - "topEdgeFade": false,
182 - "bottomEdgeFade": scrollable,
183 - "fadeSize": 32,
184 - "scrollHint": {
185 - "visible": scrollable,
186 - "icon": "content_paste",
187 - "side": "right",
188 - "tooltip": "scroll clipboard"
189 - },
190 - "flickMonitor": {
191 - "enabled": true,
192 - "velocitySamples": 6,
193 - "events": ["pressed", "positionChanged", "released"]
194 - }
195 - };
196 - }
52 + // --- trimmed serialization: the view binds the cloned rows directly ---
198 53 function stateObject(query) {
199 - const visibleRows = filteredRows(query);
54 + const now = Date.now();
55 + const viewRows = Clip.filterRows(rows, query).map((row) => {
56 + return Clip.cloneRow(row, now);
57 + });
200 58 return {
201 - "backend": "Clipboard.qml",
202 - "query": String(query || ""),
203 - "searchable": true,
204 - "launcherProvider": true,
205 59 "privateMode": privateMode,
206 60 "privateRole": privateMode ? "warning" : "ui.accent",
207 - "helperProcesses": ["wl-paste --watch", "wl-copy", "wtype"],
208 - "durablePersistence": true,
209 - "historyPath": historyPath,
210 - "persistenceReady": persistenceReady,
211 - "fakeRows": false,
212 - "cleanupProof": true,
213 - "lastAction": lastAction,
214 - "clipboardPanelContract": clipboardPanelContract(),
215 - "pinnedCount": rows.filter((row) => {
216 - return row.pinned;
217 - }).length,
218 - "scrollableListChrome": scrollableListChrome(visibleRows.length),
219 - "rows": visibleRows,
220 - "rowsById": rowsById(rows.map((row) => {
221 - return cloneRow(row);
222 - }))
61 + "rows": viewRows,
62 + "lastAction": lastAction
234 74 function launcherRows(query) {
235 - const result = filteredRows(query);
75 + const now = Date.now();
76 + const result = Clip.filterRows(rows, query).map((row) => {
77 + return Clip.cloneRow(row, now);
78 + });
236 79 for (let i = 0; i < result.length; i++) {
237 80 result[i].subtitle = privateMode ? "private clipboard" : "clipboard";
238 81 result[i].keyboard = true;
315 158 const parsed = JSON.parse(String(text || "{}"));
316 159 const loadedRows = Array.isArray(parsed.rows) ? parsed.rows : [];
317 160 rows = loadedRows.map((row) => {
318 - return persistedRow(row);
161 + return Clip.persistedRow(row);
319 162 }).filter((row) => {
320 - return row.id.length > 0 && isReadableText(row.body);
163 + return row.id.length > 0 && Clip.isReadableText(row.body);
321 164 }).slice(0, maxRows);
322 165 } catch (error) {
323 166 rows = [];
333 176 const payload = {
334 177 "version": 1,
335 178 "rows": rows.map((row) => {
336 - return persistedRow(row);
179 + return Clip.persistedRow(row);
337 180 }).slice(0, maxRows)
339 182 clipboardHistoryFile.setText(JSON.stringify(payload, null, 2));
348 191 return stateJson();
194 + // --- exercises clip.js detect/sort/filter/clone through the service ---
195 + function selfTest() {
196 + const cases = [];
197 + function ok(name, cond) {
198 + cases.push({
199 + "name": name,
200 + "pass": !!cond
201 + });
203 + try {
204 + ok("detect-url", Clip.detectKind("https://example.com/x").kind === "url");
205 + ok("detect-color", Clip.detectKind("#ff0000").kind === "color");
206 + ok("detect-image", Clip.detectKind("/tmp/shot.png").kind === "image");
207 + ok("detect-path", Clip.detectKind("/etc/hosts").kind === "path");
208 + ok("detect-text", Clip.detectKind("just some words").kind === "text");
209 + const sorted = Clip.sortRows([
210 + { "id": "a", "title": "a", "body": "a", "pinned": false, "createdAt": 100 },
211 + { "id": "b", "title": "b", "body": "b", "pinned": false, "createdAt": 200 },
212 + { "id": "c", "title": "c", "body": "c", "pinned": true, "createdAt": 50 }
213 + ]);
214 + ok("sort-pinned-first", sorted[0].id === "c");
215 + ok("sort-recency-desc", sorted[1].id === "b" && sorted[2].id === "a");
216 + const filtered = Clip.filterRows([
217 + { "id": "x", "title": "hello", "body": "world", "pinned": false, "createdAt": 1 },
218 + { "id": "y", "title": "foo", "body": "bar", "pinned": false, "createdAt": 2 }
219 + ], "foo");
220 + ok("filter-match", filtered.length === 1 && filtered[0].id === "y");
221 + const imageRow = Clip.cloneRow({ "id": "i", "body": "/tmp/p.png", "pinned": false, "createdAt": Date.now() });
222 + ok("clone-image", imageRow.isImage === true && imageRow.title === "Image" && imageRow.imagePath === "/tmp/p.png");
223 + const colorRow = Clip.cloneRow({ "id": "c2", "body": "#abc", "pinned": false, "createdAt": Date.now() });
224 + ok("clone-swatch", colorRow.kind === "color" && colorRow.swatch === "#aabbcc");
225 + } catch (error) {
226 + ok("threw:" + error, false);
228 + const fail = cases.filter((c) => {
229 + return !c.pass;
230 + }).length;
231 + return JSON.stringify({
232 + "pass": cases.length - fail,
233 + "fail": fail,
234 + "cases": cases
235 + });
351 238 FileView {
352 239 id: clipboardHistoryFile

quickshell/nuguland/PopoutHost.qml

Modified
2222 2222 property string query: ""
2223 2223 property var state: clipboardService ? Util.parseJson(clipboardService.stateJson(), {
2224 2224 "rows": [],
2225 - "clipboardPanelContract": {
2226 - },
2227 - "scrollableListChrome": {
2225 + "privateMode": false,
2226 + "privateRole": "ui.accent",
2227 + "lastAction": {
2229 2229 }) : ({
2230 2230 "rows": [],
2231 - "clipboardPanelContract": {
2232 - },
2233 - "scrollableListChrome": {
2231 + "privateMode": false,
2232 + "privateRole": "ui.accent",
2233 + "lastAction": {
2236 2236 readonly property var rows: state.rows || []
2237 - readonly property var panel: state.clipboardPanelContract || ({
2238 - })
2241 2239 function refreshFrom(text) {
2289 2287 Rectangle {
2290 2288 objectName: "searchField"
2291 - width: parent.width - 112
2292 - height: 30
2293 - radius: 10
2289 + width: parent.width - 108
2290 + height: 32
2291 + radius: 12
2294 2292 color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.14) : "transparent"
2295 2293 border.width: 0
2296 2294 border.color: root.theme ? root.theme.ui.accent : "transparent"
2296 + Text {
2297 + id: searchGlyph
2299 + anchors.left: parent.left
2300 + anchors.leftMargin: 11
2301 + anchors.verticalCenter: parent.verticalCenter
2302 + text: ""
2303 + color: root.theme ? root.theme.ui.minor : "white"
2304 + font.family: "Symbols Nerd Font Mono"
2305 + font.pixelSize: 13
2298 2308 TextInput {
2299 2309 id: input
2301 2311 anchors.fill: parent
2302 - anchors.leftMargin: 10
2303 - anchors.rightMargin: 10
2312 + anchors.leftMargin: 32
2313 + anchors.rightMargin: 12
2304 2314 verticalAlignment: TextInput.AlignVCenter
2305 2315 color: root.theme ? root.theme.content.normal : "white"
2306 2316 selectionColor: root.theme ? root.theme.ui.focus : "#ffffff"
2315 2325 NuguText {
2316 2326 anchors.left: parent.left
2317 - anchors.leftMargin: 10
2327 + anchors.leftMargin: 32
2318 2328 anchors.verticalCenter: parent.verticalCenter
2319 2329 visible: input.text.length === 0
2320 2330 theme: root.theme
2327 2337 Rectangle {
2328 2338 objectName: "privateModeChip"
2329 - width: 104
2330 - height: 30
2331 - radius: 10
2339 + width: 100
2340 + height: 32
2341 + radius: 12
2332 2342 color: root.theme ? root.theme.withAlpha(root.state.privateMode ? root.theme.warning : root.theme.ui.accent, 0.2) : "transparent"
2333 2343 border.width: 0
2334 2344 border.color: root.theme ? (root.state.privateMode ? root.theme.warning : root.theme.ui.accent) : "transparent"
2336 - NuguText {
2346 + Row {
2337 2347 anchors.centerIn: parent
2338 - theme: root.theme
2339 - variant: "meta"
2340 - selected: root.state.privateMode
2341 - text: root.state.privateMode ? "private" : "normal"
2348 + spacing: 6
2350 + Text {
2351 + anchors.verticalCenter: parent.verticalCenter
2352 + text: root.state.privateMode ? "" : ""
2353 + color: root.theme ? (root.state.privateMode ? root.theme.warning : root.theme.ui.accent) : "white"
2354 + font.family: "Symbols Nerd Font Mono"
2355 + font.pixelSize: 13
2358 + NuguText {
2359 + anchors.verticalCenter: parent.verticalCenter
2360 + theme: root.theme
2361 + variant: "meta"
2362 + text: root.state.privateMode ? "private" : "normal"
2344 2367 MouseArea {
2353 2376 Rectangle {
2354 2377 objectName: "clipboardHistoryPanel"
2355 2378 width: parent.width
2356 - height: Math.min(190, Math.max(86, rowColumn.implicitHeight + 14))
2379 + height: Math.min(440, Math.max(120, rowColumn.implicitHeight + 16))
2357 2380 radius: 14
2358 2381 clip: true
2359 2382 color: root.theme ? root.theme.withAlpha(root.theme.ui.backdrop, 0.7) : "transparent"
2364 2387 id: list
2366 2389 anchors.fill: parent
2367 - anchors.margins: 7
2390 + anchors.margins: 8
2368 2391 contentHeight: rowColumn.implicitHeight
2369 2392 clip: true
2393 + boundsBehavior: Flickable.StopAtBounds
2371 2395 Column {
2372 2396 id: rowColumn
2383 2407 required property var modelData
2385 - objectName: "pinnedFirstRows"
2409 + objectName: "clipRow"
2386 2410 width: rowColumn.width
2387 - height: 50
2388 - radius: 11
2389 - color: root.theme ? root.theme.withAlpha(modelData.pinned ? root.theme.ui.focus : root.theme.ui.minor, modelData.pinned ? 0.24 : 0.1) : "transparent"
2390 - border.width: 0
2391 - border.color: root.theme ? (modelData.pinned ? root.theme.ui.focus : root.theme.ui.accent) : "transparent"
2411 + height: 56
2412 + radius: 13
2413 + color: root.theme ? root.theme.withAlpha(clipRow.modelData.pinned ? root.theme.ui.focus : root.theme.ui.minor, clipRow.modelData.pinned ? 0.22 : 0.1) : "transparent"
2414 + border.width: clipRow.modelData.pinned ? 1 : 0
2415 + border.color: root.theme ? root.theme.withAlpha(root.theme.ui.focus, 0.5) : "transparent"
2417 + // Single hover detector covering the whole card. NoButton
2418 + // lets clicks fall through to the action buttons (later
2419 + // siblings); the buttons keep hoverEnabled off so they
2420 + // never steal containsMouse from this detector.
2421 + MouseArea {
2422 + id: rowHover
2424 + anchors.fill: parent
2425 + hoverEnabled: true
2426 + acceptedButtons: Qt.NoButton
2429 + Item {
2430 + id: leadingSlot
2432 + anchors.left: parent.left
2433 + anchors.leftMargin: 9
2434 + anchors.verticalCenter: parent.verticalCenter
2435 + width: 36
2436 + height: 36
2438 + Image {
2439 + id: thumb
2441 + anchors.fill: parent
2442 + visible: clipRow.modelData.isImage && thumb.status !== Image.Error
2443 + // encodeURI keeps "/" but escapes spaces/specials so screenshot
2444 + // paths ("/tmp/Screenshot from ….png") resolve as valid file:// URLs
2445 + source: clipRow.modelData.isImage ? "file://" + encodeURI(clipRow.modelData.imagePath || "") : ""
2446 + sourceSize.width: 36
2447 + sourceSize.height: 36
2448 + fillMode: Image.PreserveAspectCrop
2449 + asynchronous: true
2450 + clip: true
2451 + smooth: true
2454 + Rectangle {
2455 + id: swatch
2457 + anchors.fill: parent
2458 + visible: !clipRow.modelData.isImage && !!clipRow.modelData.swatch
2459 + radius: 9
2460 + color: clipRow.modelData.swatch ? clipRow.modelData.swatch : "transparent"
2461 + border.width: 1
2462 + border.color: root.theme ? root.theme.withAlpha(root.theme.ui.normal, 0.25) : "transparent"
2465 + // Type-icon fallback: shown for non-image/non-color
2466 + // rows, and when the image thumbnail fails to load.
2467 + Text {
2468 + anchors.centerIn: parent
2469 + visible: !swatch.visible && !thumb.visible
2470 + text: clipRow.modelData.icon
2471 + color: root.theme ? root.theme.ui.accent : "white"
2472 + font.family: "Symbols Nerd Font Mono"
2473 + font.pixelSize: 18
2393 2478 Column {
2394 - anchors.left: parent.left
2479 + anchors.left: leadingSlot.right
2395 2480 anchors.right: actionRail.left
2396 2481 anchors.verticalCenter: parent.verticalCenter
2397 - anchors.leftMargin: 8
2398 - spacing: 2
2482 + anchors.leftMargin: 11
2483 + anchors.rightMargin: 8
2484 + spacing: 3
2400 2486 NuguText {
2401 2487 theme: root.theme
2407 2493 NuguText {
2408 2494 theme: root.theme
2409 2495 variant: "meta"
2410 - text: clipRow.modelData.body
2496 + text: clipRow.modelData.kind + " · " + clipRow.modelData.age
2411 2497 width: parent.width
2412 2498 elide: Text.ElideRight
2503 + // Pin badge, hidden while the action rail is revealed.
2504 + Text {
2505 + id: pinBadge
2507 + anchors.right: parent.right
2508 + anchors.rightMargin: 11
2509 + anchors.top: parent.top
2510 + anchors.topMargin: 8
2511 + visible: clipRow.modelData.pinned && !rowHover.containsMouse
2512 + text: ""
2513 + color: root.theme ? root.theme.ui.focus : "white"
2514 + font.family: "Symbols Nerd Font Mono"
2515 + font.pixelSize: 11
2418 2519 id: actionRail
2420 - objectName: "maskedActionRail"
2421 2521 anchors.right: parent.right
2422 - anchors.rightMargin: 6
2522 + anchors.rightMargin: 8
2423 2523 anchors.verticalCenter: parent.verticalCenter
2424 - spacing: 4
2524 + spacing: 5
2525 + opacity: rowHover.containsMouse ? 1 : 0
2526 + enabled: rowHover.containsMouse
2528 + Behavior on opacity {
2529 + NumberAnimation {
2530 + duration: root.theme && root.theme.lowPowerMode ? 0 : 120
2531 + easing.type: Easing.OutCubic
2426 2536 Repeater {
2427 2537 model: ["copy", "paste", "pin", "delete"]
2432 2542 required property string modelData
2434 - width: actionButton.modelData === "delete" ? 42 : 34
2435 - height: 26
2436 - radius: 9
2437 - color: root.theme ? root.theme.withAlpha(actionButton.modelData === "delete" ? root.theme.error : root.theme.ui.accent, 0.16) : "transparent"
2438 - border.width: 0
2439 - border.color: root.theme ? (actionButton.modelData === "delete" ? root.theme.error : root.theme.ui.accent) : "transparent"
2544 + readonly property bool isDelete: actionButton.modelData === "delete"
2545 + readonly property bool isPin: actionButton.modelData === "pin"
2546 + readonly property bool pinActive: actionButton.isPin && clipRow.modelData.pinned
2547 + readonly property string tint: !root.theme ? "transparent" : (actionButton.isDelete ? root.theme.error : (actionButton.pinActive ? root.theme.ui.focus : root.theme.ui.accent))
2441 - NuguText {
2549 + width: 30
2550 + height: 30
2551 + radius: 10
2552 + color: root.theme ? root.theme.withAlpha(actionButton.tint, actionButton.pinActive ? 0.32 : 0.16) : "transparent"
2553 + border.width: 0
2554 + border.color: "transparent"
2556 + Text {
2442 2557 anchors.centerIn: parent
2443 - theme: root.theme
2444 - variant: "meta"
2445 - text: actionButton.modelData === "copy" ? "cp" : actionButton.modelData === "paste" ? "ps" : actionButton.modelData === "pin" ? (clipRow.modelData.pinned ? "un" : "pin") : "del"
2558 + text: actionButton.modelData === "copy" ? "" : actionButton.modelData === "paste" ? "" : actionButton.isPin ? "" : ""
2559 + color: actionButton.isDelete ? (root.theme ? root.theme.error : "white") : (root.theme ? (actionButton.pinActive ? root.theme.ui.focus : root.theme.ui.normal) : "white")
2560 + font.family: "Symbols Nerd Font Mono"
2561 + font.pixelSize: 13
2448 2564 MouseArea {
2452 2568 root.copy(clipRow.modelData.id);
2453 2569 else if (actionButton.modelData === "paste")
2454 2570 root.paste(clipRow.modelData.id);
2455 - else if (actionButton.modelData === "pin")
2571 + else if (actionButton.isPin)
2456 2572 root.togglePin(clipRow.modelData.id);
2458 2574 root.deleteRow(clipRow.modelData.id);
2476 - Rectangle {
2477 - anchors.left: parent.left
2478 - anchors.right: parent.right
2479 - anchors.top: parent.top
2480 - height: root.state.scrollableListChrome && root.state.scrollableListChrome.topEdgeFade ? root.state.scrollableListChrome.fadeSize : 0
2481 - visible: height > 0
2483 - gradient: Gradient {
2484 - GradientStop {
2485 - position: 0
2486 - color: root.theme ? root.theme.ui.backdrop : "black"
2489 - GradientStop {
2490 - position: 1
2491 - color: "transparent"
2498 - Rectangle {
2499 - anchors.left: parent.left
2500 - anchors.right: parent.right
2501 - anchors.bottom: parent.bottom
2502 - height: root.state.scrollableListChrome && root.state.scrollableListChrome.bottomEdgeFade ? root.state.scrollableListChrome.fadeSize : 0
2503 - visible: height > 0
2504 - rotation: 180
2506 - gradient: Gradient {
2507 - GradientStop {
2508 - position: 0
2509 - color: root.theme ? root.theme.ui.backdrop : "black"
2512 - GradientStop {
2513 - position: 1
2514 - color: "transparent"

quickshell/nuguland/SurfaceManager.qml

Modified
95 95 case "clipboard":
96 96 return {
97 97 "width": width,
98 - "height": heightBudget(500)
98 + "height": heightBudget(560)
100 100 case "launcher":
101 101 return {
212 212 "clipboard": {
213 213 "component": "clipboard-history",
214 214 "source": "Clipboard.qml",
215 - "visual": ["search", "pinned", "private-mode", "launcher-rows"]
215 + "visual": ["search", "cards", "thumbnails", "private-mode"]
217 217 "launcher": {
218 218 "component": "launcher-search",

quickshell/nuguland/clip.js

Added
new file mode 100644
1 +// clip.js — pure clipboard logic: normalize, content-typing, sort, filter, shapers.
2 +// NO I/O. Dual-mode: node `require` (tests) + QML import. Same pattern as caldav.js/sysinfo.js.
4 +// --- Nerd Font glyphs (verified to render). Kept as \uXXXX escapes. ---
5 +var ICON_IMAGE = "\uF03E"; // image
6 +var ICON_COLOR = "\uF043"; // color (tint)
7 +var ICON_URL = "\uF0C1"; // url (link)
8 +var ICON_PATH = "\uF15B"; // path (file)
9 +var ICON_TEXT = "\uF0F6"; // text (file-text)
11 +// --- lowercase, null-safe (search/dedupe key) ---
12 +function normalize(text) {
13 + return String(text == null ? "" : text).toLowerCase();
16 +// --- reject empty / oversized / mostly-control-character (binary) captures ---
17 +function isReadableText(text) {
18 + var value = String(text == null ? "" : text);
19 + if (value.length === 0 || value.length > 65536) return false;
20 + var bad = 0;
21 + for (var i = 0; i < value.length; i++) {
22 + var code = value.charCodeAt(i);
23 + if ((code >= 0 && code < 9) || (code > 13 && code < 32) || code === 65533) bad++;
24 + }
25 + return bad <= Math.max(2, Math.floor(value.length / 100));
28 +// --- FNV-1a-ish XOR+imul hash. Literals kept identical to the original QML so
29 +// existing clip-<hash> dedupe IDs survive across restart. ---
30 +function hashText(text) {
31 + var value = String(text == null ? "" : text);
32 + var hash = 2.16614e+09;
33 + for (var i = 0; i < value.length; i++) {
34 + hash ^= value.charCodeAt(i);
35 + hash = Math.imul(hash, 1.67776e+07);
36 + }
37 + return (hash >>> 0).toString(16);
40 +// --- first non-empty-trimmed line of a value ---
41 +function firstLine(text) {
42 + return String(text == null ? "" : text).split(/\r?\n/)[0].trim();
45 +// --- a single-line path-like token (spaces allowed — screenshots have them) ---
46 +function looksLikePath(value) {
47 + if (/[\n\r\t]/.test(value)) return false;
48 + return /^(\/|~\/|\.\/|\.\.\/|file:\/\/)/.test(value);
51 +// --- temp /tmp image path OR any path ending in an image extension ---
52 +function isImagePath(text) {
53 + var value = String(text == null ? "" : text).trim();
54 + if (!looksLikePath(value)) return false;
55 + return /\.(png|jpg|jpeg|webp|gif)$/i.test(value);
58 +// --- a single http(s) / www URL token ---
59 +function isUrl(text) {
60 + var value = String(text == null ? "" : text).trim();
61 + if (/\s/.test(value)) return false;
62 + return /^(https?:\/\/|www\.)\S+$/i.test(value);
65 +// --- clamp an integer string into a 0..255 byte ---
66 +function clampByte(s) {
67 + var n = parseInt(s, 10);
68 + if (!isFinite(n)) return 0;
69 + return n < 0 ? 0 : (n > 255 ? 255 : n);
72 +function byteHex(n) {
73 + var h = n.toString(16);
74 + return h.length < 2 ? "0" + h : h;
77 +// --- parse #rgb / #rgba / #rrggbb / #rrggbbaa and rgb()/rgba() into "#rrggbb".
78 +// Shorthand is expanded; alpha is dropped. Returns null on anything else. ---
79 +function parseColor(text) {
80 + var v = String(text == null ? "" : text).trim().toLowerCase();
81 + var hex = /^#([0-9a-f]{3,8})$/.exec(v);
82 + if (hex) {
83 + var h = hex[1];
84 + if (h.length === 3 || h.length === 4) {
85 + h = h[0] + h[0] + h[1] + h[1] + h[2] + h[2]; // expand, drop shorthand alpha
86 + } else if (h.length === 6) {
87 + // already #rrggbb
88 + } else if (h.length === 8) {
89 + h = h.slice(0, 6); // drop alpha
90 + } else {
91 + return null; // length 5 or 7 — not a valid color
92 + }
93 + return "#" + h;
94 + }
95 + var rgb = /^rgba?\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*(?:,\s*[0-9.]+\s*)?\)$/.exec(v);
96 + if (rgb) {
97 + return "#" + byteHex(clampByte(rgb[1])) + byteHex(clampByte(rgb[2])) + byteHex(clampByte(rgb[3]));
98 + }
99 + return null;
102 +// --- content-type classification. Precedence: image, color, url, path, else text. ---
103 +function detectKind(text) {
104 + if (isImagePath(text)) return { kind: "image", icon: ICON_IMAGE };
105 + if (parseColor(text) !== null) return { kind: "color", icon: ICON_COLOR };
106 + if (isUrl(text)) return { kind: "url", icon: ICON_URL };
107 + if (looksLikePath(text)) return { kind: "path", icon: ICON_PATH };
108 + return { kind: "text", icon: ICON_TEXT };
111 +// --- title for a row: "Image" for image paths, else the (truncated) first line ---
112 +function rowTitle(text) {
113 + if (isImagePath(text)) return "Image";
114 + var line = firstLine(text);
115 + if (line.length === 0) return "Clipboard";
116 + return line.length > 64 ? line.slice(0, 61) + "…" : line;
119 +// --- "just now" | "Nm" | "Nh" | "Nd" relative age ---
120 +function ageLabel(createdAt, now) {
121 + var t = Number(createdAt);
122 + var ref = (now == null ? Date.now() : Number(now));
123 + if (!isFinite(t) || !isFinite(ref)) return "just now";
124 + var diff = ref - t;
125 + if (diff < 60000) return "just now";
126 + var minutes = Math.floor(diff / 60000);
127 + if (minutes < 60) return minutes + "m";
128 + var hours = Math.floor(diff / 3600000);
129 + if (hours < 24) return hours + "h";
130 + return Math.floor(diff / 86400000) + "d";
133 +// --- pinned first, then createdAt descending (recency). Returns a new array. ---
134 +function sortRows(rows) {
135 + var list = (rows || []).slice();
136 + list.sort(function (a, b) {
137 + var pa = a && a.pinned ? 1 : 0;
138 + var pb = b && b.pinned ? 1 : 0;
139 + if (pa !== pb) return pb - pa;
140 + return Number(b && b.createdAt || 0) - Number(a && a.createdAt || 0);
141 + });
142 + return list;
145 +// --- substring match on title+body, then sortRows ---
146 +function filterRows(rows, query) {
147 + var q = normalize(query);
148 + var matched = [];
149 + var list = rows || [];
150 + for (var i = 0; i < list.length; i++) {
151 + var row = list[i];
152 + if (q.length === 0 ||
153 + normalize(row.title).indexOf(q) >= 0 ||
154 + normalize(row.body).indexOf(q) >= 0) {
155 + matched.push(row);
158 + return sortRows(matched);
161 +// --- view + launcher row shape. Launcher-compatible: id,title,body,pinned,provider,route
162 +// (the service adds subtitle/keyboard). `now` is injectable for deterministic age. ---
163 +function cloneRow(row, now) {
164 + var src = row || {};
165 + var body = String(src.body == null ? "" : src.body);
166 + var kind = detectKind(body);
167 + var isImage = kind.kind === "image";
168 + var color = kind.kind === "color" ? parseColor(body) : null;
169 + return {
170 + id: String(src.id == null ? "" : src.id),
171 + title: isImage ? "Image" : rowTitle(body),
172 + body: body,
173 + pinned: !!src.pinned,
174 + kind: kind.kind,
175 + icon: kind.icon,
176 + isImage: isImage,
177 + imagePath: isImage ? body.trim() : null,
178 + swatch: color,
179 + age: ageLabel(src.createdAt, now),
180 + provider: "clipboard",
181 + route: "clipboard"
182 + };
185 +// --- durable persistence shape (clipboard-history.json rows) ---
186 +function persistedRow(row) {
187 + var src = row || {};
188 + return {
189 + id: String(src.id == null ? "" : src.id),
190 + title: String(src.title == null ? "Clipboard" : src.title),
191 + body: String(src.body == null ? "" : src.body),
192 + pinned: !!src.pinned,
193 + createdAt: Number(src.createdAt == null ? Date.now() : src.createdAt)
194 + };
197 +if (typeof module !== 'undefined' && module.exports) {
198 + module.exports = { normalize: normalize, isReadableText: isReadableText,
199 + hashText: hashText, firstLine: firstLine, rowTitle: rowTitle,
200 + isImagePath: isImagePath, parseColor: parseColor, detectKind: detectKind,
201 + sortRows: sortRows, filterRows: filterRows, ageLabel: ageLabel,
202 + cloneRow: cloneRow, persistedRow: persistedRow };

quickshell/nuguland/clip.test.js

Added
new file mode 100644
1 +const assert = require('assert');
2 +const C = require('./clip.js');
4 +// --- detectKind: every branch, precedence-correct ---
5 +assert.strictEqual(C.detectKind('https://example.com/page?x=1').kind, 'url');
6 +assert.strictEqual(C.detectKind('#ff8800').kind, 'color');
7 +assert.strictEqual(C.detectKind('#f80').kind, 'color'); // shorthand still a color
8 +assert.strictEqual(C.detectKind('/tmp/screenshot-12.png').kind, 'image'); // image beats path
9 +assert.strictEqual(C.detectKind('/home/u/file').kind, 'path'); // path, no image ext
10 +assert.strictEqual(C.detectKind('just some prose here').kind, 'text');
11 +// icons match the detected kind
12 +assert.strictEqual(C.detectKind('#f80').icon, '\uF043');
13 +assert.strictEqual(C.detectKind('https://x.io').icon, '\uF0C1');
14 +assert.strictEqual(C.detectKind('/tmp/a.png').icon, '\uF03E');
16 +// --- parseColor: shorthand expansion + alpha drop + rejection ---
17 +assert.strictEqual(C.parseColor('#f80'), '#ff8800'); // #rgb -> #rrggbb
18 +assert.strictEqual(C.parseColor('#ff8800'), '#ff8800'); // #rrggbb passthrough
19 +assert.strictEqual(C.parseColor('#f808'), '#ff8800'); // #rgba -> drop alpha
20 +assert.strictEqual(C.parseColor('#ff8800cc'), '#ff8800');// #rrggbbaa -> drop alpha
21 +assert.strictEqual(C.parseColor('rgb(255, 136, 0)'), '#ff8800');
22 +assert.strictEqual(C.parseColor('rgba(255,136,0,0.5)'), '#ff8800');
23 +assert.strictEqual(C.parseColor('#f808'), '#ff8800'); // (4-digit body is #rgba, valid)
24 +assert.strictEqual(C.parseColor('#ff888'), null); // 5-digit body -> invalid
25 +assert.strictEqual(C.parseColor('#fffffff'), null); // length 7 -> invalid
26 +assert.strictEqual(C.parseColor('hello'), null);
27 +assert.strictEqual(C.parseColor('orange'), null);
29 +// --- isImagePath ---
30 +assert.strictEqual(C.isImagePath('/tmp/x.png'), true);
31 +assert.strictEqual(C.isImagePath('/home/u/pic.JPEG'), true);
32 +assert.strictEqual(C.isImagePath('/home/u/notes.txt'), false);
33 +assert.strictEqual(C.isImagePath('not a path.png'), false); // has whitespace
35 +// --- sortRows: pinned floats above a NEWER unpinned; newest-first within a group ---
36 +const unsorted = [
37 + { id: 'a', pinned: false, createdAt: 100 },
38 + { id: 'b', pinned: true, createdAt: 50 }, // pinned but OLD
39 + { id: 'c', pinned: false, createdAt: 300 }, // newest unpinned
40 + { id: 'd', pinned: true, createdAt: 70 } // pinned, newer than b
41 +];
42 +const sorted = C.sortRows(unsorted);
43 +assert.deepStrictEqual(sorted.map(r => r.id), ['d', 'b', 'c', 'a']);
44 +// pinned ('d','b') precede the newer unpinned 'c'; within each group newest first
45 +assert.strictEqual(sorted[0].id, 'd');
46 +assert.strictEqual(sorted[1].id, 'b');
47 +assert.strictEqual(C.sortRows(unsorted).length, 4); // does not drop rows
49 +// --- filterRows: substring on title+body, ordered by sortRows afterwards ---
50 +const pool = [
51 + { id: 'k1', title: 'hello world', body: '', pinned: false, createdAt: 10 },
52 + { id: 'k2', title: 'unrelated', body: 'say hello', pinned: false, createdAt: 40 }, // matches via body
53 + { id: 'k3', title: 'HELLO again', body: '', pinned: false, createdAt: 20 }, // case-insensitive
54 + { id: 'k4', title: 'nope', body: 'nothing', pinned: false, createdAt: 99 }
55 +];
56 +const hits = C.filterRows(pool, 'hello');
57 +assert.deepStrictEqual(hits.map(r => r.id), ['k2', 'k3', 'k1']); // newest-first, k4 excluded
58 +assert.strictEqual(C.filterRows(pool, '').length, 4); // empty query = all
60 +// --- ageLabel: bucket boundaries ---
61 +const now = 1000000000000;
62 +assert.strictEqual(C.ageLabel(now, now), 'just now'); // 0s
63 +assert.strictEqual(C.ageLabel(now - 90 * 1000, now), '1m'); // 90s -> 1m
64 +assert.strictEqual(C.ageLabel(now - 2 * 3600 * 1000, now), '2h'); // 2h
65 +assert.strictEqual(C.ageLabel(now - 3 * 86400 * 1000, now), '3d');// 3d
67 +// --- isReadableText: rejects a binary string, accepts prose ---
68 +let binary = '';
69 +for (let i = 0; i < 64; i++) binary += String.fromCharCode(i % 7); // control bytes 0..6
70 +assert.strictEqual(C.isReadableText(binary), false);
71 +assert.strictEqual(C.isReadableText('a normal clipboard line'), true);
72 +assert.strictEqual(C.isReadableText(''), false);
74 +// --- cloneRow: launcher-compatible shape + enriched view fields ---
75 +const cr = C.cloneRow({ id: 'x', body: '#f80', pinned: true, createdAt: now }, now);
76 +['id', 'title', 'body', 'pinned', 'provider', 'route'].forEach(function (k) {
77 + assert.ok(cr.hasOwnProperty(k), 'cloneRow missing launcher key: ' + k);
78 +});
79 +assert.strictEqual(cr.provider, 'clipboard');
80 +assert.strictEqual(cr.route, 'clipboard');
81 +assert.strictEqual(cr.kind, 'color');
82 +assert.strictEqual(cr.swatch, '#ff8800');
83 +assert.strictEqual(cr.isImage, false);
84 +assert.strictEqual(cr.imagePath, null);
85 +assert.strictEqual(cr.age, 'just now');
86 +// image row: title forced to "Image", imagePath populated, swatch null
87 +const ci = C.cloneRow({ id: 'y', body: '/tmp/a.png', createdAt: now }, now);
88 +assert.strictEqual(ci.title, 'Image');
89 +assert.strictEqual(ci.isImage, true);
90 +assert.strictEqual(ci.imagePath, '/tmp/a.png');
91 +assert.strictEqual(ci.swatch, null);
93 +// --- persistedRow: durable storage shape ---
94 +const pr = C.persistedRow({ id: 'z', title: 't', body: 'b', pinned: true, createdAt: 5 });
95 +assert.deepStrictEqual(pr, { id: 'z', title: 't', body: 'b', pinned: true, createdAt: 5 });
97 +console.log('clip.test.js: ALL PASS');

quickshell/nuguland/shell.qml

Modified
638 638 function selfTest() : string { return resources.selfTest(); }
641 + IpcHandler {
642 + target: "clipboard"
643 + function selfTest() : string { return clipboard.selfTest(); }
641 646 IpcHandler {
642 647 function ping() : string {
643 648 return "nuguland";