1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
|
import Quickshell
import Quickshell.Io
import Quickshell.Services.SystemTray
import Quickshell.Widgets
import Custom as Custom
import QtQuick
import qs.Services
PanelWindow {
id: bar
property var modelData
anchors {
top: true
left: true
right: true
}
margins {
left: 26 + 8
right: 26 + 8
}
screen: modelData
implicitHeight: 21
color: "transparent"
Rectangle {
color: Qt.rgba(0, 0, 0, 0.66)
anchors.fill: parent
// bottomLeftRadius: 8
// bottomRightRadius: 8
}
Row {
id: left
height: parent.height
width: childrenRect.width
anchors.left: parent.left
anchors.leftMargin: 8
anchors.verticalCenter: parent.verticalCenter
spacing: 8
Row {
id: workspaces
property var ignoreWorkspaces: @ignore_workspaces@
height: parent.height
anchors.verticalCenter: parent.verticalCenter
spacing: 0
Repeater {
model: {
let currWorkspaces = NiriService.workspaces;
const ignoreWorkspaces = Array.from(workspaces.ignoreWorkspaces);
currWorkspaces = currWorkspaces.filter(ws => ws.is_active || ignoreWorkspaces.every(iws => iws !== ws.name));
currWorkspaces.sort((a, b) => {
if (NiriService.outputs?.[a.output]?.logical?.x !== NiriService.outputs?.[b.output]?.logical?.x)
return NiriService.outputs?.[a.output]?.logical?.x - NiriService.outputs?.[b.output]?.logical?.x
if (NiriService.outputs?.[a.output]?.logical?.y !== NiriService.outputs?.[b.output]?.logical?.y)
return NiriService.outputs?.[a.output]?.logical?.y - NiriService.outputs?.[b.output]?.logical?.y
return a.idx - b.idx;
});
return currWorkspaces;
}
Rectangle {
property var workspaceData: modelData
width: wsLabel.contentWidth + 8
color: {
if (mouseArea.containsMouse) {
return "#33808080";
}
return "transparent";
}
height: parent.height
anchors.verticalCenter: parent.verticalCenter
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
enabled: true
onClicked: {
NiriService.sendCommand({ "Action": { "FocusWorkspace": { "reference": { "Id": workspaceData.id } } } }, _ => {})
}
}
Text {
id: wsLabel
font.pointSize: 10
font.family: "Fira Sans"
color: {
if (workspaceData.is_active)
return "#23fd00";
if (workspaceData.active_window_id === null)
return "#555";
return "white";
}
anchors.centerIn: parent
text: workspaceData.name ? workspaceData.name : workspaceData.idx
}
}
}
}
}
Row {
id: center
height: parent.height
width: childrenRect.width
anchors.centerIn: parent
spacing: 5
Item {
id: activeWindowDisplay
property var activeWindow: {
let currWindowId = Array.from(NiriService.workspaces).find(ws => {
return ws.output === bar.screen.name && ws.is_active;
})?.active_window_id;
return currWindowId ? Array.from(NiriService.windows).find(win => win.id == currWindowId) : null;
}
property var windowEntry: activeWindow ? DesktopEntries.heuristicLookup(activeWindow.app_id) : null
anchors.verticalCenter: parent.verticalCenter
width: activeWindowDisplayContent.width
height: parent.height
Row {
id: activeWindowDisplayContent
width: childrenRect.width
height: parent.height
anchors.verticalCenter: parent.verticalCenter
spacing: 8
IconImage {
id: activeWindowIcon
height: 14
width: 14
anchors.verticalCenter: parent.verticalCenter
source: {
let icon = activeWindowDisplay.windowEntry?.icon
if (typeof icon === 'string' || icon instanceof String) {
if (icon.includes("?path=")) {
const split = icon.split("?path=")
if (split.length !== 2)
return icon
const name = split[0]
const path = split[1]
const fileName = name.substring(
name.lastIndexOf("/") + 1)
return `file://${path}/${fileName}`
} else
icon = Quickshell.iconPath(icon);
return icon
}
return ""
}
asynchronous: true
smooth: true
mipmap: true
}
Text {
id: windowTitle
width: Math.min(implicitWidth, bar.width - 2*Math.max(left.width, right.width) - 2*8 - activeWindowIcon.width - activeWindowDisplayContent.spacing)
property var appAliases: { "Firefox": "Mozilla Firefox", "mpv Media Player": "mpv", "Thunderbird": "Mozilla Thunderbird", "Thunderbird (LMU)": "Mozilla Thunderbird" }
elide: Text.ElideRight
maximumLineCount: 1
color: "white"
anchors.verticalCenter: parent.verticalCenter
text: {
if (!activeWindowDisplay.activeWindow)
return "";
var title = activeWindowDisplay.activeWindow.title;
var appName = activeWindowDisplay.windowEntry?.name;
if (appAliases[appName])
appName = appAliases[appName];
if (appName && title.endsWith(appName)) {
const oldTitle = title;
title = title.substring(0, title.length - appName.length);
title = title.replace(/\s*(—|-)\s*$/, "");
if (!title)
title = oldTitle;
}
return title;
}
}
}
}
}
Row {
id: right
height: parent.height
width: childrenRect.width
anchors.right: parent.right
anchors.rightMargin: 8
anchors.verticalCenter: parent.verticalCenter
spacing: 0
Item {
anchors.verticalCenter: parent.verticalCenter
width: systemTrayRow.childrenRect.width
height: parent.height
clip: true
Row {
id: systemTrayRow
anchors.centerIn: parent
width: childrenRect.width
height: parent.height
spacing: 0
Repeater {
model: SystemTray.items.values
delegate: Item {
property var trayItem: modelData
property string iconSource: {
let icon = trayItem && trayItem.icon
if (typeof icon === 'string' || icon instanceof String) {
if (icon.includes("?path=")) {
const split = icon.split("?path=")
if (split.length !== 2)
return icon
const name = split[0]
const path = split[1]
const fileName = name.substring(
name.lastIndexOf("/") + 1)
return `file://${path}/${fileName}`
}
return icon
}
return ""
}
width: 16
height: parent.height
anchors.verticalCenter: parent.verticalCenter
IconImage {
anchors.centerIn: parent
width: parent.width
height: parent.width
source: parent.iconSource
asynchronous: true
smooth: true
mipmap: true
}
MouseArea {
id: trayItemArea
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: mouse => {
if (!trayItem)
return
if (mouse.button === Qt.LeftButton
&& !trayItem.onlyMenu) {
trayItem.activate()
return
}
if (trayItem.hasMenu) {
var globalPos = mapToGlobal(0, 0)
var currentScreen = screen || Screen
var screenX = currentScreen.x || 0
var relativeX = globalPos.x - screenX
menuAnchor.menu = trayItem.menu
menuAnchor.anchor.window = bar
menuAnchor.anchor.rect = Qt.rect(
relativeX,
21,
parent.width, 1)
menuAnchor.open()
}
}
}
}
}
}
QsMenuAnchor {
id: menuAnchor
}
}
Rectangle {
height: parent.height
width: 4
color: "transparent"
}
Rectangle {
id: kbdWidget
property var keyboardAbbrev: { "English (programmer Dvorak)": "dvp", "English (US)": "us" }
width: kbdLabel.contentWidth + 8
color: {
if (kbdMouseArea.containsMouse) {
return "#33808080";
}
return "transparent";
}
height: parent.height
anchors.verticalCenter: parent.verticalCenter
MouseArea {
id: kbdMouseArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
enabled: true
onClicked: {
NiriService.sendCommand({ "Action": { "SwitchLayout": { "layout": "Next" } } }, _ => {})
}
}
Text {
id: kbdLabel
font.pointSize: 10
font.family: "Fira Sans"
color: {
if (NiriService.keyboardLayouts?.current_idx === 0)
return "#555";
return "white";
}
anchors.centerIn: parent
text: {
const currentLayout = NiriService.keyboardLayouts?.names?.[NiriService.keyboardLayouts.current_idx];
if (!currentLayout)
return "";
return kbdWidget.keyboardAbbrev[currentLayout] ? kbdWidget.keyboardAbbrev[currentLayout] : currentLayout;
}
}
}
Rectangle {
height: parent.height
width: 4
color: "transparent"
}
Text {
id: clock
color: "white"
anchors.verticalCenter: parent.verticalCenter
Custom.Chrono {
id: chrono
format: "W{0:%V-%u} {0:%F} {0:%H:%M:%S%Ez}"
}
text: chrono.date
font.pointSize: 10
font.family: "Fira Sans"
font.features: { "tnum": 1 }
}
}
}
|