-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtiled.rb
More file actions
48 lines (39 loc) · 1.12 KB
/
tiled.rb
File metadata and controls
48 lines (39 loc) · 1.12 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
GAP = 64
require_relative 'geom.rb'
require_relative 'leaf.rb'
require_relative 'node.rb'
require_relative 'layout'
class TiledLayout < Layout
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
def find(w) = @root.find(w)
def place(window, focus=nil, dir=nil)
return if apply_placements(window)
return @root.place(window) if !focus
leaf = self.find(focus)
if leaf && leaf.parent
leaf.parent.place_adjacent(window, leaf, dir)
else @root.place(window)
end
call
true
end
def call(focus=nil)
new_windows = windows - @root.children
cleanup
new_windows.each { place(_1,focus) }
g = GAP/(1.3 ** @root.children.length)
@root.layout(gap(@geom,g), g)
end
private
def windows = @desktop.children.find_all{|w| w.mapped && !w.floating?}
def cleanup = (@root = Node(@root.keep(windows)))
def apply_placements(window) = @root.placements.any? { _1.accept(window) }
end