Class: Dumon::OutDeviceManager
- Inherits:
-
Object
- Object
- Dumon::OutDeviceManager
- 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
Instance Attribute Summary collapse
-
#outputs ⇒ Object
readonly
Cached information about current output devices.
-
#stool ⇒ Object
readonly
System tool to be used for output devices management.
Instance Method Summary collapse
-
#common_resolutions ⇒ Object
Gets list of common resolutions of all output devices.
-
#default_resolution(output) ⇒ Object
Gets default resolution of given output device.
-
#read ⇒ Object
Reads info about current accessible output devices and their settings.
-
#reset ⇒ Object
Resets output to the first one delivered by the underlaying system tool and switches to its default resolution.
-
#switch(options) ⇒ Object
Switches output according to given mode and corresponding parameters.
Methods included from Rrutils::Options
#assert, #keys_to_sym, #verify_and_sanitize_options, #verify_options
Instance Attribute Details
#outputs ⇒ Object (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 |
#stool ⇒ Object (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_resolutions ⇒ Object
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 |
#read ⇒ Object
Reads info about current accessible output devices and their settings. Readed infos will be stored and accessible via reader ‘outputs’.
90 91 92 |
# File 'lib/dumon/omanager.rb', line 90 def read raise NotImplementedError, 'this should be overridden by concrete sub-class' end |
#reset ⇒ Object
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() # pre-conditions (, { :mode => [:single, :mirror, :hsequence, :vsequence], :out => :optional, :outs => :optional, :resolution => :optional, :resolutions => :optional, :primary => :optional }) mode = [:mode].to_sym case mode when :single (, {:mode => [:single], :out => outputs.keys, :resolution => :optional}) out_name = [:out] # given resolution exists for given output unless [:resolution].nil? assert(outputs[out_name][:resolutions].include?([:resolution]), "unknown resolution: #{[:resolution]}, output: #{out_name}") end single(out_name, [:resolution]) when :mirror (, {:mode => [:mirror], :resolution => :mandatory}) # given resolution exist for all outputs outputs.each do |k,v| assert(v[:resolutions].include?([:resolution]), "unknown resolution: #{[:resolution]}, output: #{k}") end mirror([:resolution]) when :hsequence, :vsequence (, {:mode => [:hsequence, :vsequence], :outs => :mandatory, :resolutions => :mandatory, :primary => :optional}) assert([:outs].is_a?(Array), 'parameter :outs has to be Array') assert([:resolutions].is_a?(Array), 'parameter :resolutions has to be Array') assert([:outs].size == [:resolutions].size, 'size of :outs and :resolutions does not match') assert([:outs].size > 1, 'sequence mode expects at least 2 outputs') if ![:primary].nil? and [:primary].to_sym != :none assert(outputs.keys.include?([:primary]), "unknown primary output: #{[:primary]}") end sequence([:outs], [:resolutions], [:primary], :hsequence === [:mode]) end Dumon::App.instance.current_profile = end |