begin astal rewrite in lua; implement workspace widget in statusbar
This commit is contained in:
15
lua/globals.lua
Normal file
15
lua/globals.lua
Normal file
@ -0,0 +1,15 @@
|
||||
lgi = require('lgi')
|
||||
|
||||
astal = require("astal")
|
||||
|
||||
GLib = astal.GLib
|
||||
Gtk = astal.Gtk
|
||||
Gdk = astal.Gdk
|
||||
Gio = astal.Gio
|
||||
|
||||
Astal = astal.Astal
|
||||
Widget = astal.Widget
|
||||
|
||||
bind = astal.bind
|
||||
|
||||
Variable = astal.Variable
|
23
lua/lib/init.lua
Normal file
23
lua/lib/init.lua
Normal file
@ -0,0 +1,23 @@
|
||||
local M = {}
|
||||
|
||||
function M.map(tbl, f)
|
||||
local t = {}
|
||||
for k,v in pairs(tbl) do
|
||||
t[k] = f(v)
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
function M.sequence(start, stop)
|
||||
local t = {}
|
||||
for i=start,stop do
|
||||
table.insert(t, i)
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
function ternary(cond, t, f)
|
||||
if cond then return t else return f end
|
||||
end
|
||||
|
||||
return M
|
9
lua/widgets/bar/init.lua
Normal file
9
lua/widgets/bar/init.lua
Normal file
@ -0,0 +1,9 @@
|
||||
local workspaces <const> = require(... .. '.workspaces')
|
||||
|
||||
return Astal.Window({
|
||||
namespace = "bar",
|
||||
name = "bar",
|
||||
anchor = Astal.WindowAnchor.TOP + Astal.WindowAnchor.LEFT + Astal.WindowAnchor.RIGHT,
|
||||
exclusivity = "EXCLUSIVE",
|
||||
child = workspaces,
|
||||
})
|
48
lua/widgets/bar/workspaces.lua
Normal file
48
lua/widgets/bar/workspaces.lua
Normal file
@ -0,0 +1,48 @@
|
||||
local Hyprland <const> = astal.require("AstalHyprland")
|
||||
local map, sequence = require('lua.lib').map, require('lua.lib').sequence
|
||||
|
||||
local hypr = Hyprland.get_default()
|
||||
|
||||
local map, sequence = require('lua.lib').map, require('lua.lib').sequence
|
||||
|
||||
local hypr = Hyprland.get_default()
|
||||
|
||||
local function workspace_row(start, stop)
|
||||
return Widget.Box({
|
||||
children = map(sequence(start, stop), function(i)
|
||||
return Widget.Button({
|
||||
setup = function(self)
|
||||
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)
|
||||
if workspace:get_id() == i then
|
||||
-- ick
|
||||
local count = 0
|
||||
for _ in ipairs(workspace:get_clients()) do
|
||||
count = count + 1
|
||||
end
|
||||
self:toggle_class_name('occupied', workspace:get_id() == i and count > 0)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
end,
|
||||
on_click_release = function()
|
||||
hypr:message_async(string.format("dispatch workspace %d", i))
|
||||
end
|
||||
})
|
||||
end)
|
||||
})
|
||||
end
|
||||
|
||||
return Widget.Box({
|
||||
class_name = 'workspaces',
|
||||
vertical = true,
|
||||
hexpand = false,
|
||||
halign = 'START',
|
||||
children = {
|
||||
workspace_row(1, 5),
|
||||
workspace_row(6, 10),
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user