Class: Xrandr::Control

Inherits:
Object
  • Object
show all
Defined in:
lib/xrandr.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parser = Parser.new) ⇒ Control

Returns a new instance of Control.



7
8
9
10
# File 'lib/xrandr.rb', line 7

def initialize(parser = Parser.new)
  @screens, @outputs = * parser.parse
  @command = 'xrandr'
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



5
6
7
# File 'lib/xrandr.rb', line 5

def command
  @command
end

#outputsObject (readonly)

Returns the value of attribute outputs.



5
6
7
# File 'lib/xrandr.rb', line 5

def outputs
  @outputs
end

#screensObject (readonly)

Returns the value of attribute screens.



5
6
7
# File 'lib/xrandr.rb', line 5

def screens
  @screens
end

Instance Method Details

#apply!Object



35
36
37
38
# File 'lib/xrandr.rb', line 35

def apply!
  Kernel.system(command)
  initialize
end

#configure(output = nil, **options) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/xrandr.rb', line 12

def configure(output = nil, **options)
  output = find_output(output) if output

  command << " --output #{output.name}" if output
  command << options.map do |option, value|
    value = nil if value == true
    " --#{option} #{value}".rstrip
  end.join(' ')
end

#find_output(output) ⇒ Object Also known as: []



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/xrandr.rb', line 22

def find_output(output)
  if output.kind_of? Output
    output
  elsif output.kind_of? String
    outputs.find {|o| o.name == output}
  elsif output.kind_of? Integer
    outputs[output]
  else
    raise ArgumentError, "Expecting a string, an integer or an Xrandr::Output instance"
  end
end