summaryrefslogtreecommitdiff
path: root/pkgs/astal/src/widget/bar
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-06-17 15:14:45 -0400
committerFreya Murphy <freya@freyacat.org>2025-06-17 15:14:45 -0400
commit1173df26fd78fdd59679645004847237ed7a0a54 (patch)
treeb75e6bd3ee1a878b1a3e74d94fb9ea0bb94c14a7 /pkgs/astal/src/widget/bar
parentadd upowerd (diff)
downloaddotfiles-nix-1173df26fd78fdd59679645004847237ed7a0a54.tar.gz
dotfiles-nix-1173df26fd78fdd59679645004847237ed7a0a54.tar.bz2
dotfiles-nix-1173df26fd78fdd59679645004847237ed7a0a54.zip
add astal package, update flake to support packages
Diffstat (limited to 'pkgs/astal/src/widget/bar')
-rw-r--r--pkgs/astal/src/widget/bar/audio.lua20
-rw-r--r--pkgs/astal/src/widget/bar/battery.lua21
-rw-r--r--pkgs/astal/src/widget/bar/date.lua18
-rw-r--r--pkgs/astal/src/widget/bar/focusedClient.lua29
-rw-r--r--pkgs/astal/src/widget/bar/init.lua44
-rw-r--r--pkgs/astal/src/widget/bar/tray.lua34
-rw-r--r--pkgs/astal/src/widget/bar/wifi.lua24
-rw-r--r--pkgs/astal/src/widget/bar/workspaces.lua28
8 files changed, 218 insertions, 0 deletions
diff --git a/pkgs/astal/src/widget/bar/audio.lua b/pkgs/astal/src/widget/bar/audio.lua
new file mode 100644
index 0000000..c1934f9
--- /dev/null
+++ b/pkgs/astal/src/widget/bar/audio.lua
@@ -0,0 +1,20 @@
+local astal = require("astal")
+local Widget = require("astal.gtk3.widget")
+local Wp = astal.require("AstalWp")
+local bind = astal.bind
+
+return function()
+ local speaker = Wp.get_default().audio.default_speaker
+
+ return Widget.Box({
+ class_name = "audio",
+ Widget.Icon({
+ icon = bind(speaker, "volume-icon"),
+ }),
+ Widget.Label({
+ label = bind(speaker, "volume"):as(function(p)
+ return tostring(math.floor(p * 100)) .. '%'
+ end)
+ }),
+ })
+end
diff --git a/pkgs/astal/src/widget/bar/battery.lua b/pkgs/astal/src/widget/bar/battery.lua
new file mode 100644
index 0000000..d13143a
--- /dev/null
+++ b/pkgs/astal/src/widget/bar/battery.lua
@@ -0,0 +1,21 @@
+local astal = require("astal")
+local Widget = require("astal.gtk3.widget")
+local Battery = astal.require("AstalBattery")
+local bind = astal.bind
+
+return function()
+ 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
diff --git a/pkgs/astal/src/widget/bar/date.lua b/pkgs/astal/src/widget/bar/date.lua
new file mode 100644
index 0000000..b64d8bb
--- /dev/null
+++ b/pkgs/astal/src/widget/bar/date.lua
@@ -0,0 +1,18 @@
+local astal = require("astal")
+local Widget = require("astal.gtk3.widget")
+local Variable = astal.Variable
+local GLib = astal.require("GLib")
+
+local format = "%Y-%m-%d %a %H:%M:%S"
+local date = Variable(""):poll(
+ 1000, function()
+ return GLib.DateTime.new_now_local():format(format)
+ end
+);
+
+return function()
+ return Widget.Label({
+ class_name = "date",
+ label = date(),
+ })
+end
diff --git a/pkgs/astal/src/widget/bar/focusedClient.lua b/pkgs/astal/src/widget/bar/focusedClient.lua
new file mode 100644
index 0000000..329cc4e
--- /dev/null
+++ b/pkgs/astal/src/widget/bar/focusedClient.lua
@@ -0,0 +1,29 @@
+local astal = require("astal")
+local Widget = require("astal.gtk3.widget")
+local Hyprland = astal.require("AstalHyprland")
+local bind = astal.bind
+
+local hypr = Hyprland.get_default()
+
+function Client(client)
+ -- sanity check
+ if not client then
+ return nil
+ end
+
+ return Widget.Label({
+ ellipsize = "END",
+ max_width_chars = 50,
+ label = bind(client, "title"):as(tostring),
+ })
+end
+
+return function()
+ local focused = bind(hypr, "focused-client")
+
+ return Widget.Box({
+ class_name = "focusedClient",
+ visible = focused,
+ focused:as(Client)
+ })
+end
diff --git a/pkgs/astal/src/widget/bar/init.lua b/pkgs/astal/src/widget/bar/init.lua
new file mode 100644
index 0000000..038ac90
--- /dev/null
+++ b/pkgs/astal/src/widget/bar/init.lua
@@ -0,0 +1,44 @@
+local astal = require("astal")
+local Widget = require("astal.gtk3.widget")
+
+local Workspaces = require("widget.bar.workspaces")
+local FocusedClient = require("widget.bar.focusedClient")
+local Date = require("widget.bar.date")
+local WiFi = require("widget.bar.wifi")
+local Audio = require("widget.bar.audio")
+local Battery = require("widget.bar.battery")
+local Tray = require("widget.bar.tray")
+
+return function(gdkmonitor)
+ local Anchor = astal.require('Astal').WindowAnchor
+
+ return Widget.Window({
+ class_name = "bar",
+ gdkmonitor = gdkmonitor,
+ anchor = Anchor.TOP + Anchor.LEFT + Anchor.RIGHT,
+ exclusivity = "EXCLUSIVE",
+ Widget.CenterBox({
+ Widget.Box({
+ class_name = "left",
+ halign = "START",
+ hexpand = true,
+ Workspaces(),
+ FocusedClient(),
+ }),
+ Widget.Box({
+ class_name = "center",
+ hexpand = true,
+ Date(),
+ }),
+ Widget.Box({
+ class_name = "right",
+ halign = "END",
+ hexpand = true,
+ WiFi(),
+ Audio(),
+ Battery(),
+ Tray(),
+ }),
+ })
+ })
+end
diff --git a/pkgs/astal/src/widget/bar/tray.lua b/pkgs/astal/src/widget/bar/tray.lua
new file mode 100644
index 0000000..9046494
--- /dev/null
+++ b/pkgs/astal/src/widget/bar/tray.lua
@@ -0,0 +1,34 @@
+local astal = require("astal")
+local Widget = require("astal.gtk3.widget")
+local Tray = astal.require("AstalTray")
+local lib = require("lib")
+local bind = astal.bind
+
+function Item(item)
+ return Widget.MenuButton({
+ class_name = "menubtn",
+ 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({
+ gicon = bind(item, "gicon"),
+ }),
+ })
+end
+
+function Items(items)
+ return lib.map(items, Item)
+end
+
+return function()
+ local tray = Tray.get_default()
+
+ return Widget.Box({
+ class_name = "tray",
+ visible = bind(tray, "items"):as(lib.empty):as(lib.neg),
+ bind(tray, "items"):as(Items)
+ })
+end
diff --git a/pkgs/astal/src/widget/bar/wifi.lua b/pkgs/astal/src/widget/bar/wifi.lua
new file mode 100644
index 0000000..7a293a0
--- /dev/null
+++ b/pkgs/astal/src/widget/bar/wifi.lua
@@ -0,0 +1,24 @@
+local astal = require("astal")
+local Widget = require("astal.gtk3.widget")
+local Network = astal.require("AstalNetwork")
+local bind = astal.bind
+
+return function()
+ local network = Network.get_default()
+ local wifi = bind(network, "wifi")
+
+ return Widget.Box({
+ class_name = "wifi",
+ visible = wifi,
+ wifi:as(function(wifi)
+ return Widget.Box({
+ Widget.Icon({
+ icon = bind(wifi, "icon-name"),
+ }),
+ Widget.Label({
+ label = bind(wifi, "ssid"),
+ }),
+ })
+ end),
+ })
+end
diff --git a/pkgs/astal/src/widget/bar/workspaces.lua b/pkgs/astal/src/widget/bar/workspaces.lua
new file mode 100644
index 0000000..8bc1785
--- /dev/null
+++ b/pkgs/astal/src/widget/bar/workspaces.lua
@@ -0,0 +1,28 @@
+local astal = require("astal")
+local Widget = require("astal.gtk3.widget")
+local Hyprland = astal.require("AstalHyprland")
+local lib = require('lib')
+local bind = astal.bind
+
+local hypr = Hyprland.get_default()
+
+function Workspace(ws)
+ return Widget.Button({
+ class_name = bind(hypr, "focused-workspace"):as(function(fw)
+ return "workspace " .. (fw == ws and "primary" or "")
+ end),
+ on_clicked = function() ws:focus() end,
+ label = ws.id,
+ })
+end
+
+function Workspaces(wss)
+ return lib.map(lib.sort(wss, 'id'), Workspace)
+end
+
+return function()
+ return Widget.Box({
+ class_name = "workspaces",
+ bind(hypr, "workspaces"):as(Workspaces)
+ })
+end