diff --git a/lib/wlayout/site.reek b/lib/wlayout/site.reek new file mode 100644 index 0000000..2499b81 --- /dev/null +++ b/lib/wlayout/site.reek @@ -0,0 +1,5 @@ +--- +UncommunicativeVariableName: + enabled: false +UncommunicativeMethodName: + enabled: false diff --git a/lib/wlayout/windows.rb b/lib/wlayout/windows.rb index 822a107..aa6b55b 100644 --- a/lib/wlayout/windows.rb +++ b/lib/wlayout/windows.rb @@ -1,41 +1,82 @@ # -*- encoding: utf-8 -*- module WLayout + # Public: Position windows of a given workspace. class Windows def initialize workspace - # Trouver les fenêtres - @windows = WMCtrl.instance.windows - @windows = @windows.select { |i| i[:desktop] == workspace.id } - + @workspace = workspace + @wm = WMCtrl.instance + find_windows + position_master_window exit if @windows.empty? + position_remaining_windows + end - # Placer la fenêtre active (si il y en a une) en tête de liste - @windows.sort! { |x,y| y[:active] ? 1 : -1 } + private - # Trouver les futures coordonnées de la fenêtre maître - @master = @windows.slice!(0) - master_h_exterior = (workspace.h - workspace.y) / 2 - master_h = master_h_exterior - @master[:frame_extents][2] - @master[:frame_extents][3] - master_w = workspace.w - @master[:frame_extents][0] - @master[:frame_extents][1] - # Placer la fenêtre maître - WMCtrl.instance.action_window(@master[:id], :move_resize, 0, - workspace.x, workspace.y, - master_w, master_h) + def find_windows + @windows = windows_in_active_workspace + exit if @windows.empty? + put_active_window_on_top + end - # Trouver les futures coordonnées des autres fenêtres - real_w = workspace.w / @windows.count - x = workspace.x - y = workspace.y + master_h_exterior - @windows.each do |win| - w = real_w - win[:frame_extents][0]- win[:frame_extents][1] - h = workspace.h - (workspace.y + master_h_exterior) - win[:frame_extents][2]- win[:frame_extents][3] - WMCtrl.instance.action_window(win[:id], :move_resize, 0, x, y, w, h) - x += real_w + def windows_in_active_workspace + @wm.windows.select { |win| win[:desktop] == @workspace.id } end + def put_active_window_on_top + @windows.sort! { |x,y| y[:active] ? 1 : -1 } + end - end + def position_master_window + @master = get_master_window + calculate_master + move_resize_master + end + def get_master_window + @windows.slice!(0) + end + + def calculate_master + @master[:height_exterior] = (@workspace.height - @workspace.y) / 2 + ext = @master[:frame_extents] + @master[:height] = @master[:height_exterior] - ext[2] - ext[3] + @master[:width] = @workspace.width - ext[0] - ext[1] + end + + def move_resize_master + @wm.action_window(@master[:id], :move_resize, 0, @workspace.x, + @workspace.y, @master[:width], @master[:height]) + end + + def position_remaining_windows + @real_width = @workspace.width / @windows.count + @x = @workspace.x + @y = @workspace.y + @master[:height_exterior] + @windows.each { |win| position_window win } + end + + def position_window win + ext = win[:frame_extents] + width = get_win_width ext + height = get_win_height ext + move_resize_window win, width, height + @x += @real_width + end + + def get_win_width ext + @real_width - ext[0]- ext[1] + end + + def get_win_height ext + tmp = @workspace.y + @master[:height_exterior] + @workspace.height - tmp - ext[2] - ext[3] + end + + def move_resize_window win, width, height + @wm.action_window(win[:id], :move_resize, 0, @x, @y, width, height) + end end end diff --git a/lib/wlayout/workspace.rb b/lib/wlayout/workspace.rb index 6c6d528..11b0caf 100644 --- a/lib/wlayout/workspace.rb +++ b/lib/wlayout/workspace.rb @@ -1,23 +1,36 @@ # -*- encoding: utf-8 -*- module WLayout + # Public: Current workspace (virtual desktop) state. class Workspace - attr_reader :id, :x, :y, :w, :h + attr_reader :id def initialize - desktops = WMCtrl.instance.desktops - desktops.each do |d| - if d[:current] - @id = d[:id] - @x = d[:workarea][0] - @y = d[:workarea][1] - @w = d[:workarea][2] - @h = d[:workarea][3] + @desktops = WMCtrl.instance.desktops + @desktops.each do |desktop| + if desktop[:current] + @id = desktop[:id] break end end end + def x + @desktops[@id][:workarea][0] + end + + def y + @desktops[@id][:workarea][1] + end + + def width + @desktops[@id][:workarea][2] + end + + def height + @desktops[@id][:workarea][3] + end + end end diff --git a/reek.sed b/reek.sed old mode 100644 new mode 100755