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
|
const hyprland = await Service.import("hyprland")
const audio = await Service.import("audio")
const battery = await Service.import("battery")
const network = await Service.import("network")
const hour = Variable("", {
poll: [60000, 'date "+%H:%M"']
})
function IconLabel(icon, label) {
return [
Widget.Icon({ icon }),
Widget.Label({ label }),
]
}
function Workspaces() {
const active = hyprland.active.workspace.bind("id")
const workspaces = hyprland.bind("workspaces")
.as(ws => ws.map(({ id }) => Widget.Button({
on_clicked: () => hyprland.messageAsync(`dispatch workspace ${id}`),
child: Widget.Label(`${id}`),
class_name: active.as(i => `${i === id ? "focused" : ""}`)
})))
return Widget.Box({
class_name: "workspaces",
children: workspaces,
})
}
//function SysTray() {
//
//}
function Clock() {
return Widget.Label({
class_name: "clock",
label: hour.bind(),
})
}
function Network() {
const label = network.wifi.bind("strength").as(s => ` ${s}`)
return Widget.Box({
class_name: "network",
children: [
Widget.Label({ label })
]
})
}
function Volume() {
const icons = {
101: "overamplified",
67: "high",
34: "medium",
1: "low",
0: "muted",
}
function getIcon() {
const icon = audio.speaker.is_muted ? 0 : [101, 67, 34, 1, 0].find(
threshold => threshold <= audio.speaker.volume * 100)
return `audio-volume-${icons[icon]}-symbolic`
}
const icon = Utils.watch(getIcon(), audio.speaker, getIcon)
const label = audio.speaker.bind("volume").as(v => ` ${Math.floor(v * 100 + 0.01)}%`)
return Widget.Box({
class_name: "volume",
children: IconLabel(icon, label)
})
}
function Battery() {
const label = battery.bind("percent").as(p => ` ${p}%`)
const icon = battery.bind("percent").as(p =>
`battery-level-${Math.floor(p / 10) * 10}-symbolic`
)
return Widget.Box({
class_name: "battery",
children: IconLabel(icon, label)
})
}
function Left() {
return Widget.Box({
spacing: 10,
children: [
Workspaces(),
//SysTray(),
]
})
}
function Center() {
return Widget.Box({
spacing: 10,
children: [
Clock(),
]
})
}
function Right() {
return Widget.Box({
hpack: "end",
spacing: 10,
children: [
Network(),
Volume(),
Battery(),
]
})
}
export function Bar(monitor = 0) {
return Widget.Window({
name: `bar-${monitor}`,
class_name: "bar",
monitor,
anchor: ["top", "left", "right"],
exclusivity: "exclusive",
child: Widget.CenterBox({
start_widget: Left(),
center_widget: Center(),
end_widget: Right(),
}),
})
}
|