2024-01-03 06:12:18 +01:00
|
|
|
|
|
|
|
GAP = 64
|
|
|
|
|
|
|
|
require_relative 'geom.rb'
|
|
|
|
require_relative 'leaf.rb'
|
|
|
|
require_relative 'node.rb'
|
|
|
|
|
|
|
|
class TiledLayout
|
|
|
|
attr_reader :root
|
|
|
|
|
|
|
|
def initialize(desktop, geom)
|
|
|
|
@desktop = desktop
|
|
|
|
@geom = geom.dup
|
|
|
|
# FIXME: This is to account for a bar, but we shouldn't just assume
|
|
|
|
# the height here
|
|
|
|
@geom.height -= 30
|
|
|
|
@root = Node.new(dir: :lr)
|
|
|
|
end
|
|
|
|
|
2024-01-13 19:55:59 +01:00
|
|
|
def windows = @desktop.children.find_all{|w| w.mapped && !w.floating?}
|
2024-01-03 06:12:18 +01:00
|
|
|
def cleanup = (@root = Node(@root.keep(windows)))
|
|
|
|
def find(w) = @root.find(w)
|
|
|
|
|
2024-01-21 22:15:30 +01:00
|
|
|
def apply_placements(window) = @root.placements.any? { _1.accept(window) }
|
2024-01-19 21:12:47 +01:00
|
|
|
|
2024-01-21 01:15:59 +01:00
|
|
|
def place(window, focus=nil, dir=nil)
|
|
|
|
return if apply_placements(window)
|
|
|
|
return @root.place(window) if !focus
|
2024-01-19 21:12:47 +01:00
|
|
|
leaf = self.find(focus)
|
2024-01-21 01:33:10 +01:00
|
|
|
leaf&.parent&.place_adjacent(window, leaf, dir) || @root.place(window)
|
2024-01-19 21:12:47 +01:00
|
|
|
call
|
|
|
|
end
|
2024-01-03 06:12:18 +01:00
|
|
|
|
|
|
|
def call
|
2024-01-21 01:15:59 +01:00
|
|
|
new_windows = windows - @root.children
|
2024-01-03 06:12:18 +01:00
|
|
|
cleanup
|
2024-01-21 01:15:59 +01:00
|
|
|
new_windows.each { place(_1) }
|
|
|
|
g = GAP/(1.3 ** @root.children.length)
|
2024-01-03 06:12:18 +01:00
|
|
|
@root.layout(gap(@geom,g), g)
|
|
|
|
end
|
|
|
|
end
|