class Swm::ResizeCommand

Attributes

options[R]

Public Class Methods

new(options) click to toggle source
# File lib/swm/commands/resize_command.rb, line 30
def initialize(options)
  @options = options
end
print_help() click to toggle source
run(options) click to toggle source
# File lib/swm/commands/resize_command.rb, line 6
def self.run(options)
  new(options).run
end

Public Instance Methods

run() click to toggle source
# File lib/swm/commands/resize_command.rb, line 34
def run
  screen_dimensions = Screen.dimensions
  rect = [0, 0, screen_dimensions[0], screen_dimensions[1]]
  set_offset(rect)
  resize_in_rect(rect)
end

Private Instance Methods

resize_in_rect(rect) click to toggle source
# File lib/swm/commands/resize_command.rb, line 52
def resize_in_rect(rect)
  x_percent = options[:x]
  y_percent = options[:y]
  width_percent = options[:width]
  height_percent = options[:height]

  x =       (rect[0] + rect[2] * x_percent / 100.0).to_i
  y =       (rect[1] + rect[3] * y_percent / 100.0).to_i
  width =   (rect[2] * width_percent / 100.0).to_i
  height =  (rect[3] * height_percent / 100.0).to_i

  window = Window.current
  window.set x, y, width, height
end
set_offset(rect) click to toggle source
# File lib/swm/commands/resize_command.rb, line 43
def set_offset(rect)
  rect[0] += options[:left] || 0
  rect[2] -= options[:left] || 0
  rect[1] += options[:top] || 0
  rect[3] -= options[:top] || 0
  rect[2] -= options[:right] || 0
  rect[3] -= options[:bottom] || 0
end