thornWM/lib/tree/init.lua
2025-05-23 15:41:23 +00:00

85 lines
2.2 KiB
Lua

-- This source code form is subject to the terms of the MPL-v2 https://mozilla.org/MPL/2.0/ --
--* .name Manages the tree structure that holds all monitors, containers, windows, and tags
local X = require("x")
local EWMH = require("ewmh")
local Conf = require("conf")
local Tree = {
windows = {},
monitors = {},
focusedWindow = nil,
focusedMonitor = nil,
-- tags = {},
}
-- local Tag = require("tree.tag")
local Window = require("tree.window")
function Tree.newWindow(ev)
local win = Window.new(ev.id)
if EWMH.shouldManage(win) then
Tree.windows[win.id] = win
win.managed = true
if EWMH.shouldTile(win) then
table.insert(Tree.focusedMonitor.stack, win)
win.monitor = Tree.focusedMonitor
-- Tree.focusedMonitor:updateTiling()
else
win:float()
end
win:show()
else
win.managed = false
win:show()
return
end
return win
end
----* table tag Tree.newTag(any id, [table preset]) Creates a new tag that can then be added to tables. New tags are also initialised automatically with *Window*:*addTag*()
--function Tree.newTag(id, tbl)
-- if Tree.tags[id] then return Tree.tags[id] end
-- local tag = Tag.new(tbl)
-- tag.id = id
-- Tree.tags[id] = tag
-- return tag
--end
--* Tree.init() Sets up the tree
function Tree.init()
Window.init()
for m,monitor in pairs(X.getMonitors()) do
Tree.monitors[m] = monitor
monitor.number = m
monitor.stack = {}
monitor.dockMargins = { top = 0, bottom = 0, left = 0, right = 0 }
monitor.margins = { top = 5, bottom = 5, left = 5, right = 5 }
function monitor:updateTiling()
if self.tiler then
self.tiler:tile(self.stack, self)
end
end
function monitor:setMargins(m)
print("привет", inspect(m))
self.margins.top = m.top + self.dockMargins.top
self.margins.bottom = m.bottom + self.dockMargins.bottom
self.margins.right = m.right + self.dockMargins.right
self.margins.left = m.left + self.dockMargins.left
end
if Conf.eventHandlers.newMonitor then
Conf.eventHandlers.newMonitor(monitor)
end
end
Tree.focusedMonitor = Tree.monitors[1]
-- Tree.newTag("focused")
end
-- function Tree.updateDirty()
-- if Tree.dirtyGeometry then
-- for w,win in pairs(Tree.windows) do
-- if win.dirtyGeometry then
-- win:applyGeometry()
-- end
-- end
-- end
-- end
return Tree