lib/xrandr.rb in xrandr-0.0.4 vs lib/xrandr.rb in xrandr-0.0.5

- old
+ new

@@ -1,7 +1,7 @@ module Xrandr - VERSION = '0.0.4' + VERSION = '0.0.5' class Control attr_reader :screens, :outputs, :command def initialize(parser = Parser.new) @@ -67,20 +67,25 @@ args = { name: /[a-zA-Z0-9\-\_]+/, connected: /connected|disconnected/, primary: /primary/, resolution: /\d+x\d+\+\d+\+\d+/, + rotation: /(inverted|left|right) \(/, info: /\([^\)]+\)/, dimensions: /[0-9+]+mm x [0-9]+mm/, } .map {|token, regex| [token, data.scan(regex).first] } .to_h # split resolution and position values split all values, coherce to integers, split the array in halfs, assign each half) args[:resolution], args[:position] = args[:resolution].split(/x|\+/).each_slice(2).map {|v| v.join('x') } if args[:resolution] + # Xrandr swaps resolution when display is rotated left or right + args[:resolution] = args[:resolution].split('x').reverse!.join('x') if args[:rotation] == 'left' || args[:rotation] == 'right' + # Coherce parameters + args[:rotation] = args[:rotation] ? args[:rotation].first : 'normal' args[:connected] = args[:connected] == 'connected' args[:primary] = args[:primary] == 'primary' # Parse modes @@ -109,24 +114,25 @@ Mode.new args end end class Output - attr_reader :name, :connected, :primary, :resolution, :position, :info, :dimensions, :modes + attr_reader :name, :connected, :primary, :resolution, :position, :rotation, :info, :dimensions, :modes ON = 'on'.freeze OFF = 'off'.freeze DISCONNECTED = 'disconnected'.freeze - def initialize(name:, connected:, primary: false, resolution: nil, position: nil, info: '', dimensions: '', modes: []) + def initialize(name:, connected:, primary: false, resolution: nil, position: nil, rotation: '', info: '', dimensions: '', modes: []) raise ArgumentError, "must provide a name for the output" unless name raise ArgumentError, "connected cant be nil" unless connected == true || connected == false @name = name @connected = connected @primary = primary @resolution = resolution @position = position @info = info + @rotation = rotation @dimensions = dimensions @modes = modes end def current