Class: Dumon::XrandrManager
- Inherits:
-
OutDeviceManager
- Object
- OutDeviceManager
- Dumon::XrandrManager
- Defined in:
- lib/dumon/omanager.rb
Overview
This class manages output devices via xrandr system tool.
Instance Attribute Summary
Attributes inherited from OutDeviceManager
Instance Method Summary collapse
-
#initialize ⇒ XrandrManager
constructor
Constructor.
-
#read ⇒ Object
:nodoc:.
Methods inherited from OutDeviceManager
#common_resolutions, #default_resolution, #reset, #switch
Methods included from Rrutils::Options
#assert, #keys_to_sym, #verify_and_sanitize_options, #verify_options
Constructor Details
#initialize ⇒ XrandrManager
Constructor. Checks whether the ‘xrandr’ system tool is there.
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/dumon/omanager.rb', line 159 def initialize paths = ['/usr/bin/xrandr', 'xrandr'] paths.each do |path| begin `#{path}` @stool = path Dumon.logger.info "System tool found: #{path}" break rescue => e Dumon.logger.warn "unknown tool: #{path}, message: #{e.message}" end end raise "no system tool found, checked for #{paths}" if self.stool.nil? # just to check if it works self.read end |
Instance Method Details
#read ⇒ Object
:nodoc:
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/dumon/omanager.rb', line 178 def read #:nodoc: @outputs = nil # clear previous info rslt = {} output = nil xrandr_out = `#{self.stool} -q` xrandr_out.each_line do |line| if line =~ /^[\w-]+ connected / output = line[/^[\w-]+/] rslt[output] = {:resolutions => []} end if line =~ /^\s*[0-9x]+\s+\d+/ and not output.nil? resolution = line[/[0-9x]+/] rslt[output][:default] = resolution if line.include? '+' rslt[output][:current] = resolution if line.include? '*' rslt[output][:resolutions] << resolution end end # BF 13 not all outputs provide default resolution rslt.each do |output,| # consider the first resolution (the highest) as default [:default] = [:resolutions].first unless .include? :default end Dumon::logger.debug "Outputs found: #{rslt}" # verify structure of readed infos assert(!rslt.empty?, 'no outputs found') rslt.each do |output,| (, {:resolutions=>:mandatory, :default=>:mandatory, :current=>:optional}) assert([:resolutions].size >= 1, "no resolution found, output=#{output}") end @outputs = rslt rslt end |