repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

feat(nuguland): sort bar widgets by persistent usage

a5cf593e17b9bbaebdb72f313d753b1e0f2ad702

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Wire the usage tracker into the shell and drive the bar's widget order
from it. The two static chip groups collapse into one Repeater over the
usage-sorted layout order; chip label/width move into chipLabel()/
chipWidth() resolvers. Opening a widget records a use (close-toggle does
not). Order is snapshotted at load, so the bar stays put within a session
and re-sorts on next launch. Adds a 'usage' IPC target for inspection.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Changed files (3)

quickshell/nuguland/Bar.qml

Modified
24 24 required property QtObject idleService
25 25 required property QtObject lockService
26 26 required property QtObject surfaces
27 + required property QtObject usageService
29 + function chipLabel(name) {
30 + switch (String(name)) {
31 + case "clock":
32 + return root.timeService ? root.timeService.compact : "--:--";
33 + case "launcher":
34 + return "launch";
35 + case "media":
36 + return "media";
37 + case "system":
38 + return "system";
39 + case "clipboard":
40 + return "clip";
41 + case "audio":
42 + return root.audioService ? root.audioService.privacyLabel().toLowerCase() : "audio";
43 + case "brightness":
44 + return "bright";
45 + case "connectivity":
46 + return "network";
47 + case "power":
48 + return "power";
49 + case "notifications":
50 + return "notify";
51 + case "tray":
52 + return root.trayService && root.trayService.attentionCount > 0 ? `tray ${root.trayService.attentionCount}` : "tray";
53 + case "idle":
54 + return "idle";
55 + }
56 + return String(name);
57 + }
59 + function chipWidth(name) {
60 + switch (String(name)) {
61 + case "clock":
62 + return 70;
63 + case "launcher":
64 + return 68;
65 + case "media":
66 + return 60;
67 + case "system":
68 + return 96;
69 + case "clipboard":
70 + return 54;
71 + case "audio":
72 + return root.audioService && root.audioService.privacyLabel() === "Mic Cam" ? 80 : 62;
73 + case "brightness":
74 + return 66;
75 + case "connectivity":
76 + return 78;
77 + case "power":
78 + return 64;
79 + case "notifications":
80 + return 66;
81 + case "tray":
82 + return root.trayService && root.trayService.attentionCount > 0 ? 66 : 54;
83 + case "idle":
84 + return 50;
85 + }
86 + return 60;
87 + }
28 89 function itemRectInBar(item) {
29 90 let x = 0;
55 116 return ;
57 118 const target = String(name);
58 - if (root.surfaces.popoutOpen && root.surfaces.popoutName === target)
119 + if (root.surfaces.popoutOpen && root.surfaces.popoutName === target) {
59 120 root.surfaces.closePopout("bar-toggle");
60 - else
121 + } else {
122 + if (root.usageService)
123 + root.usageService.record(target);
61 125 root.surfaces.openRegisteredPopout(target);
64 129 function refreshSurfaceGeometry() {
106 171 Layout.alignment: Qt.AlignVCenter
107 172 spacing: 4
109 - BarChip {
110 - popoutName: "clock"
111 - label: root.timeService ? root.timeService.compact : "--:--"
112 - preferredWidth: 70
113 - }
174 + Repeater {
175 + model: root.usageService ? root.usageService.layoutOrder : []
115 - BarChip {
116 - popoutName: "launcher"
117 - label: "launch"
118 - preferredWidth: 68
119 - }
177 + delegate: BarChip {
178 + required property var modelData
121 - BarChip {
122 - popoutName: "media"
123 - label: "media"
124 - preferredWidth: 60
125 - }
180 + popoutName: modelData
181 + label: root.chipLabel(modelData)
182 + preferredWidth: root.chipWidth(modelData)
127 - }
129 - RowLayout {
130 - Layout.alignment: Qt.AlignVCenter
131 - spacing: 4
133 - BarChip {
134 - popoutName: "system"
135 - label: "system"
136 - preferredWidth: 96
137 - }
139 - BarChip {
140 - popoutName: "clipboard"
141 - label: "clip"
142 - preferredWidth: 54
143 - }
145 - BarChip {
146 - popoutName: "audio"
147 - label: root.audioService ? root.audioService.privacyLabel().toLowerCase() : "audio"
148 - preferredWidth: root.audioService && root.audioService.privacyLabel() === "Mic Cam" ? 80 : 62
149 - }
151 - BarChip {
152 - popoutName: "brightness"
153 - label: "bright"
154 - preferredWidth: 66
155 - }
157 - BarChip {
158 - popoutName: "connectivity"
159 - label: "network"
160 - preferredWidth: 78
161 - }
163 - BarChip {
164 - popoutName: "power"
165 - label: "power"
166 - preferredWidth: 64
167 - }
169 - BarChip {
170 - popoutName: "notifications"
171 - label: "notify"
172 - preferredWidth: 66
173 - }
175 - BarChip {
176 - popoutName: "tray"
177 - label: root.trayService && root.trayService.attentionCount > 0 ? `tray ${root.trayService.attentionCount}` : "tray"
178 - preferredWidth: root.trayService && root.trayService.attentionCount > 0 ? 66 : 54
179 - }
181 - BarChip {
182 - popoutName: "idle"
183 - label: "idle"
184 - preferredWidth: 50

quickshell/nuguland/Usage.qml

Modified
12 12 // Canonical widget set; array order is the tie-break for equal counts.
13 13 readonly property var widgets: ["clock", "launcher", "media", "system", "clipboard", "audio", "brightness", "connectivity", "power", "notifications", "tray", "idle"]
15 - // Snapshotted at load (see FileView.onLoaded); the bar binds to this.
15 + // Snapshotted once at load (see FileView.onLoaded); the bar binds to this.
16 16 property var layoutOrder: widgets
17 + property bool snapshotted: false
19 + function snapshot() {
20 + if (root.snapshotted)
21 + return ;
23 + root.snapshotted = true;
24 + root.layoutOrder = root.ordered();
25 + }
18 27 function countFor(name) {
19 28 const counts = usageAdapter.counts || ({
62 71 FileView {
63 72 id: usageFile
74 + // Single writer (this shell), so no watchChanges: a reload on our own
75 + // write would re-snapshot layoutOrder mid-session.
65 76 path: Quickshell.statePath("nuguland-widget-usage.json")
66 - watchChanges: true
67 - onFileChanged: reload()
68 77 onAdapterUpdated: writeAdapter()
69 - onLoaded: root.layoutOrder = root.ordered()
70 - onLoadFailed: root.layoutOrder = root.widgets
78 + onLoaded: root.snapshot()
79 + onLoadFailed: root.snapshot()
72 81 JsonAdapter {
73 82 id: usageAdapter

quickshell/nuguland/shell.qml

Modified
110 110 id: surfaceManager
113 + Usage {
114 + id: usage
113 117 Variants {
114 118 model: Quickshell.screens
334 338 idleService: idle
335 339 lockService: lock
336 340 surfaces: surfaceManager
341 + usageService: usage
408 413 target: "brightness"
416 + IpcHandler {
417 + function usageState() : string {
418 + return usage.stateJson();
421 + function record(name: string) : string {
422 + return usage.record(name);
425 + target: "usage"
411 428 IpcHandler {
412 429 function ping() : string {
413 430 return "nuguland";