summaryrefslogtreecommitdiff
path: root/pkgs/astal/src/widget/bar/workspaces.lua
blob: 8bc17851fbea905b6037db593939bb468b6485f2 (plain)
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
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