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
|
;; This file defines the right-side status bar for the Niri Wayland compositor.
;; It displays workspaces, active windows, and system statistics (CPU, RAM, network,
;; battery, audio, date/time). The bar is anchored to the top-right of the monitor
;; with a width of 60px and spans the full height.
(defpoll time :interval "10s" "date '+%I:%M'")
(defpoll ampm :interval "10s" "date '+%p'")
(defpoll date :interval "60s" "date '+%d/%m'")
(defpoll full_date :interval "60s" "date '+%A, %d %B %Y'")
(deflisten niri_status :initial "{\"workspaces\":[],\"active_windows\":[]}" "@@niri-status-script@@")
(deflisten system_stats
:initial "{\"cpu\":{\"percent\":0,\"per_core\":[],\"freq_mhz\":null,\"load_avg\":null,\"tooltip\":\"CPU: 0%\"},\"ram\":{\"percent\":0,\"used\":\"0B\",\"total\":\"0B\",\"available\":\"0B\",\"swap_percent\":0,\"swap_used\":\"0B\",\"swap_total\":\"0B\",\"speed_mhz\":null,\"tooltip\":\"RAM: 0%\"},\"net\":{\"status\":\"down\",\"tooltip\":\"Network Offline\",\"routes\":[]},\"sound\":{\"percent\":0,\"mute\":true,\"sink\":null,\"tooltip\":\"Volume: unknown\"},\"battery\":{\"percent\":0,\"present\":false,\"charging\":false,\"status\":\"none\",\"tooltip\":\"No battery\"}}"
"@@system-stats-script@@")
(defwindow bar
:monitor 0
:geometry (geometry :x "0px"
:y "0px"
:width "60px"
:height "100%"
:anchor "top right")
:stacking "fg"
:focusable "none"
:reserve (struts :distance "60px" :side "right")
(bar-content))
(defwidget bar-content []
(box :orientation "v"
:space-evenly false
:class "bar-container"
:vexpand true
(workspaces-widget :workspaces "${niri_status.workspaces}")
(windows-widget :windows "${niri_status.active_windows}")
(system-widget)))
(defwidget workspaces-widget [workspaces]
(box :orientation "v"
:space-evenly false
:spacing 4
:halign "fill"
:class "workspaces"
(for ws in workspaces
(eventbox :onclick "niri msg action focus-workspace ${ws.idx}"
:cursor "pointer"
:halign "fill"
:tooltip "${ws.tooltip}"
(box :class "workspace-button ${ws.is_active ? 'active' : ''}"
:halign "fill"
(overlay :halign "fill"
(image :class "workspace-icon"
:path "${ws.icon}"
:image-width 20
:image-height 20)
(label :class "workspace-idx"
:text "${ws.idx}"
:halign "end"
:valign "end")))))))
(defwidget windows-widget [windows]
(box :orientation "v"
:space-evenly false
:spacing 4
:halign "center"
:class "windows"
:vexpand true
(for w in windows
(eventbox :onclick "niri msg action focus-window --id ${w.id}"
:cursor "pointer"
:halign "fill"
:tooltip "${w.app_id}: ${w.title != '' ? ' ' : ''}${w.title}"
(box :halign "fill"
:class "window-button ${w.is_focused ? 'focused' : ''}"
(image :class "window-icon"
:path "${w.icon}"
:image-width 20
:image-height 20))))))
(defwidget system-widget []
(box :orientation "v"
:space-evenly false
:spacing 6
:halign "fill"
:class "system"
(box :orientation "v"
:class "system-item"
:halign "fill"
:space-evenly false
:spacing 4
:tooltip "${system_stats.net.tooltip}"
(image :class "system-icon"
:icon "${system_stats.net.status == 'down' ? 'network-offline' : system_stats.net.routes[0].type == 'wifi' ? 'network-wireless' : system_stats.net.routes[0].type == 'ethernet' ? 'network-wired' : system_stats.net.routes[0].type == 'tun' ? 'network-vpn' : 'network-offline'}"
:image-width 24
:image-height 24)
(label :class "system-label small"
:text "${system_stats.net.status == 'down' ? '-' : system_stats.net.routes[0].tx}")
(label :class "system-label small"
:text "${system_stats.net.status == 'down' ? '-' : system_stats.net.routes[0].rx}"))
(box :orientation "v"
:class "system-item"
:space-evenly false
:spacing 4
:tooltip "${system_stats.cpu.tooltip}"
(image :class "system-icon"
:icon "cpu"
:image-width 24
:image-height 24)
(label :class "system-label" :text "${system_stats.cpu.percent}%"))
(box :orientation "v"
:class "system-item"
:space-evenly false
:spacing 4
:tooltip "${system_stats.ram.tooltip}"
(image :class "system-icon"
:icon "drive-harddisk"
:image-width 24
:image-height 24)
(label :class "system-label" :text "${system_stats.ram.percent}%"))
(box :orientation "v"
:class "system-item"
:space-evenly false
:spacing 4
:tooltip "${system_stats.battery.tooltip}"
(image :class "system-icon"
:icon "battery"
:image-width 24
:image-height 24)
(label :class "system-label"
:text "${system_stats.battery.present ? (system_stats.battery.percent + '%') : '-'}"))
(eventbox :onclick "pamixer --toggle-mute"
:onscroll "bash -c '[ \"{}\" = \"up\" ] && pamixer --increase 5 --unmute || pamixer --decrease 5'"
:cursor "pointer"
:halign "fill"
(box :orientation "v"
:space-evenly false
:spacing 4
:class "system-item"
:tooltip "${system_stats.sound.tooltip}"
(image :class "system-icon"
:icon "audio-volume-high"
:image-width 24
:image-height 24)
(label :class "system-label"
:text "${system_stats.sound.mute ? '-' : (system_stats.sound.percent + '%')}")))
(box :orientation "v"
:class "system-item"
:space-evenly false
:spacing 4
:tooltip "${full_date} ${time} (${date})"
(image :class "system-icon"
:icon "calendar"
:image-width 24
:image-height 24)
(label :class "system-label small" :text time)
(label :class "system-label small" :text ampm)
(label :class "system-label small" :text date))))
|