mirror of
https://github.com/vidarh/rubywm.git
synced 2024-09-28 03:21:18 +02:00
Mostly for documentation, gave tiled/floating layout a base class and made some methods private
This commit is contained in:
parent
aa14a824cf
commit
9c7f44497a
3 changed files with 23 additions and 9 deletions
|
@ -1,8 +1,10 @@
|
|||
#
|
||||
# Apart from the very limited "place" the main purpose of this
|
||||
# class is to ensure there *always* is a layout
|
||||
#
|
||||
class FloatingLayout
|
||||
|
||||
require_relative 'layout'
|
||||
|
||||
class FloatingLayout < Layout
|
||||
|
||||
def initialize(rootgeom)
|
||||
@rootgeom = rootgeom
|
||||
|
@ -23,6 +25,4 @@ class FloatingLayout
|
|||
y = (@rootgeom.height - height)/2 if y == 0
|
||||
w.configure(x:, y:, width:, height:)
|
||||
end
|
||||
|
||||
def call = nil
|
||||
end
|
||||
|
|
11
layout.rb
Normal file
11
layout.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
# Public Layout interface
|
||||
|
||||
class Layout
|
||||
def call(focus=nil) = nil
|
||||
def find(window) = nil
|
||||
def find(window, focus=nil, dir=nil) = nil
|
||||
def place(window) = nil
|
||||
|
||||
def layout(...) = call(...)
|
||||
end
|
13
tiled.rb
13
tiled.rb
|
@ -4,8 +4,9 @@ GAP = 64
|
|||
require_relative 'geom.rb'
|
||||
require_relative 'leaf.rb'
|
||||
require_relative 'node.rb'
|
||||
require_relative 'layout'
|
||||
|
||||
class TiledLayout
|
||||
class TiledLayout < Layout
|
||||
attr_reader :root
|
||||
|
||||
def initialize(desktop, geom)
|
||||
|
@ -17,12 +18,8 @@ class TiledLayout
|
|||
@root = Node.new(dir: :lr)
|
||||
end
|
||||
|
||||
def windows = @desktop.children.find_all{|w| w.mapped && !w.floating?}
|
||||
def cleanup = (@root = Node(@root.keep(windows)))
|
||||
def find(w) = @root.find(w)
|
||||
|
||||
def apply_placements(window) = @root.placements.any? { _1.accept(window) }
|
||||
|
||||
def place(window, focus=nil, dir=nil)
|
||||
return if apply_placements(window)
|
||||
return @root.place(window) if !focus
|
||||
|
@ -42,4 +39,10 @@ class TiledLayout
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue