repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

feat(launcher): graphical redesign — real app icons, subsequence fuzzy

864680a72f9d6a186a4c5f06eac00fc8956a17cb

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Extract launcher logic to pure node-tested launch.js (prefixIntent,
subsequence-aware fuzzyScore, calculatorValue, buildApps, rankResults);
Launcher.qml becomes a thin I/O shell over it, plus selfTest (14/14).

View: full-width card list with real themed app icons (IconImage +
Quickshell.iconPath), provider accent bars, solid dark cards, calculator
result row, wheel/keyboard nav. Delete narration bloat (launcherPanelContract,
scrollableListChrome, launcherPreviewPanel, previewActionRows), the 386px
side preview panel, and provider chips. Net -312 QML lines.

Fix: 'clip' prefix detection (trim stripped the trigger space); wheel
direction now matches the Up arrow.

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

Changed files (5)

quickshell/nuguland/Launcher.qml

Modified
1 1 import QtQuick
2 2 import Quickshell
3 +import "launch.js" as Launch
4 5 Item {
5 6 id: root
7 8 property QtObject niriService
8 9 property QtObject clipboardService
9 - property var wheelTrace: []
10 10 property var launchRecords: []
11 11 property var lastInteraction: ({
34 34 // Apps come straight from Quickshell's native DesktopEntries singleton, which
35 35 // already parses XDG desktop files, drops Hidden/NoDisplay, and dedupes by id.
36 - // The binding re-evaluates when the entry set changes.
37 - readonly property var apps: root.buildApps(DesktopEntries.applications ? DesktopEntries.applications.values : [])
36 + // The binding re-evaluates when the entry set changes. Mapping lives in launch.js.
37 + readonly property var apps: Launch.buildApps(DesktopEntries.applications ? DesktopEntries.applications.values : [])
38 38 readonly property bool appScanDone: true
39 39 readonly property string appScanError: ""
41 - function normalize(text) {
42 - return String(text || "").trim().toLowerCase();
43 - }
45 - function prefixIntent(raw) {
46 - const text = String(raw || "").trim();
47 - if (text.startsWith("="))
48 - return {
49 - "provider": "calculator",
50 - "query": text.slice(1).trim()
51 - };
53 - if (text.startsWith(">"))
54 - return {
55 - "provider": "action",
56 - "query": text.slice(1).trim()
57 - };
59 - if (text.toLowerCase().startsWith("clip "))
60 - return {
61 - "provider": "clipboard",
62 - "query": text.slice(5).trim()
63 - };
65 - return {
66 - "provider": "all",
67 - "query": text
68 - };
69 - }
71 - function fuzzyScore(query, title, providerBoost) {
72 - const q = normalize(query);
73 - const t = normalize(title);
74 - if (q.length === 0)
75 - return providerBoost;
77 - if (t === q)
78 - return providerBoost + 1000;
80 - if (t.startsWith(q))
81 - return providerBoost + 800 - t.length;
83 - if (t.indexOf(q) >= 0)
84 - return providerBoost + 500 - t.indexOf(q);
86 - return -1;
87 - }
89 - function calculatorValue(expression) {
90 - const expr = String(expression || "").replace(/\s+/g, "");
91 - if (!/^[0-9.+\-*/()%]+$/.test(expr) || expr.length === 0)
92 - return "";
94 - try {
95 - const value = Function(`"use strict"; return (${expr})`)();
96 - if (typeof value !== "number" || !Number.isFinite(value))
97 - return "";
99 - return Number.isInteger(value) ? String(value) : String(Math.round(value * 10000) / 10000);
100 - } catch (error) {
101 - return "";
102 - }
103 - }
105 - function rowVerb(provider, row) {
106 - if (row.verb)
107 - return String(row.verb);
109 - if (provider === "calculator")
110 - return "copy-result";
112 - if (provider === "action")
113 - return "run-action";
115 - if (provider === "app")
116 - return "launch-app";
118 - if (provider === "clipboard")
119 - return "copy-clipboard";
121 - if (provider === "window")
122 - return "focus-window";
124 - return "activate";
125 - }
127 - function rowIconRole(provider, row) {
128 - if (row.iconRole)
129 - return String(row.iconRole);
131 - if (provider === "calculator")
132 - return "calculator";
134 - if (provider === "action")
135 - return "shell-action";
137 - if (provider === "app")
138 - return "desktop-entry";
140 - if (provider === "clipboard")
141 - return "clipboard";
143 - if (provider === "window")
144 - return "niri-window";
146 - return "item";
147 - }
149 - function previewActionRows(row) {
150 - const provider = String(row.provider || "item");
151 - const primaryLabel = provider === "calculator" ? "Copy result" : (provider === "app" ? "Launch" : (provider === "window" ? "Focus" : "Run"));
152 - return [{
153 - "id": "primary",
154 - "label": primaryLabel,
155 - "iconRole": row.iconRole || provider,
156 - "verb": row.verb || "activate",
157 - "primaryAction": true,
158 - "keyboardReturnActivates": true
159 - }, {
160 - "id": "copy-title",
161 - "label": "Copy title",
162 - "iconRole": "clipboard",
163 - "verb": "copy-title",
164 - "primaryAction": false,
165 - "keyboardReturnActivates": false
166 - }, {
167 - "id": "copy-subtitle",
168 - "label": "Copy detail",
169 - "iconRole": "clipboard",
170 - "verb": "copy-subtitle",
171 - "primaryAction": false,
172 - "keyboardReturnActivates": false
173 - }];
174 - }
176 - function recordWheelSelection(before, after, deltaY) {
177 - const entry = {
178 - "kind": "wheel-select",
179 - "before": before,
180 - "after": after,
181 - "deltaY": deltaY
182 - };
183 - const rows = wheelTrace.slice(Math.max(0, wheelTrace.length - 15));
184 - rows.push(entry);
185 - wheelTrace = rows;
186 - lastInteraction = entry;
187 - return stateJson();
188 - }
190 - function providerCounts() {
191 - return {
192 - "app": apps.length,
193 - "action": actions.length,
194 - "clipboard": clipboardProviderRows("").length,
195 - "window": niriService ? (niriService.windows || []).length : 0,
196 - "calculator": 1
197 - };
198 - }
41 + // IPC serializer (launcherState). Telemetry essentials only — all narration
42 + // fields were removed with the launcher redesign.
200 43 function stateJson() {
201 44 return JSON.stringify({
202 - "backend": "Launcher.qml",
203 - "wheelTrace": wheelTrace,
204 45 "launchRecords": launchRecords,
205 46 "lastInteraction": lastInteraction,
206 - "realWheelSelection": lastInteraction.kind === "wheel-select" && lastInteraction.before !== lastInteraction.after,
207 - "launcherPanelContract": launcherPanelContract(),
208 47 "appCount": apps.length,
209 48 "appScanDone": appScanDone,
210 - "appScanError": appScanError,
211 - "desktopEntrySource": "xdg-data-dirs",
212 - "fakeApps": false,
213 - "providerCounts": providerCounts()
49 + "appScanError": appScanError
53 + // Telemetry-ONLY: records activations; does NOT feed scoring (ranking is a
54 + // pure function of query + static per-provider boost in launch.js).
217 55 function rememberActivation(record, executed) {
218 56 const entry = {
219 57 "kind": "activate",
333 171 const wanted = String(id);
334 172 for (let i = 0; i < actions.length; i++) {
335 173 if (actions[i].id === wanted)
336 - return shapeRow(actions[i], "action", 1500);
174 + return Launch.shapeRow(actions[i], "action", 1500);
339 177 for (let i = 0; i < apps.length; i++) {
340 178 if (apps[i].id === wanted || apps[i].desktopId === wanted)
341 - return shapeRow(Object.assign({
179 + return Launch.shapeRow(Object.assign({
342 180 "route": "desktop-entry"
343 181 }, apps[i]), "app", 1500);
379 217 return JSON.stringify(lastInteraction);
382 - function launcherPanelContract() {
383 - return {
384 - "source": "Nuguland launcher Content.qml AppList.qml ActionItem.qml plus Nuguland SearchResults.qml ResultPreview plus Nuguland LaunchContent.qml",
385 - "ownedBy": "PopoutHost.qml inline LauncherPanel",
386 - "fullLauncherSurface": true,
387 - "searchFieldDockedBottom": true,
388 - "singleResultList": true,
389 - "sidePreviewPanel": true,
390 - "keyboardNavigation": true,
391 - "providerChips": true,
392 - "serviceFedOnly": true,
393 - "noSettingsCenter": true,
394 - "resultParts": ["iconRole", "title", "subtitle", "verb", "tags"],
395 - "previewActions": ["primary", "copy-title", "copy-subtitle"]
396 - };
397 - }
399 - function launcherPreviewPanel(row) {
400 - if (!row)
401 - return {
402 - "source": "Nuguland SearchResults.qml ResultPreview plus Nuguland launcher Content.qml",
403 - "emptyState": true,
404 - "sidePanelWidth": 386,
405 - "actionRows": [],
406 - "keyboardReturnActivates": "primaryAction"
407 - };
409 - return {
410 - "source": "Nuguland SearchResults.qml ResultPreview plus Nuguland launcher Content.qml",
411 - "emptyState": false,
412 - "provider": row.provider,
413 - "title": row.title || row.id || row.provider,
414 - "subtitle": row.subtitle || row.provider,
415 - "iconRole": row.iconRole,
416 - "verb": row.verb,
417 - "preview": row.preview,
418 - "sidePanelWidth": 386,
419 - "selectedResultDrivesPreview": true,
420 - "primaryAction": row.verb,
421 - "keyboardReturnActivates": "primaryAction",
422 - "settingsBacked": false,
423 - "actionRows": previewActionRows(row)
424 - };
425 - }
427 - function shapeRow(row, provider, score) {
428 - const next = Object.assign({
429 - }, row);
430 - const route = next.route || provider;
431 - next.provider = provider;
432 - next.iconRole = rowIconRole(provider, next);
433 - next.verb = rowVerb(provider, next);
434 - next.subtitle = next.subtitle || provider;
435 - next.tags = next.tags || [provider, route, next.verb];
436 - next.preview = next.preview || {
437 - "provider": provider,
438 - "title": next.title || next.id || provider,
439 - "subtitle": next.subtitle,
440 - "route": route
441 - };
442 - next.score = score;
443 - next.keyboard = true;
444 - return next;
445 - }
447 - function pushResult(results, row, provider, score) {
448 - if (score < 0)
449 - return ;
451 - results.push(shapeRow(row, provider, score));
452 - }
454 - function scrollableListChrome(rowCount, selectedIndex) {
455 - const count = Math.max(0, Number(rowCount));
456 - const selected = Math.max(0, Number(selectedIndex));
457 - const scrollable = count > 4;
458 - return {
459 - "source": "Nuguland ScrollEdgeFade.qml plus Nuguland FlickMonitor.qml",
460 - "scrollEdgeFade": true,
461 - "topEdgeFade": scrollable && selected > 0,
462 - "bottomEdgeFade": scrollable && selected < count - 1,
463 - "fadeSize": 32,
464 - "scrollHint": {
465 - "visible": scrollable,
466 - "icon": "keyboard_arrow_up_down",
467 - "side": "right",
468 - "tooltip": "scroll results"
469 - },
470 - "flickMonitor": {
471 - "enabled": true,
472 - "velocitySamples": 6,
473 - "events": ["pressed", "positionChanged", "released"]
474 - }
475 - };
476 - }
220 + // Clipboard rows come from the clipboard service as a JSON string; the service
221 + // does its own query filtering. Empty list on missing service / parse failure.
478 222 function clipboardProviderRows(query) {
479 223 if (!clipboardService)
480 224 return [];
489 - function windowRows(query, boost, results) {
490 - const windows = niriService ? (niriService.windows || []) : [];
491 - for (let i = 0; i < windows.length; i++) {
492 - const win = windows[i];
493 - const title = win.title || win.app_id || win.appId || `window ${win.id}`;
494 - const score = fuzzyScore(query, title, boost);
495 - pushResult(results, {
496 - "id": String(win.id),
497 - "title": title,
498 - "subtitle": win.app_id || win.appId || "window",
499 - "route": "niri-window",
500 - "windowId": win.id
501 - }, "window", score);
502 - }
503 - }
505 - // Map Quickshell DesktopEntry objects to the row shape the launcher consumes.
506 - // Exec field codes (%f, %u, …) are already stripped from `command` by Quickshell.
507 - function buildApps(entries) {
508 - const list = entries || [];
509 - const rows = [];
510 - for (let i = 0; i < list.length; i++) {
511 - const e = list[i];
512 - if (!e || !e.name)
513 - continue;
515 - const id = String(e.id || e.name);
516 - const argv = [];
517 - const command = e.command || [];
518 - for (let j = 0; j < command.length; j++) argv.push(String(command[j]));
519 - rows.push({
520 - "id": "app:" + id,
521 - "title": String(e.name),
522 - "subtitle": String(e.comment || e.genericName || id),
523 - "desktopId": id,
524 - // uwsm resolves the desktop id (with .desktop suffix) for proper
525 - // startup/env integration; argv is the fallback launch path.
526 - "desktopPath": id + ".desktop",
527 - "exec": String(e.execString || ""),
528 - "execArgv": argv,
529 - "icon": String(e.icon || ""),
530 - "terminal": !!e.runInTerminal,
531 - "route": "desktop-entry"
532 - });
533 - }
534 - rows.sort((a, b) => String(a.title).localeCompare(String(b.title)));
535 - return rows;
536 - }
233 + // Thin wrapper over launch.rankResults: gather the live source bundles (apps,
234 + // actions, niri windows, clipboard rows) and delegate all parsing/scoring/sort
235 + // to the pure ranking core. Returns {query, providerIntent, selectedIndex, results}.
538 236 function search(raw) {
539 - const intent = prefixIntent(raw);
540 - const query = intent.query;
541 - const results = [];
542 - const calc = calculatorValue(query);
543 - if ((intent.provider === "calculator" || intent.provider === "all") && calc.length > 0)
544 - pushResult(results, {
545 - "id": `calc:${query}`,
546 - "title": calc,
547 - "subtitle": query,
548 - "value": calc,
549 - "route": "calculator"
550 - }, "calculator", intent.provider === "calculator" ? 2000 : 600);
552 - if (intent.provider === "action" || intent.provider === "all") {
553 - for (let i = 0; i < actions.length; i++) pushResult(results, actions[i], "action", fuzzyScore(query, actions[i].title, intent.provider === "action" ? 1500 : 300))
554 - }
555 - if (intent.provider === "app" || intent.provider === "all") {
556 - for (let i = 0; i < apps.length; i++) pushResult(results, Object.assign({
557 - "route": "desktop-entry"
558 - }, apps[i]), "app", fuzzyScore(query, apps[i].title, 900))
559 - }
560 - if (intent.provider === "clipboard" || intent.provider === "all") {
561 - const clipRows = clipboardProviderRows(query);
562 - for (let i = 0; i < clipRows.length; i++) pushResult(results, Object.assign({
563 - "route": "clipboard",
564 - "backend": "Clipboard.qml"
565 - }, clipRows[i]), "clipboard", fuzzyScore(query, clipRows[i].title, intent.provider === "clipboard" ? 1400 : 200))
566 - }
567 - windowRows(query, intent.provider === "window" ? 1300 : 250, results);
568 - results.sort((a, b) => {
569 - return b.score - a.score || String(a.title).localeCompare(String(b.title));
237 + const intent = Launch.prefixIntent(raw);
238 + const windows = niriService ? (niriService.windows || []) : [];
239 + const clipRows = (intent.intent === "clipboard" || intent.intent === "all") ? clipboardProviderRows(intent.query) : [];
240 + const ranked = Launch.rankResults(raw, {
241 + "apps": apps,
242 + "actions": actions,
243 + "windows": windows,
244 + "clipRows": clipRows
571 - const selectedIndex = results.length > 0 ? 0 : -1;
572 - const selectedResult = selectedIndex >= 0 ? results[selectedIndex] : null;
573 246 return JSON.stringify({
574 247 "query": raw,
575 - "providerIntent": intent.provider,
576 - "selectedIndex": selectedIndex,
577 - "singleScoredList": true,
578 - "keyboardFirst": true,
579 - "noPluginCommands": true,
580 - "scrollableListChrome": scrollableListChrome(results.length, selectedIndex),
581 - "launcherPanelContract": launcherPanelContract(),
582 - "launcherPreviewPanel": launcherPreviewPanel(selectedResult),
583 - "results": results
248 + "providerIntent": ranked.providerIntent,
249 + "selectedIndex": ranked.selectedIndex,
250 + "results": ranked.results
251 + });
254 + // Gate test: exercises the pure launch.js logic through QML so a stale qmlcache
255 + // or a broken import surfaces as failing cases. Mirrors Clipboard.qml selfTest.
256 + function selfTest() {
257 + const cases = [];
258 + function ok(name, cond) {
259 + cases.push({
260 + "name": name,
261 + "pass": !!cond
262 + });
264 + try {
265 + ok("prefix-calculator", Launch.prefixIntent("=2+2").intent === "calculator");
266 + ok("prefix-action", Launch.prefixIntent("> over").intent === "action");
267 + ok("prefix-clipboard", Launch.prefixIntent("clip foo").intent === "clipboard" && Launch.prefixIntent("clip foo").query === "foo");
268 + ok("prefix-all", Launch.prefixIntent("firefox").intent === "all");
269 + const exact = Launch.fuzzyScore("firefox", "firefox", 0);
270 + const prefix = Launch.fuzzyScore("fire", "firefox", 0);
271 + const subseq = Launch.fuzzyScore("frfx", "firefox", 0);
272 + ok("fuzzy-order", exact > prefix && prefix > subseq && subseq >= 0);
273 + ok("fuzzy-miss", Launch.fuzzyScore("zzz", "firefox", 0) === -1);
274 + ok("calc-eval", Launch.calculatorValue("2+2") === "4");
275 + ok("calc-reject-call", Launch.calculatorValue("a()") === null);
276 + ok("calc-reject-assign", Launch.calculatorValue("x=1") === null);
277 + const rApp = Launch.rankResults("firefox", {
278 + "apps": [{
279 + "title": "Files",
280 + "id": "app:files"
281 + }, {
282 + "title": "Firefox",
283 + "id": "app:ff",
284 + "icon": "firefox"
285 + }]
286 + });
287 + ok("rank-exact-first", rApp.selectedIndex === 0 && rApp.results[0].title === "Firefox");
288 + ok("rank-keeps-icon", rApp.results[0].icon === "firefox");
289 + const rAction = Launch.rankResults("> over", {
290 + "actions": [{
291 + "title": "Overview",
292 + "id": "overview"
293 + }],
294 + "apps": [{
295 + "title": "Overx",
296 + "id": "app:x"
297 + }]
298 + });
299 + ok("rank-action-intent", rAction.providerIntent === "action" && rAction.results[0].provider === "action");
300 + const rClip = Launch.rankResults("clip ", {
301 + "clipRows": [{
302 + "title": "snippet",
303 + "id": "clip-1"
304 + }]
305 + });
306 + ok("rank-clip-intent", rClip.providerIntent === "clipboard" && rClip.results[0].provider === "clipboard");
307 + const rCalc = Launch.rankResults("=2*21", {});
308 + ok("rank-calc-row", rCalc.calc !== null && rCalc.calc.value === "42" && rCalc.results[0].title === "42");
309 + } catch (error) {
310 + ok("threw:" + error, false);
312 + const fail = cases.filter((c) => {
313 + return !c.pass;
314 + }).length;
315 + return JSON.stringify({
316 + "pass": cases.length - fail,
317 + "fail": fail,
318 + "cases": cases

quickshell/nuguland/PopoutHost.qml

Modified
1 1 import QtQuick
2 2 import Quickshell
3 3 import Quickshell.Wayland
4 +import Quickshell.Widgets
4 5 import "Util.js" as Util
5 6 import "caldav.js" as Ical
6 7 import "sysinfo.js" as Sys
1578 1579 property var state: launcherService ? Util.parseJson(launcherService.search(query), {
1579 1580 "results": [],
1580 1581 "selectedIndex": -1,
1581 - "launcherPanelContract": {
1582 - },
1583 - "launcherPreviewPanel": {
1584 - },
1585 - "scrollableListChrome": {
1582 + "providerIntent": "all",
1583 + "query": ""
1587 1584 }) : ({
1588 1585 "results": [],
1589 1586 "selectedIndex": -1,
1590 - "launcherPanelContract": {
1591 - },
1592 - "launcherPreviewPanel": {
1593 - },
1594 - "scrollableListChrome": {
1587 + "providerIntent": "all",
1588 + "query": ""
1597 1590 readonly property var results: state.results || []
1598 - readonly property var selected: results.length > 0 ? results[Math.max(0, Math.min(results.length - 1, state.selectedIndex || 0))] : ({
1599 - })
1600 - readonly property var preview: state.launcherPreviewPanel || ({
1601 - "actionRows": []
1602 - })
1603 - readonly property var panel: state.launcherPanelContract || ({
1604 - })
1591 + // fixed row geometry, shared so the programmatic scroll stride can't drift
1592 + readonly property int rowHeight: 54
1593 + readonly property int rowSpacing: 6
1594 + readonly property int rowStride: rowHeight + rowSpacing
1607 1597 function refresh() {
1618 1608 function select(index) {
1609 + if (results.length === 0)
1610 + return ;
1619 1612 const i = Math.max(0, Math.min(results.length - 1, Number(index)));
1620 1613 const next = Object.assign({
1621 1614 }, state);
1622 1615 next.selectedIndex = i;
1623 - next.scrollableListChrome = launcherService ? Util.parseJson(launcherService.scrollableListChrome(results.length, i), next.scrollableListChrome || {
1624 - }) : next.scrollableListChrome;
1625 - next.launcherPreviewPanel = launcherService ? Util.parseJson(launcherService.launcherPreviewPanel(results[i]), next.launcherPreviewPanel || {
1626 - }) : next.launcherPreviewPanel;
1627 1616 state = next;
1617 + // keep the chosen row inside the non-interactive Flickable's viewport
1618 + const top = i * rowStride;
1619 + const bottom = top + rowHeight;
1620 + if (top < resultsFlick.contentY)
1621 + resultsFlick.contentY = top;
1622 + else if (bottom > resultsFlick.contentY + resultsFlick.height)
1623 + resultsFlick.contentY = bottom - resultsFlick.height;
1630 1626 function wheelSelect(deltaY) {
1632 1628 return ;
1634 1630 const current = Math.max(0, Math.min(results.length - 1, Number(state.selectedIndex || 0)));
1635 - const direction = current <= 0 ? 1 : (Number(deltaY) >= 0 ? 1 : -1);
1631 + // wheel up/away (deltaY >= 0) moves selection up, matching the Up arrow.
1632 + const direction = Number(deltaY) >= 0 ? -1 : 1;
1636 1633 const next = Math.max(0, Math.min(results.length - 1, current + direction));
1637 1634 select(next);
1638 - if (launcherService && typeof launcherService.recordWheelSelection === "function")
1639 - launcherService.recordWheelSelection(current, next, deltaY);
1643 1637 function providerColor(provider) {
1673 - Row {
1667 + // Full-width scrollable result list. The Flickable is non-interactive:
1668 + // the wheel is owned by the root WheelHandler (-> wheelSelect), and
1669 + // select() drives contentY programmatically to keep the chosen row in view.
1670 + Flickable {
1671 + id: resultsFlick
1672 + objectName: "launcherResultList"
1674 1674 width: parent.width
1675 - spacing: 10
1675 + // fill the popout budget minus the docked search field (42) + hint
1676 + // (~18) + the two 10px Column gaps; clamped so it never collapses.
1677 + height: Math.max(120, (root.parent ? root.parent.height : 460) - 84)
1678 + contentHeight: resultColumn.implicitHeight
1679 + interactive: false
1680 + clip: true
1681 + boundsBehavior: Flickable.StopAtBounds
1683 + Behavior on contentY {
1684 + NumberAnimation {
1685 + duration: root.theme && root.theme.lowPowerMode ? 0 : 140
1686 + easing.type: Easing.OutCubic
1677 1690 Column {
1678 - objectName: "singleResultList"
1679 - width: Math.max(220, parent.width - 396)
1680 - spacing: 6
1691 + id: resultColumn
1682 - Row {
1683 - objectName: "providerChips"
1684 - width: parent.width
1685 - spacing: 5
1687 - Repeater {
1688 - model: ["all", "app", "action", "clipboard", "calculator", "window"]
1690 - delegate: Rectangle {
1691 - id: chip
1693 - required property string modelData
1695 - width: Math.max(44, label.implicitWidth + 16)
1696 - height: 24
1697 - radius: 12
1698 - color: root.theme ? root.theme.withAlpha(root.state.providerIntent === chip.modelData ? root.theme.ui.focus : root.theme.ui.minor, root.state.providerIntent === chip.modelData ? 0.18 : 0.08) : "transparent"
1699 - border.width: 0
1700 - border.color: root.theme ? (root.state.providerIntent === chip.modelData ? root.theme.ui.focus : root.theme.ui.minor) : "transparent"
1702 - NuguText {
1703 - id: label
1705 - anchors.centerIn: parent
1706 - theme: root.theme
1707 - variant: "meta"
1708 - selected: root.state.providerIntent === chip.modelData
1709 - text: chip.modelData
1693 + width: resultsFlick.width
1694 + spacing: root.rowSpacing
1718 1696 Repeater {
1719 - model: root.results.slice(0, 7)
1697 + model: root.results.slice(0, 60)
1721 1699 delegate: Rectangle {
1722 - id: row
1700 + id: rrow
1724 1702 required property int index
1725 1703 required property var modelData
1704 + readonly property bool isSelected: index === (root.state.selectedIndex || 0)
1705 + readonly property bool isCalc: modelData.provider === "calculator"
1706 + readonly property color tint: root.providerColor(modelData.provider)
1727 1708 width: parent.width
1728 - height: 44
1709 + height: root.rowHeight
1729 1710 radius: 12
1730 - color: root.theme ? root.theme.withAlpha(index === root.state.selectedIndex ? root.theme.ui.focus : root.providerColor(row.modelData.provider), index === root.state.selectedIndex ? 0.18 : 0.08) : "transparent"
1731 - border.width: 0
1732 - border.color: index === root.state.selectedIndex && root.theme ? root.theme.ui.focus : root.providerColor(row.modelData.provider)
1711 + // solid dark card — the popup frame is light, so a translucent
1712 + // tint washes out (white bleeds through). Provider identity is
1713 + // carried by the left accent bar + border; selection by focus.
1714 + color: root.theme ? root.theme.withAlpha(root.theme.ui.backdrop, rrow.isSelected ? 0.82 : 0.55) : "transparent"
1715 + border.width: rrow.isSelected ? 2 : 1
1716 + border.color: root.theme ? (rrow.isSelected ? root.theme.ui.focus : root.theme.withAlpha(rrow.tint, 0.45)) : "transparent"
1718 + // provider-colored left accent bar (identity at a glance)
1734 1719 Rectangle {
1735 1720 anchors.left: parent.left
1736 - anchors.leftMargin: 8
1737 - anchors.verticalCenter: parent.verticalCenter
1738 - width: 28
1739 - height: 28
1740 - radius: 9
1741 - color: root.theme ? root.theme.withAlpha(root.providerColor(row.modelData.provider), 0.18) : "transparent"
1742 - border.width: 0
1743 - border.color: root.providerColor(row.modelData.provider)
1721 + anchors.top: parent.top
1722 + anchors.bottom: parent.bottom
1723 + anchors.margins: 2
1724 + width: 3
1725 + radius: 2
1726 + color: rrow.tint
1727 + opacity: rrow.isSelected ? 1 : 0.7
1745 - NuguText {
1730 + // leading 32px icon slot: real themed app icon, else the
1731 + // provider Nerd Font glyph. Glyph also covers the app
1732 + // fallback when the icon name fails to resolve (status
1733 + // never reaches Image.Ready -> glyph stays visible).
1734 + Item {
1735 + id: iconSlot
1737 + anchors.left: parent.left
1738 + anchors.leftMargin: 10
1739 + anchors.verticalCenter: parent.verticalCenter
1740 + width: 32
1741 + height: 32
1743 + IconImage {
1744 + id: appIcon
1746 + anchors.fill: parent
1747 + visible: rrow.modelData.provider === "app" && appIcon.status === Image.Ready
1748 + source: (rrow.modelData.provider === "app" && String(rrow.modelData.icon || "").length > 0) ? Quickshell.iconPath(String(rrow.modelData.icon), true) : ""
1751 + Text {
1746 1752 anchors.centerIn: parent
1747 - theme: root.theme
1748 - variant: "meta"
1749 - text: String(row.modelData.iconRole || "?").slice(0, 2)
1753 + visible: !appIcon.visible
1754 + text: String(rrow.modelData.glyph || "")
1755 + font.family: "Symbols Nerd Font Mono"
1756 + font.pixelSize: 18
1757 + color: rrow.tint
1754 - NuguText {
1755 - anchors.left: parent.left
1756 - anchors.leftMargin: 44
1762 + // calculator row: expression small, value large + mono
1763 + Column {
1764 + visible: rrow.isCalc
1765 + anchors.left: iconSlot.right
1766 + anchors.leftMargin: 12
1757 1767 anchors.right: parent.right
1758 - anchors.rightMargin: 8
1759 - anchors.top: parent.top
1760 - anchors.topMargin: 6
1761 - theme: root.theme
1762 - selected: index === root.state.selectedIndex
1763 - text: row.modelData.title || row.modelData.id || "result"
1764 - elide: Text.ElideRight
1768 + anchors.rightMargin: 12
1769 + anchors.verticalCenter: parent.verticalCenter
1770 + spacing: 1
1772 + NuguText {
1773 + theme: root.theme
1774 + variant: "meta"
1775 + text: rrow.modelData.subtitle || rrow.modelData.id || "expression"
1776 + width: parent.width
1777 + opacity: 0.8
1780 + Text {
1781 + width: parent.width
1782 + text: String(rrow.modelData.value || rrow.modelData.title || "0")
1783 + color: rrow.isSelected && root.theme ? root.theme.content.backdrop : (root.theme ? root.theme.content.normal : "white")
1784 + font.family: "IBM Plex Mono"
1785 + font.pixelSize: 22
1786 + font.bold: true
1787 + elide: Text.ElideRight
1767 - NuguText {
1768 - anchors.left: parent.left
1769 - anchors.leftMargin: 44
1792 + // standard row: title + muted `verb · subtitle` meta
1793 + Column {
1794 + visible: !rrow.isCalc
1795 + anchors.left: iconSlot.right
1796 + anchors.leftMargin: 12
1770 1797 anchors.right: parent.right
1771 - anchors.rightMargin: 8
1772 - anchors.bottom: parent.bottom
1773 - anchors.bottomMargin: 5
1774 - theme: root.theme
1775 - variant: "meta"
1776 - text: `${row.modelData.verb || "activate"} · ${row.modelData.subtitle || row.modelData.provider}`
1777 - elide: Text.ElideRight
1778 - opacity: 0.78
1798 + anchors.rightMargin: 12
1799 + anchors.verticalCenter: parent.verticalCenter
1800 + spacing: 2
1802 + NuguText {
1803 + theme: root.theme
1804 + selected: rrow.isSelected
1805 + text: rrow.modelData.title || rrow.modelData.id || "result"
1806 + width: parent.width
1809 + NuguText {
1810 + theme: root.theme
1811 + variant: "meta"
1812 + text: `${rrow.modelData.verb || "activate"} · ${rrow.modelData.subtitle || rrow.modelData.provider}`
1813 + width: parent.width
1814 + opacity: 0.78
1781 1819 MouseArea {
1782 1820 anchors.fill: parent
1783 - onClicked: root.select(index)
1821 + onClicked: root.select(rrow.index)
1784 1822 onWheel: (wheel) => {
1785 1823 wheel.accepted = true;
1786 1824 root.wheelSelect(wheel.angleDelta.y);
1796 - Rectangle {
1797 - objectName: "sidePreviewPanel"
1798 - width: 386
1799 - height: 266
1800 - radius: 15
1801 - color: root.theme ? root.theme.withAlpha(root.theme.ui.backdrop, 0.9) : "transparent"
1802 - border.width: 0
1803 - border.color: root.theme ? root.theme.ui.accent : "transparent"
1805 - Column {
1806 - anchors.fill: parent
1807 - anchors.margins: 12
1808 - spacing: 8
1810 - Rectangle {
1811 - width: 58
1812 - height: 58
1813 - radius: 18
1814 - color: root.theme ? root.theme.withAlpha(root.providerColor(root.preview.provider || root.selected.provider), 0.2) : "transparent"
1815 - border.width: 0
1816 - border.color: root.providerColor(root.preview.provider || root.selected.provider)
1818 - NuguText {
1819 - anchors.centerIn: parent
1820 - theme: root.theme
1821 - variant: "title"
1822 - text: String(root.preview.iconRole || root.selected.iconRole || "?").slice(0, 2)
1827 - NuguText {
1828 - theme: root.theme
1829 - variant: "title"
1830 - text: root.preview.title || "launcher"
1831 - width: parent.width
1832 - elide: Text.ElideRight
1835 - NuguText {
1836 - theme: root.theme
1837 - text: root.preview.subtitle || "type to search"
1838 - width: parent.width
1839 - elide: Text.ElideRight
1842 - Rectangle {
1843 - width: parent.width
1844 - height: 1
1845 - color: root.theme ? root.theme.ui.accent : "transparent"
1848 - Repeater {
1849 - model: root.preview.actionRows || []
1851 - delegate: Rectangle {
1852 - required property var modelData
1854 - width: parent.width
1855 - height: 30
1856 - radius: 9
1857 - color: root.theme ? root.theme.withAlpha(modelData.primaryAction ? root.theme.ui.focus : root.theme.ui.minor, modelData.primaryAction ? 0.16 : 0.08) : "transparent"
1858 - border.width: 0
1859 - border.color: root.theme ? (modelData.primaryAction ? root.theme.ui.focus : root.theme.ui.minor) : "transparent"
1861 - NuguText {
1862 - anchors.left: parent.left
1863 - anchors.leftMargin: 8
1864 - anchors.verticalCenter: parent.verticalCenter
1865 - theme: root.theme
1866 - variant: "meta"
1867 - selected: !!modelData.primaryAction
1868 - text: `${modelData.label} · ${modelData.verb}`
1869 - width: parent.width - 16
1870 - elide: Text.ElideRight
1883 1836 Rectangle {
1932 1885 objectName: "keyboardNavigation"
1933 1886 theme: root.theme
1934 1887 variant: "meta"
1935 - text: `↑↓ select · Enter ${root.preview.keyboardReturnActivates || "primaryAction"} · ${(root.state.scrollableListChrome && root.state.scrollableListChrome.scrollHint && root.state.scrollableListChrome.scrollHint.visible) ? "scroll" : "fit"}`
1888 + text: "↑↓ select · Enter activate"
1936 1889 width: parent.width
1937 1890 elide: Text.ElideRight

quickshell/nuguland/launch.js

Added
new file mode 100644
1 +// launch.js — pure launcher logic: normalize, prefix intents, subsequence fuzzy
2 +// scoring, calculator eval, row shaping, app mapping, and the ranking core.
3 +// NO I/O. Dual-mode: node `require` (tests) + QML import. Same pattern as clip.js.
5 +// --- Provider Nerd Font glyphs (FA PUA, render in "Symbols Nerd Font Mono").
6 +// Kept as \uXXXX escapes. App glyph is the FALLBACK shown only when a real
7 +// desktop icon fails to resolve. ---
8 +var GLYPH_APP = "\uF135"; // rocket (app fallback)
9 +var GLYPH_ACTION = "\uF013"; // gear
10 +var GLYPH_CALCULATOR = "\uF1EC"; // calculator
11 +var GLYPH_CLIPBOARD = "\uF0EA"; // clipboard
12 +var GLYPH_WINDOW = "\uF2D0"; // window
14 +// --- lowercase + trim, null-safe (search/compare key) ---
15 +function normalize(text) {
16 + return String(text == null ? "" : text).trim().toLowerCase();
19 +// --- prefix routing: `=`->calculator, `>`->action, `clip `->clipboard, else all.
20 +// Strips the prefix into `query`. Returns {intent, query}. ---
21 +function prefixIntent(raw) {
22 + var text = String(raw == null ? "" : raw).trim();
23 + if (text.indexOf("=") === 0)
24 + return { intent: "calculator", query: text.slice(1).trim() };
25 + if (text.indexOf(">") === 0)
26 + return { intent: "action", query: text.slice(1).trim() };
27 + // `.trim()` above strips the trailing space, so match "clip" exactly or the
28 + // "clip <query>" form. (IPC also trims the arg, so a bare "clip " arrives as "clip".)
29 + var low = text.toLowerCase();
30 + if (low === "clip" || low.indexOf("clip ") === 0)
31 + return { intent: "clipboard", query: text.slice(4).trim() };
32 + return { intent: "all", query: text };
35 +// --- a char is part of a word (vs. a boundary separator: space, -, _, ., /, :) ---
36 +function isWordChar(ch) {
37 + return /[a-z0-9]/.test(ch);
40 +// --- greedy left-to-right subsequence match of q against t (both normalized).
41 +// Returns {matched, firstIndex, contiguous, boundaryHits}. `contiguous` counts
42 +// adjacent matched positions; `boundaryHits` counts matches at a word start. ---
43 +function subsequenceMatch(q, t) {
44 + var qi = 0;
45 + var positions = [];
46 + for (var ti = 0; ti < t.length && qi < q.length; ti++) {
47 + if (t.charAt(ti) === q.charAt(qi)) {
48 + positions.push(ti);
49 + qi++;
50 + }
51 + }
52 + if (qi < q.length)
53 + return { matched: false, firstIndex: -1, contiguous: 0, boundaryHits: 0 };
54 + var contiguous = 0;
55 + var boundaryHits = 0;
56 + for (var i = 0; i < positions.length; i++) {
57 + var p = positions[i];
58 + if (i > 0 && positions[i] === positions[i - 1] + 1)
59 + contiguous++;
60 + if (p === 0 || !isWordChar(t.charAt(p - 1)))
61 + boundaryHits++;
62 + }
63 + return {
64 + matched: true,
65 + firstIndex: positions[0],
66 + contiguous: contiguous,
67 + boundaryHits: boundaryHits
68 + };
71 +// --- subsequence-aware ranking. Bands stay separated so categories can't cross:
72 +// exact +1000, prefix +800-len, word-boundary subsequence (base 600), loose
73 +// subsequence (base 350), substring fallback, else -1. `boost` is a per-provider
74 +// weight; empty query returns boost so every row lists. ---
75 +function fuzzyScore(query, title, boost) {
76 + var b = Number(boost) || 0;
77 + var q = normalize(query);
78 + var t = normalize(title);
79 + if (q.length === 0)
80 + return b;
81 + if (t === q)
82 + return b + 1000;
83 + if (t.indexOf(q) === 0)
84 + return b + 800 - t.length;
86 + var m = subsequenceMatch(q, t);
87 + if (m.matched) {
88 + // every matched char at a word start => acronym-grade (high band)
89 + var allBoundary = m.boundaryHits === q.length;
90 + var base = allBoundary ? 600 : 350;
91 + var bonus = m.contiguous * 10 + m.boundaryHits * 15 - m.firstIndex;
92 + return b + base + bonus;
93 + }
94 + // substring fallback (any contiguous substring is already a subsequence, so
95 + // this is effectively unreachable — kept to document intent).
96 + var idx = t.indexOf(q);
97 + if (idx > 0)
98 + return b + 300 - idx;
99 + return -1;
102 +// --- regex-guarded arithmetic eval. Returns a formatted string, or null on
103 +// guard failure / non-finite / non-number. Integers print plain; otherwise
104 +// rounded to 4 decimals. ---
105 +function calculatorValue(expression) {
106 + var expr = String(expression == null ? "" : expression).replace(/\s+/g, "");
107 + if (expr.length === 0 || !/^[0-9.+\-*/()%]+$/.test(expr))
108 + return null;
109 + try {
110 + var value = Function('"use strict"; return (' + expr + ')')();
111 + if (typeof value !== "number" || !isFinite(value))
112 + return null;
113 + return value === Math.floor(value)
114 + ? String(value)
115 + : String(Math.round(value * 10000) / 10000);
116 + } catch (error) {
117 + return null;
121 +// --- primary verb per provider (row may override via row.verb) ---
122 +function rowVerb(provider, row) {
123 + if (row && row.verb)
124 + return String(row.verb);
125 + if (provider === "calculator") return "copy-result";
126 + if (provider === "action") return "run-action";
127 + if (provider === "app") return "launch-app";
128 + if (provider === "clipboard") return "copy-clipboard";
129 + if (provider === "window") return "focus-window";
130 + return "activate";
133 +// --- semantic icon role per provider (row may override via row.iconRole) ---
134 +function rowIconRole(provider, row) {
135 + if (row && row.iconRole)
136 + return String(row.iconRole);
137 + if (provider === "calculator") return "calculator";
138 + if (provider === "action") return "shell-action";
139 + if (provider === "app") return "desktop-entry";
140 + if (provider === "clipboard") return "clipboard";
141 + if (provider === "window") return "niri-window";
142 + return "item";
145 +// --- Nerd Font fallback glyph per provider (apps fall back to rocket) ---
146 +function providerGlyph(provider) {
147 + if (provider === "action") return GLYPH_ACTION;
148 + if (provider === "calculator") return GLYPH_CALCULATOR;
149 + if (provider === "clipboard") return GLYPH_CLIPBOARD;
150 + if (provider === "window") return GLYPH_WINDOW;
151 + return GLYPH_APP;
154 +// --- clone + enrich a row for the result list. Preserves `icon` (desktop icon
155 +// name) for apps so the view can render the real themed image. ---
156 +function shapeRow(row, provider, score) {
157 + var next = Object.assign({}, row || {});
158 + next.provider = provider;
159 + next.iconRole = rowIconRole(provider, next);
160 + next.verb = rowVerb(provider, next);
161 + next.glyph = providerGlyph(provider);
162 + next.subtitle = next.subtitle || provider;
163 + next.score = score;
164 + next.keyboard = true;
165 + return next;
168 +// --- filter (score < 0 drops) + shape into the results list ---
169 +function pushResult(results, row, provider, score) {
170 + if (score < 0)
171 + return;
172 + results.push(shapeRow(row, provider, score));
175 +// --- Map Quickshell DesktopEntry objects to launcher rows, sorted by title.
176 +// Exec field codes (%f, %u, …) are already stripped from `command` by Quickshell.
177 +// Keeps `icon` (desktop icon name) for real themed-icon rendering. ---
178 +function buildApps(entries) {
179 + var list = entries || [];
180 + var rows = [];
181 + for (var i = 0; i < list.length; i++) {
182 + var e = list[i];
183 + if (!e || !e.name)
184 + continue;
185 + var id = String(e.id || e.name);
186 + var argv = [];
187 + var command = e.command || [];
188 + for (var j = 0; j < command.length; j++) argv.push(String(command[j]));
189 + rows.push({
190 + id: "app:" + id,
191 + title: String(e.name),
192 + subtitle: String(e.comment || e.genericName || id),
193 + desktopId: id,
194 + // uwsm resolves the desktop id (with .desktop suffix) for proper
195 + // startup/env integration; argv is the fallback launch path.
196 + desktopPath: id + ".desktop",
197 + exec: String(e.execString || ""),
198 + execArgv: argv,
199 + icon: String(e.icon || ""),
200 + terminal: !!e.runInTerminal,
201 + route: "desktop-entry"
202 + });
204 + rows.sort(function (a, b) {
205 + return String(a.title).localeCompare(String(b.title));
206 + });
207 + return rows;
210 +// --- the pure ranking core. Takes the already-gathered source bundles (no I/O)
211 +// and returns {results, selectedIndex, providerIntent, calc}. Applies prefix
212 +// intent, scores each provider, filters non-matches, sorts by score then title. ---
213 +function rankResults(rawQuery, sources) {
214 + var src = sources || {};
215 + var apps = src.apps || [];
216 + var actions = src.actions || [];
217 + var windows = src.windows || [];
218 + var clipRows = src.clipRows || [];
220 + var intent = prefixIntent(rawQuery);
221 + var provider = intent.intent;
222 + var query = intent.query;
223 + var results = [];
225 + var calcValue = calculatorValue(query);
226 + var calc = null;
227 + if ((provider === "calculator" || provider === "all") && calcValue !== null) {
228 + calc = {
229 + id: "calc:" + query,
230 + title: calcValue,
231 + subtitle: query,
232 + value: calcValue,
233 + route: "calculator"
234 + };
235 + pushResult(results, calc, "calculator", provider === "calculator" ? 2000 : 600);
238 + if (provider === "action" || provider === "all") {
239 + for (var a = 0; a < actions.length; a++)
240 + pushResult(results, actions[a], "action",
241 + fuzzyScore(query, actions[a].title, provider === "action" ? 1500 : 300));
244 + if (provider === "app" || provider === "all") {
245 + for (var p = 0; p < apps.length; p++)
246 + pushResult(results, Object.assign({ route: "desktop-entry" }, apps[p]),
247 + "app", fuzzyScore(query, apps[p].title, 900));
250 + if (provider === "clipboard" || provider === "all") {
251 + for (var c = 0; c < clipRows.length; c++)
252 + pushResult(results, Object.assign({ route: "clipboard" }, clipRows[c]),
253 + "clipboard", fuzzyScore(query, clipRows[c].title, provider === "clipboard" ? 1400 : 200));
256 + // Windows have no prefix intent, so they list only in `all` (or an explicit
257 + // `window` intent, kept for forward-compat). This intentionally differs from
258 + // the old search() which added windows under every intent.
259 + if (provider === "all" || provider === "window") {
260 + for (var w = 0; w < windows.length; w++) {
261 + var win = windows[w];
262 + var title = win.title || win.app_id || win.appId || ("window " + win.id);
263 + pushResult(results, {
264 + id: String(win.id),
265 + title: title,
266 + subtitle: win.app_id || win.appId || "window",
267 + route: "niri-window",
268 + windowId: win.id
269 + }, "window", fuzzyScore(query, title, provider === "window" ? 1300 : 250));
273 + results.sort(function (x, y) {
274 + return y.score - x.score || String(x.title).localeCompare(String(y.title));
275 + });
277 + return {
278 + results: results,
279 + selectedIndex: results.length > 0 ? 0 : -1,
280 + providerIntent: provider,
281 + calc: calc
282 + };
285 +if (typeof module !== 'undefined' && module.exports) {
286 + module.exports = { normalize: normalize, prefixIntent: prefixIntent,
287 + subsequenceMatch: subsequenceMatch, fuzzyScore: fuzzyScore,
288 + calculatorValue: calculatorValue, rowVerb: rowVerb,
289 + rowIconRole: rowIconRole, providerGlyph: providerGlyph,
290 + shapeRow: shapeRow, pushResult: pushResult, buildApps: buildApps,
291 + rankResults: rankResults };

quickshell/nuguland/launch.test.js

Added
new file mode 100644
1 +const assert = require('assert');
2 +const L = require('./launch.js');
4 +// --- prefixIntent: each prefix routes + strips, returns {intent, query} ---
5 +assert.deepStrictEqual(L.prefixIntent('=2+2'), { intent: 'calculator', query: '2+2' });
6 +assert.deepStrictEqual(L.prefixIntent('>lock'), { intent: 'action', query: 'lock' });
7 +assert.deepStrictEqual(L.prefixIntent('clip foo'), { intent: 'clipboard', query: 'foo' });
8 +assert.deepStrictEqual(L.prefixIntent('firefox'), { intent: 'all', query: 'firefox' });
9 +// the key is `intent`, NOT `provider` (contract rename)
10 +assert.strictEqual(L.prefixIntent('=2+2').intent, 'calculator');
11 +assert.strictEqual(L.prefixIntent('=2+2').provider, undefined);
12 +assert.strictEqual(L.prefixIntent('CLIP bar').intent, 'clipboard'); // prefix is case-insensitive
14 +// --- fuzzyScore: exact > prefix > word-boundary subsequence > loose subsequence > -1 ---
15 +const exact = L.fuzzyScore('firefox', 'firefox', 0); // 1000
16 +const prefix = L.fuzzyScore('fire', 'firefox', 0); // 800 - 7
17 +const wbSub = L.fuzzyScore('fb', 'firefox browser', 0); // acronym, high band
18 +const loose = L.fuzzyScore('frfx', 'firefox', 0); // scattered, low band
19 +assert.ok(exact > prefix, 'exact > prefix');
20 +assert.ok(prefix > wbSub, 'prefix > word-boundary subsequence');
21 +assert.ok(wbSub > loose, 'word-boundary subsequence > loose subsequence');
22 +assert.ok(loose >= 0, 'loose subsequence is a match (>= 0)');
23 +// "frfx" finds "firefox"; "zzz" does not
24 +assert.ok(L.fuzzyScore('frfx', 'firefox', 0) > 0, 'frfx matches firefox');
25 +assert.strictEqual(L.fuzzyScore('zzz', 'firefox', 0), -1, 'zzz does not match firefox');
26 +// empty query returns the bare boost (so every row lists)
27 +assert.strictEqual(L.fuzzyScore('', 'anything', 900), 900);
28 +// exact concrete value + provider boost adds in
29 +assert.strictEqual(L.fuzzyScore('firefox', 'firefox', 900), 1900);
31 +// --- calculatorValue: evaluates, rejects non-arithmetic, null on fail/non-finite ---
32 +assert.strictEqual(L.calculatorValue('2+2'), '4');
33 +assert.strictEqual(L.calculatorValue('2*21'), '42');
34 +assert.strictEqual(L.calculatorValue(' 1 + 1 '), '2'); // whitespace stripped
35 +assert.strictEqual(L.calculatorValue('1/2'), '0.5'); // non-integer formatting
36 +assert.strictEqual(L.calculatorValue('a()'), null); // letters rejected by guard
37 +assert.strictEqual(L.calculatorValue('x=1'), null); // assignment rejected by guard
38 +assert.strictEqual(L.calculatorValue('1/0'), null); // Infinity -> non-finite
39 +assert.strictEqual(L.calculatorValue(''), null); // empty -> null
41 +// --- buildApps: sorts by title + carries the desktop icon name ---
42 +const apps = L.buildApps([
43 + { id: 'gimp', name: 'GIMP', icon: 'gimp', comment: 'Image editor' },
44 + { id: 'firefox', name: 'Firefox', icon: 'firefox-icon', comment: 'Web browser' }
45 +]);
46 +assert.deepStrictEqual(apps.map(a => a.title), ['Firefox', 'GIMP']); // alpha sorted
47 +assert.strictEqual(apps[0].icon, 'firefox-icon'); // icon carried
48 +assert.strictEqual(apps[1].icon, 'gimp');
49 +assert.strictEqual(apps[0].id, 'app:firefox');
50 +assert.strictEqual(apps[0].desktopPath, 'firefox.desktop');
51 +assert.ok(L.buildApps([{ id: 'noname' }]).length === 0); // entries without name skipped
53 +// --- rankResults: exact app title ranks to selectedIndex 0, icon preserved ---
54 +const allRank = L.rankResults('Firefox', { apps: apps });
55 +assert.strictEqual(allRank.providerIntent, 'all');
56 +assert.strictEqual(allRank.selectedIndex, 0);
57 +assert.strictEqual(allRank.results[0].title, 'Firefox');
58 +assert.strictEqual(allRank.results[0].provider, 'app');
59 +assert.strictEqual(allRank.results[0].icon, 'firefox-icon'); // icon survives shaping
61 +// --- rankResults: `>` honors action intent ---
62 +const actions = [
63 + { id: 'lock', title: 'Lock', subtitle: 'Lock this session', route: 'service' },
64 + { id: 'overview', title: 'Overview', subtitle: 'Open niri overview', route: 'service' }
65 +];
66 +const actionRank = L.rankResults('>', { apps: apps, actions: actions });
67 +assert.strictEqual(actionRank.providerIntent, 'action');
68 +assert.ok(actionRank.results.length >= 1);
69 +assert.ok(actionRank.results.every(r => r.provider === 'action')); // no apps leak in
70 +assert.strictEqual(actionRank.selectedIndex, 0);
72 +// --- rankResults: `clip ` honors clipboard intent ---
73 +const clipRows = [{ id: 'c1', title: 'hello clip', body: 'hello clip' }];
74 +const clipRank = L.rankResults('clip hello', { apps: apps, clipRows: clipRows });
75 +assert.strictEqual(clipRank.providerIntent, 'clipboard');
76 +assert.ok(clipRank.results.length >= 1);
77 +assert.ok(clipRank.results.every(r => r.provider === 'clipboard'));
79 +// --- rankResults: `=2*21` emits a calc row with value 42 (string) ---
80 +const calcRank = L.rankResults('=2*21', {});
81 +assert.strictEqual(calcRank.providerIntent, 'calculator');
82 +assert.ok(calcRank.calc, 'calc row present');
83 +assert.strictEqual(calcRank.calc.value, '42');
84 +assert.strictEqual(calcRank.results[0].provider, 'calculator');
85 +assert.strictEqual(calcRank.results[0].title, '42');
87 +// --- rankResults: empty query lists apps sorted, selectedIndex 0 ---
88 +const emptyRank = L.rankResults('', { apps: apps });
89 +assert.strictEqual(emptyRank.selectedIndex, 0);
90 +assert.deepStrictEqual(emptyRank.results.map(r => r.title), ['Firefox', 'GIMP']);
92 +console.log('launch.test.js: ALL PASS');

quickshell/nuguland/shell.qml

Modified
794 794 return launcher.stateJson();
797 + function launcherSelfTest() : string {
798 + return launcher.selfTest();
797 801 function launcherLaunchRecord(rowJson: string) : string {
798 802 return launcher.launchRecord(rowJson);