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
|
local astal = require("astal")
local Widget = require("astal.gtk3.widget")
local Variable = astal.Variable
local GLib = astal.require("GLib")
local bind = astal.bind
local Mpris = astal.require("AstalMpris")
local Battery = astal.require("AstalBattery")
local Wp = astal.require("AstalWp")
local Network = astal.require("AstalNetwork")
local Tray = astal.require("AstalTray")
local Hyprland = astal.require("AstalHyprland")
local map = require("lib").map
local function SysTray()
local tray = Tray.get_default()
return Widget.Box({
class_name = "SysTray",
bind(tray, "items"):as(function(items)
return map(items, function(item)
return Widget.MenuButton({
tooltip_markup = bind(item, "tooltip_markup"),
use_popover = false,
menu_model = bind(item, "menu-model"),
action_group = bind(item, "action-group"):as(function(ag)
return { "dbusmenu", ag }
end),
Widget.Icon({
g_icon = bind(item, "gicon"),
}),
})
end)
end),
})
end
local function FocusedClient()
local hypr = Hyprland.get_default()
local focused = bind(hypr, "focused-client")
return Widget.Box({
class_name = "Focused",
visible = focused,
focused:as(function(client)
return client and Widget.Label({
label = bind(client, "title"):as(tostring),
})
end),
})
end
local function Wifi()
local wifi = Network.get_default().wifi
return Widget.Icon({
tooltip_text = bind(wifi, "ssid"):as(tostring),
class_name = "Wifi",
icon = bind(wifi, "icon-name"),
})
end
local function AudioSlider()
local speaker = Wp.get_default().audio.default_speaker
return Widget.Box({
class_name = "AudioSlider",
css = "min-width: 140px;",
Widget.Icon({
icon = bind(speaker, "volume-icon"),
}),
Widget.Slider({
hexpand = true,
on_dragged = function(self)
speaker.volume = self.value
end,
value = bind(speaker, "volume"),
}),
})
end
local function BatteryLevel()
local bat = Battery.get_default()
return Widget.Box({
class_name = "Battery",
visible = bind(bat, "is-present"),
Widget.Icon({
icon = bind(bat, "battery-icon-name"),
}),
Widget.Label({
label = bind(bat, "percentage"):as(function(p)
return tostring(math.floor(p * 100)) .. " %"
end),
}),
})
end
local function Media()
local player = Mpris.Player.new("spotify")
return Widget.Box({
class_name = "Media",
visible = bind(player, "available"),
Widget.Box({
class_name = "Cover",
valign = "CENTER",
css = bind(player, "cover-art"):as(function(cover)
return "background-image: url('" .. (cover or "") .. "');"
end),
}),
Widget.Label({
label = bind(player, "metadata"):as(function()
return (player.title or "") .. " - " .. (player.artist or "")
end),
}),
})
end
local function Workspaces()
local hypr = Hyprland.get_default()
return Widget.Box({
class_name = "Workspaces",
bind(hypr, "workspaces"):as(function(wss)
table.sort(wss, function(a, b)
return a.id < b.id
end)
return map(wss, function(ws)
if !(ws.id >= -99 and ws.id <= -2) then -- filter out special workspaces
return Widget.Button({
class_name = bind(hypr, "focused-workspace"):as(function(fw)
return fw == ws and "focused" or ""
end),
on_clicked = function()
ws:focus()
end,
label = bind(ws, "id"):as(function(v)
return type(v) == "number" and string.format("%.0f", v) or v
end),
})
end
end)
end),
})
end
local function Time(format)
local time = Variable(""):poll(1000, function()
return GLib.DateTime.new_now_local():format(format)
end)
return Widget.Label({
class_name = "Time",
on_destroy = function()
time:drop()
end,
label = time(),
})
end
return function(gdkmonitor)
local WindowAnchor = astal.require("Astal", "3.0").WindowAnchor
return Widget.Window({
class_name = "Bar",
gdkmonitor = gdkmonitor,
anchor = WindowAnchor.TOP + WindowAnchor.LEFT + WindowAnchor.RIGHT,
exclusivity = "EXCLUSIVE",
Widget.CenterBox({
Widget.Box({
halign = "START",
Workspaces(),
FocusedClient(),
}),
Widget.Box({
Media(),
}),
Widget.Box({
halign = "END",
SysTray(),
Wifi(),
AudioSlider(),
BatteryLevel(),
Time("%H:%M - %A %e."),
}),
}),
})
end
|