class Dumon::OutDeviceManager
This class represents a base class defining how concrete sub-classes manage output devices available on your system.
Attributes
Cached information about current output devices. Value will be updated by each invocation of read
.
Format: {output_name=>{:default=>“AxB”,:current=>“CxD”,:resolutions=>, …} Sample: {
"LVDS1"=>{:resolutions=>["1600x900", "1024x768"], :default=>"1600x900"}, "VGA1" =>{:resolutions=>["1920x1080", "720x400"], :default=>"1920x1080", :current=>"1920x1080"} }
System tool to be used for output devices management.
Public Instance Methods
Gets list of common resolutions of all output devices.
# File lib/dumon/omanager.rb, line 113 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
Gets default resolution of given output device.
# File lib/dumon/omanager.rb, line 103 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
Reads info about current accessible output devices and their settings. Readed infos will be stored and accessible via reader ‘outputs’.
# File lib/dumon/omanager.rb, line 97 def read raise NotImplementedError, 'this should be overridden by concrete sub-class' end
Resets output to the first one delivered by the underlaying system tool and switches to its default resolution.
# File lib/dumon/omanager.rb, line 88 def reset assert(!outputs.nil?, 'no outputs found') out = outputs.keys.first switch :mode => :single, :out => out, :resolution => default_resolution(out) end
Switches output according to given mode and corresponding parameters.
Possible options:
Single output: {:mode=>:single, :out=>‘VGA1’, :resolution=>‘1600x900’} Mirrored outputs: {:mode=>:mirror, :resolution=>‘1600x900’} Sequence of outputs: {:mode=>:hsequence, :outs=>[‘VGA1’, ‘LVDS1’], :resolutions=>[‘1920x1080’, ‘1600x900’], :primary=>:none}
# 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 # post switch action dumon_conf = Dumon::App.instance.read_config if dumon_conf.include? :post_switch job = fork { exec dumon_conf[:post_switch] } Process.detach(job) end end
Protected Instance Methods
Mirrors output on all devices with given resolution.
# File lib/dumon/omanager.rb, line 142 def mirror(resolution) raise NotImplementedError, 'this should be overridden by concrete sub-class' end
Distributes output to given devices with given order and resolution. param outs in form [‘VGA1’, ‘LVDS1’] resolutions in form [‘1920x1080’, ‘1600x900’] param primary name of primary output param horizontal whether horizontal linie of outputs
# File lib/dumon/omanager.rb, line 152 def sequence(outs, resolutions, primary=:none, horizontal=true) raise NotImplementedError, 'this should be overridden by concrete sub-class' end
Switch to given single output device with given resolution. output output resolution nil for default resolution
# File lib/dumon/omanager.rb, line 136 def single(output, resolution=nil) raise NotImplementedError, 'this should be overridden by concrete sub-class' end