Class: Dumon::OutDeviceManager

Inherits:
Object
  • Object
show all
Includes:
Rrutils::Options
Defined in:
lib/dumon/omanager.rb

Overview

This class represents a base class defining how concrete sub-classes manage output devices available on your system.

Direct Known Subclasses

XrandrManager

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Rrutils::Options

#assert, #keys_to_sym, #verify_and_sanitize_options, #verify_options

Instance Attribute Details

#outputsObject (readonly)

Cached information about current output devices. Value will be updated by each invocation of #read.

Format: href="...">default=>“AxB”,:current=>“CxD”,:resolutions=>, … Sample:

"LVDS1"=>{:resolutions=>["1600x900", "1024x768"], :default=>"1600x900",
"VGA1" =>"720x400"], :default=>"1920x1080", :current=>"1920x1080"
      }


22
23
24
# File 'lib/dumon/omanager.rb', line 22

def outputs
  @outputs
end

#stoolObject (readonly)

System tool to be used for output devices management.



11
12
13
# File 'lib/dumon/omanager.rb', line 11

def stool
  @stool
end

Instance Method Details

#common_resolutionsObject

Gets list of common resolutions of all output devices.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/dumon/omanager.rb', line 106

def common_resolutions
  assert(!outputs.nil?, 'no outputs found')

  rslt = []
  o1 = outputs.keys.first
  outputs[o1][:resolutions].each do |res|
    outputs.keys.each do |o|
      next if o === o1
      rslt << res if outputs[o][:resolutions].include?(res)
    end
  end

  rslt
end

#default_resolution(output) ⇒ Object

Gets default resolution of given output device.



96
97
98
99
100
101
102
# File 'lib/dumon/omanager.rb', line 96

def default_resolution(output)
  assert(!outputs.nil?, 'no outputs found')
  assert(outputs.keys.include?(output), "unknown output: #{output}")
  assert(outputs[output].keys.include?(:default), "no default resolution, output: #{output}")

  outputs[output][:default]
end

#readObject

Reads info about current accessible output devices and their settings. Readed infos will be stored and accessible via reader ‘outputs’.

Raises:

  • (NotImplementedError)


90
91
92
# File 'lib/dumon/omanager.rb', line 90

def read
  raise NotImplementedError, 'this should be overridden by concrete sub-class'
end

#resetObject

Resets output to the first one delivered by the underlaying system tool and switches to its default resolution.



81
82
83
84
85
# File 'lib/dumon/omanager.rb', line 81

def reset
  assert(!outputs.nil?, 'no outputs found')
  out = outputs.keys.first
  switch :mode => :single, :out => out, :resolution => default_resolution(out)
end

#switch(options) ⇒ Object

Switches output according to given mode and corresponding parameters.

Possible options:

Single output: :out=>‘VGA1’, :resolution=>‘1600x900’ Mirrored outputs: :resolution=>‘1600x900’ Sequence of outputs: :outs=>[‘VGA1’, ‘LVDS1’], :resolutions=>[‘1920x1080’, ‘1600x900’], :primary=>:none



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/dumon/omanager.rb', line 35

def switch(options)
  # pre-conditions
  verify_options(options, {
    :mode => [:single, :mirror, :hsequence, :vsequence],
    :out => :optional, :outs => :optional,
    :resolution => :optional, :resolutions => :optional,
    :primary => :optional
  })

  mode = options[:mode].to_sym

  case mode
  when :single
    verify_options(options, {:mode => [:single], :out => outputs.keys, :resolution => :optional})
    out_name = options[:out]
    # given resolution exists for given output
    unless options[:resolution].nil?
      assert(outputs[out_name][:resolutions].include?(options[:resolution]),
          "unknown resolution: #{options[:resolution]}, output: #{out_name}")
    end
    single(out_name, options[:resolution])
  when :mirror
    verify_options(options, {:mode => [:mirror], :resolution => :mandatory})
    # given resolution exist for all outputs
    outputs.each do |k,v|
      assert(v[:resolutions].include?(options[:resolution]), "unknown resolution: #{options[:resolution]}, output: #{k}")
    end
    mirror(options[:resolution])
  when :hsequence, :vsequence
    verify_options(options, {:mode => [:hsequence, :vsequence], :outs => :mandatory, :resolutions => :mandatory, :primary => :optional})
    assert(options[:outs].is_a?(Array), 'parameter :outs has to be Array')
    assert(options[:resolutions].is_a?(Array), 'parameter :resolutions has to be Array')
    assert(options[:outs].size == options[:resolutions].size, 'size of :outs and :resolutions does not match')
    assert(options[:outs].size > 1, 'sequence mode expects at least 2 outputs')
    if !options[:primary].nil? and options[:primary].to_sym != :none
      assert(outputs.keys.include?(options[:primary]), "unknown primary output: #{options[:primary]}")
    end
    sequence(options[:outs], options[:resolutions], options[:primary], :hsequence === options[:mode])
  end

  Dumon::App.instance.current_profile = options
end