repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

bar: primary-screen-only surfaces, consolidated per-output workspace trays, constant-center clock

98f884968a37487a74934f10442c124d732073f7

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

nuguland's interactive surfaces (bar, OSD, toasts) now render only on the
primary monitor instead of once per screen. Primary is configurable via
shell.primaryOutput (connector name), falling back to the first connected
screen. The wallpaper backdrop and polkit security prompt stay on every
screen by design.

The single primary bar consolidates every output's workspaces, grouping
each output onto its own faint rounded tray so it stays clear which pills
belong to which monitor; trays are ordered by physical output position
(niri logical x). Workspaces focus by unique name, so clicking another
monitor's workspace from the primary bar works cross-output.

The clock is pulled out of the usage-sorted widget order and pinned at a
constant position: centred when the right-side widgets leave room, else just
left of them so it never overlaps a widget. Right-side widgets are
right-anchored at natural width (replacing the fillWidth layout) so they
never truncate while free space remains.

Positions are all derived (parent.width, widgetsRow.x, anchors) and chip
widths now come from BarChip's content-driven sizing, removing the hardcoded
chipWidth() px table.

Supersedes the focused-output gating and per-bar workspace filter; adds a
niriSelfTest IPC that gates the grouping/idx-sort/empty-filter logic with a
synthetic two-output sample (verifiable on a single monitor).

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

Changed files (4)

+269 / −107 text lines

Diff layout

quickshell/nuguland/Bar.qml

Modified

+118 / −80 text lines

