dotfiles
My PC Dotfiles & Websitegit clone https://github.com/maydayv7/dotfiles
files/noctalia/hypr-layout/layout.luau (2403B)
1-- Hyprland Layout Indicator bar widget
2
3local scrollGlyph = noctalia.getConfig("scroll_glyph")
4local dwindleGlyph = noctalia.getConfig("dwindle_glyph")
5local floatGlyph = noctalia.getConfig("float_glyph")
6
7local command = noctalia.getConfig("command")
8local layoutCommand = noctalia.getConfig("layout_command")
9local floatCommand = noctalia.getConfig("float_command")
10
11local state = {
12 layout = "scrolling",
13 allFloat = false,
14}
15
16local function render()
17 if state.allFloat then
18 barWidget.setGlyph(floatGlyph)
19 barWidget.setTooltip(noctalia.tr("float"))
20 elseif state.layout == "dwindle" then
21 barWidget.setGlyph(dwindleGlyph)
22 barWidget.setTooltip(noctalia.tr("dwindle"))
23 else
24 barWidget.setGlyph(scrollGlyph)
25 barWidget.setTooltip(noctalia.tr("scrolling"))
26 end
27 barWidget.setText("")
28 barWidget.setVisible(true)
29end
30
31local function refreshLayout()
32 if layoutCommand == nil or layoutCommand == "" then
33 return
34 end
35 noctalia.runAsync(layoutCommand, function(result)
36 local out = result.stdout or ""
37 if string.find(out, "dwindle", 1, true) then
38 state.layout = "dwindle"
39 else
40 state.layout = "scrolling"
41 end
42 render()
43 end)
44end
45
46local function refreshFloat()
47 if floatCommand == nil or floatCommand == "" then
48 return
49 end
50 noctalia.runAsync(floatCommand, function(result)
51 local out = result.stdout or ""
52 state.allFloat = string.find(out, "true", 1, true) ~= nil
53 render()
54 end)
55end
56
57-- Static otherwise: slow periodic tick down
58function update()
59 noctalia.setUpdateInterval(60000)
60end
61
62-- Initialise from live compositor state, then render immediately
63refreshLayout()
64refreshFloat()
65render()
66
67if command ~= nil and command ~= "" then
68 noctalia.runStream(command, function(line)
69 -- Tiling layout is pushed explicitly by the layout-toggle keybind
70 local layout = string.match(line, "^custom>>layout:(%S+)$")
71 if layout ~= nil then
72 state.layout = layout
73 render()
74 return
75 end
76
77 -- The float toggle asks for an explicit re-check
78 if string.match(line, "^custom>>floatcheck$") ~= nil then
79 refreshFloat()
80 return
81 end
82
83 if string.match(line, "^openwindow>>") ~= nil
84 or string.match(line, "^closewindow>>") ~= nil
85 or string.match(line, "^movewindow>>") ~= nil
86 or string.match(line, "^workspace>>") ~= nil
87 then
88 refreshFloat()
89 end
90 end)
91end