add new widgets; rewrite workspace indicator

This commit is contained in:
gnat 2024-11-17 16:27:41 -08:00
parent 784e71e643
commit d584d25194
5 changed files with 125 additions and 10 deletions

View File

@ -0,0 +1,33 @@
local Battery <const> = lgi.require("AstalBattery")
local battery <const> = Battery.get_default()
local icons <const> = {
{"󰂎", "󰁺", "󰁻", "󰁼", "󰁽", "󰁾", "󰁿", "󰂀", "󰂁", "󰂂", "󰁹"},
{"󰢟", "󰢜", "󰂆", "󰂇", "󰂈", "󰢝", "󰂉", "󰢞", "󰂊", "󰂋", "󰂅"},
};
return Widget.Box({
class_name = 'battery-container',
children = {
Widget.CircularProgress({
class_name = 'battery-dial',
rounded = false,
inverted = false,
start_at = -.25,
end_at = .75,
value = bind(battery, 'percentage'),
child = Widget.Label({
halign = "CENTER",
hexpand = true,
justify = 2,
setup = function(self)
self:hook(battery, 'notify::percentage', function(self, percentage)
self.label = icons[battery:get_charging() and 1 or 2][math.floor(percentage*10)]
end)
self.label = icons[battery:get_charging() and 2 or 1][math.floor(battery:get_percentage()*10)]
end
})
})
}
})

18
lua/widgets/bar/clock.lua Normal file
View File

@ -0,0 +1,18 @@
local datetime = Variable(0):poll(1000, "date +'%d %b %H:%M:%S'", function(out, _) return out end)
local unix_seconds = Variable(0):poll(1000, "date +'%s'", function(out, _) return out end)
return Widget.Box({
class_name = 'clock',
vertical = true,
valign = 'CENTER',
children = {
Widget.Label({
halign = 'START',
label = bind(datetime, 'value')
}),
Widget.Label({
halign = 'START',
label = bind(unix_seconds, 'value')
})
}
})

View File

@ -1,9 +1,38 @@
local workspaces <const> = require(... .. '.workspaces')
local clock <const> = require(... .. '.clock')
local battery <const> = require(... .. '.battery')
local volume <const> = require(... .. '.volume')
local brightness <const> = require(... .. '.brightness')
return Astal.Window({
namespace = "bar",
name = "bar",
anchor = Astal.WindowAnchor.TOP + Astal.WindowAnchor.LEFT + Astal.WindowAnchor.RIGHT,
exclusivity = "EXCLUSIVE",
child = workspaces,
child = Widget.CenterBox({
start_widget = Widget.Box({
class_name = 'left',
children = {
workspaces,
}
}),
center_widget = Widget.Box({}),
end_widget = Widget.Box({
class_name = 'right',
halign = 'END',
children = {
Widget.Box({
class_name = 'sliders',
vertical = true,
children = {
volume,
brightness
}
}),
battery,
Gtk.Separator({}),
clock
}
}),
})
})

View File

@ -0,0 +1,26 @@
local wp <const> = lgi.require("AstalWp").get_default()
local endpoint = wp:get_audio():get_default_speaker()
return Widget.Box({
class_name = 'volume-slider',
children = {
Widget.Button({
child = Widget.Icon({
icon = bind(endpoint, "volume-icon"),
}),
on_clicked = function()
endpoint:set_mute(not endpoint:get_mute())
end
}),
Widget.Slider({
class_name = 'volume-slider',
hexpand = true,
draw_value = false,
value = bind(endpoint, 'volume'),
on_value_changed = function(self)
endpoint:set_volume(self.value)
end
})
}
})

View File

@ -1,4 +1,4 @@
local Hyprland <const> = astal.require("AstalHyprland")
local Hyprland <const> = lgi.require("AstalHyprland")
local map, sequence = require('lua.lib').map, require('lua.lib').sequence
local hypr = Hyprland.get_default()
@ -15,18 +15,26 @@ local function workspace_row(start, stop)
self:hook(hypr, 'notify::focused-workspace', function(self, workspace)
self:toggle_class_name('focused', workspace:get_id() == i)
end)
self:hook(hypr, 'notify::workspaces', function(self, workspaces)
map(workspaces, function(workspace)
local function update()
local workspaces = hypr:get_workspaces()
for _,workspace in ipairs(workspaces) do
if workspace:get_id() == i then
-- ick
local count = 0
for _ in ipairs(workspace:get_clients()) do
local count = 0;
for _ in pairs(workspace:get_clients()) do
count = count + 1
end
self:toggle_class_name('occupied', workspace:get_id() == i and count > 0)
self:toggle_class_name('occupied', count > 0)
end
end)
end)
end
end
self:hook(hypr, 'notify::clients', update)
self:hook(hypr, 'notify::workspaces', update)
update()
end,
on_click_release = function()
hypr:message_async(string.format("dispatch workspace %d", i))
@ -41,6 +49,7 @@ return Widget.Box({
vertical = true,
hexpand = false,
halign = 'START',
valign = 'CENTER',
children = {
workspace_row(1, 5),
workspace_row(6, 10),