Class: Xrandr::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/xrandr.rb

Constant Summary collapse

ON =
'on'.freeze
OFF =
'off'.freeze
DISCONNECTED =
'disconnected'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, connected:, primary: false, resolution: nil, position: nil, info: '', dimensions: '', modes: []) ⇒ Output

Returns a new instance of Output.

Raises:

  • (ArgumentError)


120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/xrandr.rb', line 120

def initialize(name:, connected:, primary: false, resolution: nil, position: nil, 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
  @dimensions = dimensions
  @modes = modes
end

Instance Attribute Details

#connectedObject (readonly)

Returns the value of attribute connected.



114
115
116
# File 'lib/xrandr.rb', line 114

def connected
  @connected
end

#dimensionsObject (readonly)

Returns the value of attribute dimensions.



114
115
116
# File 'lib/xrandr.rb', line 114

def dimensions
  @dimensions
end

#infoObject (readonly)

Returns the value of attribute info.



114
115
116
# File 'lib/xrandr.rb', line 114

def info
  @info
end

#modesObject (readonly)

Returns the value of attribute modes.



114
115
116
# File 'lib/xrandr.rb', line 114

def modes
  @modes
end

#nameObject (readonly)

Returns the value of attribute name.



114
115
116
# File 'lib/xrandr.rb', line 114

def name
  @name
end

#positionObject (readonly)

Returns the value of attribute position.



114
115
116
# File 'lib/xrandr.rb', line 114

def position
  @position
end

#primaryObject (readonly)

Returns the value of attribute primary.



114
115
116
# File 'lib/xrandr.rb', line 114

def primary
  @primary
end

#resolutionObject (readonly)

Returns the value of attribute resolution.



114
115
116
# File 'lib/xrandr.rb', line 114

def resolution
  @resolution
end

Instance Method Details

#currentObject



133
134
135
# File 'lib/xrandr.rb', line 133

def current
  modes.detect(&:current)
end

#preferredObject



137
138
139
# File 'lib/xrandr.rb', line 137

def preferred
  modes.detect(&:preferred)
end

#statusObject



141
142
143
144
# File 'lib/xrandr.rb', line 141

def status
  return DISCONNECTED unless connected
  current ? ON : OFF
end