Class: Swm::MoveCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/swm/commands/move_command.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ MoveCommand

Returns a new instance of MoveCommand.



27
28
29
# File 'lib/swm/commands/move_command.rb', line 27

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



25
26
27
# File 'lib/swm/commands/move_command.rb', line 25

def options
  @options
end

Class Method Details



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/swm/commands/move_command.rb', line 10

def self.print_help
  puts <<-EOF
Usage: swm move <options>
Options:
  --x: Percentage of free screen width
  --y: Percentage of free screen height
Examples:
  Center the window
swm resize --x 50 --y 50
  Move the window to the top-right corner
swm resize --x 100 --y 0

  EOF
end

.run(options) ⇒ Object



6
7
8
# File 'lib/swm/commands/move_command.rb', line 6

def self.run(options)
  new(options).run
end

Instance Method Details

#runObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/swm/commands/move_command.rb', line 31

def run
  x_percent = options[:x]
  y_percent = options[:y]

  screen_dimensions = Screen.dimensions
  window = Swm::Window.current

  x = ((screen_dimensions[0] - window.width) * x_percent / 100.0).to_i
  y = ((screen_dimensions[1] - window.height) * y_percent / 100.0).to_i

  window.move x, y
end