Module: RMonitor::XRandRWriteHelpers

Included in:
Profiles
Defined in:
lib/rmonitor/helpers/xrandr_write_helpers.rb

Instance Method Summary collapse

Instance Method Details

#turn_off(device) ⇒ Object



3
4
5
# File 'lib/rmonitor/helpers/xrandr_write_helpers.rb', line 3

def turn_off(device)
  "--output #{device} --off"
end

#turn_on(device, options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rmonitor/helpers/xrandr_write_helpers.rb', line 7

def turn_on(device, options)
  on = '--output %s --mode %s --rate %s' % [
      device,
      options[:mode],
      options[:rate],
  ]

  if options[:pos]
    on << ' --pos '      << options[:pos]
  elsif options[:left_of]
    on << ' --left-of '  << options[:left_of]
  elsif options[:right_of]
    on << ' --right-of ' << options[:right_of]
  elsif options[:above]
    on << ' --above '    << options[:above]
  elsif options[:below]
    on << ' --below '    << options[:below]
  elsif options[:same_as]
    on << ' --same-as '  << options[:same_as]
  end

  if options[:rotate]
    allowed_options = %w(normal inverted left right)

    if allowed_options.include?(options[:rotate])
      on << ' --rotate ' << options[:rotate]
    else
      raise XRandRArgumentError.new("Invalid argument for --rotate")
    end
  end

  if options[:reflect]
    allowed_options = %w(normal x y xy)

    if allowed_options.include?(options[:reflect])
      on << ' --reflect ' << options[:reflect]
    else
      raise XRandRArgumentError.new("Invalid argument for --reflect")
    end
  end

  if options[:primary]
    on << ' --primary'
  end

  on
end