diff options
Diffstat (limited to 'pkgs/astal/src/widget')
-rw-r--r-- | pkgs/astal/src/widget/bar/audio.lua | 20 | ||||
-rw-r--r-- | pkgs/astal/src/widget/bar/battery.lua | 21 | ||||
-rw-r--r-- | pkgs/astal/src/widget/bar/date.lua | 18 | ||||
-rw-r--r-- | pkgs/astal/src/widget/bar/focusedClient.lua | 29 | ||||
-rw-r--r-- | pkgs/astal/src/widget/bar/init.lua | 44 | ||||
-rw-r--r-- | pkgs/astal/src/widget/bar/tray.lua | 34 | ||||
-rw-r--r-- | pkgs/astal/src/widget/bar/wifi.lua | 24 | ||||
-rw-r--r-- | pkgs/astal/src/widget/bar/workspaces.lua | 28 | ||||
-rw-r--r-- | pkgs/astal/src/widget/corners.lua | 19 |
9 files changed, 237 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 diff --git a/pkgs/astal/src/widget/corners.lua b/pkgs/astal/src/widget/corners.lua new file mode 100644 index 0000000..d1a7755 --- /dev/null +++ b/pkgs/astal/src/widget/corners.lua @@ -0,0 +1,19 @@ +local astal = require("astal") +local Widget = require("astal.gtk3.widget") + +return function(gdkmonitor) + local Anchor = astal.require('Astal').WindowAnchor + + return Widget.Window({ + class_name = "corners", + gdkmonitor = gdkmonitor, + anchor = Anchor.TOP + Anchor.BOTTOM + Anchor.LEFT + Anchor.RIGHT, + exclusivity = "EXCLUSIVE", + setup = function(self) + self.click_through = true + end, + Widget.Box({ + expand = true, + }) + }) +end |