add new widgets; rewrite workspace indicator
This commit is contained in:
parent
784e71e643
commit
d584d25194
33
lua/widgets/bar/battery.lua
Normal file
33
lua/widgets/bar/battery.lua
Normal 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
18
lua/widgets/bar/clock.lua
Normal 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')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
@ -1,9 +1,38 @@
|
|||||||
local workspaces <const> = require(... .. '.workspaces')
|
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({
|
return Astal.Window({
|
||||||
namespace = "bar",
|
namespace = "bar",
|
||||||
name = "bar",
|
name = "bar",
|
||||||
anchor = Astal.WindowAnchor.TOP + Astal.WindowAnchor.LEFT + Astal.WindowAnchor.RIGHT,
|
anchor = Astal.WindowAnchor.TOP + Astal.WindowAnchor.LEFT + Astal.WindowAnchor.RIGHT,
|
||||||
exclusivity = "EXCLUSIVE",
|
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
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
26
lua/widgets/bar/volume.lua
Normal file
26
lua/widgets/bar/volume.lua
Normal 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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
@ -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 map, sequence = require('lua.lib').map, require('lua.lib').sequence
|
||||||
|
|
||||||
local hypr = Hyprland.get_default()
|
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:hook(hypr, 'notify::focused-workspace', function(self, workspace)
|
||||||
self:toggle_class_name('focused', workspace:get_id() == i)
|
self:toggle_class_name('focused', workspace:get_id() == i)
|
||||||
end)
|
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
|
if workspace:get_id() == i then
|
||||||
-- ick
|
local count = 0;
|
||||||
local count = 0
|
|
||||||
for _ in ipairs(workspace:get_clients()) do
|
for _ in pairs(workspace:get_clients()) do
|
||||||
count = count + 1
|
count = count + 1
|
||||||
end
|
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)
|
end
|
||||||
|
|
||||||
|
self:hook(hypr, 'notify::clients', update)
|
||||||
|
self:hook(hypr, 'notify::workspaces', update)
|
||||||
|
|
||||||
|
update()
|
||||||
end,
|
end,
|
||||||
on_click_release = function()
|
on_click_release = function()
|
||||||
hypr:message_async(string.format("dispatch workspace %d", i))
|
hypr:message_async(string.format("dispatch workspace %d", i))
|
||||||
@ -41,6 +49,7 @@ return Widget.Box({
|
|||||||
vertical = true,
|
vertical = true,
|
||||||
hexpand = false,
|
hexpand = false,
|
||||||
halign = 'START',
|
halign = 'START',
|
||||||
|
valign = 'CENTER',
|
||||||
children = {
|
children = {
|
||||||
workspace_row(1, 5),
|
workspace_row(1, 5),
|
||||||
workspace_row(6, 10),
|
workspace_row(6, 10),
|
||||||
|
Loading…
Reference in New Issue
Block a user