5656 return String(name);
5757 }
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 }
8959 // "something active inside" — drives a super subtle active dot on the chip
9060 function chipActive(name) {
9161 switch (String(name)) {
183153 color: root.theme ? root.theme.withAlpha(root.theme.ui.accent, 0.55) : "transparent"
184154 }
186 RowLayout {
187 anchors.fill: parent
156 // Constant-position clock, pinned at bar centre so the eye always lands
157 // on the same spot. Declared first so the strips can anchor to its edges.
158 BarChip {
159 id: clockChip
161 popoutName: "clock"
162 label: root.chipLabel("clock")
163 width: preferredWidth
164 height: 26
165 // Centred when the right-side widgets leave room, otherwise pinned
166 // just left of them so the clock never overlaps a widget. For a
167 // fixed widget set this x is still constant, so the glance target
168 // stays put — on a wide monitor it lands at true centre.
169 x: Math.min(parent.width / 2 - width / 2, widgetsRow.x - width - 12)
170 anchors.verticalCenter: parent.verticalCenter
171 }
173 // LEFT zone: every output's workspaces, each output on its own faint
174 // tray so it stays clear which pills belong to which monitor. Bounded by
175 // the clock on the right and clipped, so it never crosses centre.
176 Row {
177 id: workspaceStrip
179 anchors.left: parent.left
188180 anchors.leftMargin: 10
189 anchors.rightMargin: 10
190 spacing: 10
181 anchors.right: clockChip.left
182 anchors.rightMargin: 12
183 anchors.verticalCenter: parent.verticalCenter
184 height: 26
185 spacing: 8
186 clip: true
192 Row {
193 id: workspaceStrip
188 Repeater {
189 model: root.niriService ? root.niriService.workspaceGroups() : []
195 Layout.fillWidth: true
196 Layout.minimumWidth: 160
197 Layout.preferredHeight: 26
198 Layout.alignment: Qt.AlignVCenter
199 spacing: 4
200 clip: true
191 // Wrap the group in a plain Item: Qt6 won't inject an array
192 // model's modelData into a required prop on a delegate root that
193 // re-declares it for a nested Repeater. The wrapper takes the
194 // injection and hands it to the tray/pills explicitly.
195 delegate: Item {
196 id: groupItem
202 Repeater {
203 // only this monitor's workspaces, idx-sorted, so each bar
204 // reads its own 1..N instead of every output's union.
205 model: root.niriService ? root.niriService.workspacesForOutput(root.screen ? root.screen.name : "") : []
198 required property var modelData
207 delegate: Rectangle {
208 id: workspaceChip
200 width: tray.width
201 height: 26
210 required property var modelData
211 readonly property bool active: !!modelData.is_focused
212 readonly property string workspaceLabel: `${modelData.idx || modelData.id || "?"}${modelData.name ? ` ${modelData.name}` : ""}`.toLowerCase()
203 Rectangle {
204 id: tray
214 width: Math.max(34, workspaceText.implicitWidth + 18)
206 anchors.verticalCenter: parent.verticalCenter
207 width: pillRow.implicitWidth + 12
215208 height: 26
216 radius: 9
217 color: root.theme ? (active ? root.theme.withAlpha(root.theme.ui.focus, 0.28) : root.theme.withAlpha(root.theme.ui.minor, 0.1)) : "transparent"
218 border.width: 0
209 radius: 13
210 color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.07) : "transparent"
220 NuguText {
221 id: workspaceText
212 Row {
213 id: pillRow
223215 anchors.centerIn: parent
224 theme: root.theme
225 variant: "meta"
226 text: workspaceChip.workspaceLabel
227 color: !root.theme ? "transparent" : (workspaceChip.active ? root.theme.ui.accent : root.theme.ui.normal)
228 }
216 spacing: 4
230 MouseArea {
231 anchors.fill: parent
232 hoverEnabled: true
233 cursorShape: Qt.PointingHandCursor
234 onClicked: {
235 if (root.niriService)
236 root.niriService.focusWorkspace(workspaceChip.modelData.name || workspaceChip.modelData.idx || workspaceChip.modelData.id);
218 Repeater {
219 model: groupItem.modelData.workspaces
221 delegate: Item {
222 id: pillWrap
224 required property var modelData
226 width: workspaceChip.width
227 height: 26
229 Rectangle {
230 id: workspaceChip
232 readonly property bool active: !!pillWrap.modelData.is_focused
233 readonly property string workspaceLabel: `${pillWrap.modelData.idx || pillWrap.modelData.id || "?"}${pillWrap.modelData.name ? ` ${pillWrap.modelData.name}` : ""}`.toLowerCase()
235 anchors.verticalCenter: parent.verticalCenter
236 width: Math.max(30, workspaceText.implicitWidth + 16)
237 height: 22
238 radius: 8
239 color: root.theme ? (active ? root.theme.withAlpha(root.theme.ui.focus, 0.28) : root.theme.withAlpha(root.theme.ui.minor, 0.1)) : "transparent"
240 border.width: 0
242 NuguText {
243 id: workspaceText
245 anchors.centerIn: parent
246 theme: root.theme
247 variant: "meta"
248 text: workspaceChip.workspaceLabel
249 color: !root.theme ? "transparent" : (workspaceChip.active ? root.theme.ui.accent : root.theme.ui.normal)
250 }
252 MouseArea {
253 anchors.fill: parent
254 hoverEnabled: true
255 cursorShape: Qt.PointingHandCursor
256 onClicked: {
257 // focus by unique name (works cross-output); idx/id
258 // fallback only for the unnamed, which are filtered out.
259 if (root.niriService)
260 root.niriService.focusWorkspace(pillWrap.modelData.name || pillWrap.modelData.idx || pillWrap.modelData.id);
262 }
263 }
265 }
267 }
238269 }
239271 }
241273 }
245277 }
247 RowLayout {
248 Layout.alignment: Qt.AlignVCenter
249 spacing: 4
279 }
251 Repeater {
252 model: root.usageService ? root.usageService.layoutOrder : []
281 // RIGHT zone: glanceable widgets at natural width, anchored to the right
282 // edge so they never truncate while free space remains (the constraint
283 // that ruled out a fillWidth layout).
284 RowLayout {
285 id: widgetsRow
254 delegate: BarChip {
255 required property var modelData
287 anchors.right: parent.right
288 anchors.rightMargin: 10
289 anchors.verticalCenter: parent.verticalCenter
290 spacing: 4
257 popoutName: modelData
258 label: root.chipLabel(modelData)
259 preferredWidth: root.chipWidth(modelData)
260 }
292 Repeater {
293 model: root.usageService ? root.usageService.layoutOrder : []
295 delegate: BarChip {
296 required property var modelData
298 popoutName: modelData
299 label: root.chipLabel(modelData)
262300 }
264302 }

quickshell/nuguland/Niri.qml

Modified

+121 / −20 text lines

1010 property string lastError: ""
1111 property var workspaces: []
1212 readonly property var visibleWorkspaces: displayWorkspaces(workspaces)
13 // niri output name (e.g. "DP-1") that currently holds focus, derived from
14 // the single globally-focused workspace; "" if none. Used to target the
15 // OSD/toast surfaces at the active monitor instead of every screen.
16 readonly property string focusedOutput: {
17 const list = workspaces || [];
18 for (let i = 0; i < list.length; i++)
19 if (list[i].is_focused)
20 return String(list[i].output || "");
21 return "";
22 }
2313 property var windows: []
2414 property var outputs: []
2515 property var focusedWindow: null
9383 });
9484 }
96 // visible workspaces belonging to one output (a bar's own monitor), sorted
97 // by niri's per-output idx so each bar reads 1..N left-to-right. When the
98 // output name is unknown/empty, fall back to all (single-monitor / no match).
99 function workspacesForOutput(outputName) {
100 const all = visibleWorkspaces;
101 const name = String(outputName || "");
102 if (name.length === 0)
103 return all;
104 const mine = all.filter((workspace) => String(workspace.output || "") === name);
105 return mine.sort((a, b) => Number(a.idx || 0) - Number(b.idx || 0));
86 // Group visible workspaces by output, each output's list idx-sorted, so the
87 // single primary bar renders every monitor's workspaces in its own tray.
88 // Pure: pass `items` for testing; defaults to the live workspace array.
89 function groupWorkspaces(items) {
90 const vis = displayWorkspaces(items === undefined ? workspaces : items);
91 const byOutput = ({
92 });
93 const order = [];
94 for (let i = 0; i < vis.length; i++) {
95 const name = String(vis[i].output || "");
96 if (!byOutput[name]) {
97 byOutput[name] = [];
98 order.push(name);
99 }
100 byOutput[name].push(vis[i]);
101 }
102 return order.map((name) => {
103 return {
104 "output": name,
105 "workspaces": byOutput[name].slice().sort((a, b) => Number(a.idx || 0) - Number(b.idx || 0))
106 };
107 });
108 }
110 // outputs may arrive as a name-keyed object (niri snapshot) or an array
111 // (event stream); normalize to an array of records that each carry `name`.
112 function outputList() {
113 if (Array.isArray(outputs))
114 return outputs;
115 const obj = outputs || ({
116 });
117 return Object.keys(obj).map((key) => {
118 return Object.assign({
119 "name": key
120 }, obj[key]);
121 });
122 }
124 // physical left-to-right order key for an output, from niri's logical x;
125 // large fallback so unknown outputs sort last (stable, not hash order).
126 function outputX(name) {
127 const list = outputList();
128 const want = String(name || "");
129 for (let i = 0; i < list.length; i++) {
130 if (String(list[i].name || "") === want) {
131 const logical = list[i].logical || ({
132 });
133 return typeof logical.x === "number" ? logical.x : 1000000;
134 }
135 }
136 return 1000000;
137 }
139 // live grouping for the bar, groups ordered by physical output position.
140 function workspaceGroups() {
141 return groupWorkspaces(workspaces).slice().sort((a, b) => outputX(a.output) - outputX(b.output));
142 }
144 // Local gate for the grouping logic (untestable on a single monitor): feed
145 // a synthetic two-output array and assert grouping, per-tray idx sort, and
146 // empty-trailing-workspace filtering. Drive via the niriSelfTest IPC.
147 function selfTest() {
148 const failures = [];
149 const sample = [{
150 "idx": 4,
151 "output": "DP-2",
152 "name": "browser"
153 }, {
154 "idx": 5,
155 "output": "DP-2",
156 "name": "vault"
157 }, {
158 "idx": 3,
159 "output": "DP-1",
160 "name": "games"
161 }, {
162 "idx": 6,
163 "output": "DP-1",
164 "name": null
165 }, {
166 "idx": 2,
167 "output": "DP-1",
168 "name": "media"
169 }, {
170 "idx": 1,
171 "output": "DP-1",
172 "name": "code",
173 "is_focused": true
174 }];
175 const groups = groupWorkspaces(sample);
176 if (groups.length !== 2)
177 failures.push(`expected 2 groups, got ${groups.length}`);
179 const dp1 = groups.filter((g) => g.output === "DP-1")[0] || null;
180 const dp2 = groups.filter((g) => g.output === "DP-2")[0] || null;
181 if (!dp1)
182 failures.push("missing DP-1 group");
184 if (!dp2)
185 failures.push("missing DP-2 group");
187 if (dp1) {
188 const idxs = JSON.stringify(dp1.workspaces.map((w) => w.idx));
189 if (idxs !== "[1,2,3]")
190 failures.push(`DP-1 idx order ${idxs} != [1,2,3]`);
192 }
193 if (dp2) {
194 const idxs = JSON.stringify(dp2.workspaces.map((w) => w.idx));
195 if (idxs !== "[4,5]")
196 failures.push(`DP-2 idx order ${idxs} != [4,5]`);
198 }
199 const total = groups.reduce((sum, g) => sum + g.workspaces.length, 0);
200 if (total !== 5)
201 failures.push(`expected 5 pills after empty filter, got ${total}`);
203 return {
204 "pass": failures.length === 0,
205 "failures": failures
206 };
106207 }
108209 function parsePickedColor(text) {

quickshell/nuguland/Usage.qml

Modified

+3 / −1 text lines

1010 id: root
1212 // Canonical widget set; array order is the tie-break for equal counts.
13 readonly property var widgets: ["clock", "launcher", "media", "system", "clipboard", "audio", "brightness", "connectivity", "power", "notifications", "tray", "idle"]
13 // "clock" is intentionally absent: it is pinned at a constant bar-center
14 // position by Bar.qml, so it must never drift in the usage-sorted order.
15 readonly property var widgets: ["launcher", "media", "system", "clipboard", "audio", "brightness", "connectivity", "power", "notifications", "tray", "idle"]
1517 // Snapshotted once at load (see FileView.onLoaded); the bar binds to this.
1618 property var layoutOrder: widgets

quickshell/nuguland/shell.qml

Modified

+27 / −6 text lines

77ShellRoot {
88 id: shell
10 // Connector name of the monitor that hosts the interactive nuguland
11 // surfaces (bar, OSD, toasts). Set e.g. "DP-1" to pin them; left empty it
12 // falls back to the first connected screen. The wallpaper backdrop and the
13 // polkit security prompt deliberately stay on every screen.
14 property string primaryOutput: ""
15 readonly property string primaryScreenName: {
16 const screens = Quickshell.screens;
17 const want = String(shell.primaryOutput || "");
18 if (want.length > 0)
19 for (let i = 0; i < screens.length; i++)
20 if (String(screens[i].name) === want)
21 return want;
23 return screens.length > 0 ? String(screens[0].name) : "";
24 }
1026 Theme {
1127 id: nuguTheme
125141 objectName: "osdOverlaySurface"
126142 screen: modelData
127 // only on the focused monitor (fall back to all if niri hasn't
128 // reported a focused output yet) instead of duplicating on each.
129 visible: osd.visibleState && (niri.focusedOutput.length === 0 || modelData.name === niri.focusedOutput)
143 // primary monitor only — no value showing the OSD once per screen.
144 visible: osd.visibleState && modelData.name === shell.primaryScreenName
130145 implicitWidth: 300
131146 implicitHeight: osdCard.implicitHeight + 16
132147 color: "transparent"
301316 objectName: "notificationToastSurface"
302317 screen: modelData
303 // focused monitor only (fall back to all if no focused output),
304 // so a toast shows once, not once per screen.
305 visible: toasts.length > 0 && (niri.focusedOutput.length === 0 || modelData.name === niri.focusedOutput)
318 // primary monitor only, so a toast shows once, not once per screen.
319 visible: toasts.length > 0 && modelData.name === shell.primaryScreenName
306320 implicitWidth: 380
307321 implicitHeight: Math.max(1, toastColumn.implicitHeight + 16)
308322 color: "transparent"
468482 Bar {
469483 required property var modelData
485 // primary monitor only; the bar consolidates every output's
486 // workspaces into per-output trays (see Bar.qml workspaceStrip).
487 visible: modelData.name === shell.primaryScreenName
471488 screen: modelData
472489 theme: nuguTheme
473490 niriService: niri
582599 return niri.stateJson();
583600 }
602 function niriSelfTest() : string {
603 return JSON.stringify(niri.selfTest());
604 }
585606 function reloadTheme() {
586607 nuguTheme.reload();
587608 return nuguTheme.mode;