xrandr 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7bb660cead9fafcbb58f35a0eb7c3981f9c4f20
4
- data.tar.gz: cd6d57377f91e780b8a5a74e91887f1abb9f58b0
3
+ metadata.gz: c94bc868f6a3f45ed747869a7af9c02debf416a1
4
+ data.tar.gz: 9decdce0d71fa37c754397320dde46542e35b667
5
5
  SHA512:
6
- metadata.gz: 968287ec8fd4c1159c40b7087a1047a06a9f79f176617ed72c1241130b7ef3891aaa77e0991fdccfe09623536ba943dbc8e7fa78686eb2468957eaf73dd7f7e9
7
- data.tar.gz: 4eb35f1d52c17e46442d637c4a29ddaabf6873920fab6a45adf6695e5446edf2a3ff2306f9d19cd0250f87fb9f2938b520a7c2e8137da28ca8407539de9cd6d5
6
+ metadata.gz: 0c5dcda826aae40ac37bdfbcd8cbcf8af7ba24512ccd08d3c36193f3f167b023da5699e2d1ed6471688a4d2379220013688d88665a407a5e52571f3ef7f0c529
7
+ data.tar.gz: 78cd193b81fb9f6f5d1d839ffcfe5e7d5af75a082ebe0574dec943fc9ff0b1d45f491dfd5f26b94dc13bc819555ae341213ab764c8e9bc5da5ec96bb7345572b
data/README.md CHANGED
@@ -16,29 +16,39 @@ Gives you the status of each of the outputs
16
16
 
17
17
  ```ruby
18
18
 
19
- Xrandr.new.outputs #=> [ <Xrandr::Output{ id: 1, name: 'LVDS1', connected: true, mode: '1920x1080' }>, <Xrandr::Output { id: 2, name: 'VGA1', connected: false }> ]
19
+ Xrandr::Control.new.outputs #=> [#<Xrandr::Output:0x00557ed8ed80a8 @name="eDP1", @connected=true, @primary=true, @resolution="1920x1080", @position="0x0", @info="(normal left inverted right x axis y axis)", @dimensions="344mm x 193mm", @modes=[#<Xrandr::Mode:0x00557ed8ed9cc8 @resolution="1920x1080", @rate="60.0", @current=true, @preferred=true>, ... ]>, #<Xrandr::Output:0x00557ed8711f40 @name="DP1", @connected=false, @primary=false, @resolution=nil, @position=nil, @info="(normal left inverted right x axis y axis)", @dimensions=nil, @modes=[]>, ... ]
20
20
 
21
21
  ```
22
22
 
23
- Access specific output parameters
23
+ Access specific output parameters by index
24
24
 
25
25
  ```ruby
26
- randr = Xrandr.new
27
- vga = randr.output(1)
26
+ xrandr = Xrandr::Control.new
27
+
28
+ vga = xrandr.find_output(1)
29
+ # or
30
+ vga = xrandr[1]
31
+
32
+ vga.status #=> 'on' # possible values are: 'on'`, 'off' or 'disconnected'
28
33
 
29
34
  vga.connected #=> true
30
35
  vga.name #=> 'VGA1'
31
- vga.mode #=> '1920x1080'
36
+ vga.current # returns the current Xrandr::Mode for this display. nil if disconnected or off
32
37
 
33
38
  ```
34
39
 
40
+ Access specific output parameters by name
41
+
35
42
  ```ruby
36
- randr = Xrandr.new
37
- vga = randr.output('VGA1')
43
+ x = Xrandr::Control.new
44
+
45
+ vga = xrandr.find_output('VGA1')
46
+ # or
47
+ vga = xrandr['VGA1']
38
48
 
39
49
  vga.connected #=> true
40
50
  vga.name #=> 'VGA1'
41
- vga.mode #=> '1920x1080'
51
+ vga.current #=> '1920x1080'
42
52
 
43
53
  ```
44
54
 
@@ -46,7 +56,7 @@ vga.mode #=> '1920x1080'
46
56
 
47
57
 
48
58
  ```ruby
49
- xrandr = Xrandr.new
59
+ xrandr = Xrandr::Control.new
50
60
 
51
61
  # setting global options
52
62
  xrandr.configure(fb: '1920x1080', no_primary: true)
@@ -80,7 +90,7 @@ For all available configuration parameter see you can `man xrandr`
80
90
 
81
91
  ## Contributing
82
92
 
83
- Open an issue, lets talk.
93
+ Open an issue, a PR, or whatever you feel comfortable with.
84
94
 
85
95
  ## License
86
96
 
@@ -1,5 +1,5 @@
1
1
  module Xrandr
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
 
4
4
  class Control
5
5
  attr_reader :screens, :outputs, :command
@@ -69,6 +69,7 @@ module Xrandr
69
69
  connected: /connected|disconnected/,
70
70
  primary: /primary/,
71
71
  resolution: /\d+x\d+\+\d+\+\d+/,
72
+ rotation: /(inverted|left|right) \(/,
72
73
  info: /\([^\)]+\)/,
73
74
  dimensions: /[0-9+]+mm x [0-9]+mm/,
74
75
  }
@@ -78,7 +79,11 @@ module Xrandr
78
79
  # split resolution and position values split all values, coherce to integers, split the array in halfs, assign each half)
79
80
  args[:resolution], args[:position] = args[:resolution].split(/x|\+/).each_slice(2).map {|v| v.join('x') } if args[:resolution]
80
81
 
82
+ # Xrandr swaps resolution when display is rotated left or right
83
+ args[:resolution] = args[:resolution].split('x').reverse!.join('x') if args[:rotation] == 'left' || args[:rotation] == 'right'
84
+
81
85
  # Coherce parameters
86
+ args[:rotation] = args[:rotation] ? args[:rotation].first : 'normal'
82
87
  args[:connected] = args[:connected] == 'connected'
83
88
  args[:primary] = args[:primary] == 'primary'
84
89
 
@@ -111,13 +116,13 @@ module Xrandr
111
116
  end
112
117
 
113
118
  class Output
114
- attr_reader :name, :connected, :primary, :resolution, :position, :info, :dimensions, :modes
119
+ attr_reader :name, :connected, :primary, :resolution, :position, :rotation, :info, :dimensions, :modes
115
120
 
116
121
  ON = 'on'.freeze
117
122
  OFF = 'off'.freeze
118
123
  DISCONNECTED = 'disconnected'.freeze
119
124
 
120
- def initialize(name:, connected:, primary: false, resolution: nil, position: nil, info: '', dimensions: '', modes: [])
125
+ def initialize(name:, connected:, primary: false, resolution: nil, position: nil, rotation: '', info: '', dimensions: '', modes: [])
121
126
  raise ArgumentError, "must provide a name for the output" unless name
122
127
  raise ArgumentError, "connected cant be nil" unless connected == true || connected == false
123
128
  @name = name
@@ -126,6 +131,7 @@ module Xrandr
126
131
  @resolution = resolution
127
132
  @position = position
128
133
  @info = info
134
+ @rotation = rotation
129
135
  @dimensions = dimensions
130
136
  @modes = modes
131
137
  end
@@ -96,6 +96,23 @@ module Xrandr
96
96
  assert_empty output.modes
97
97
  end
98
98
 
99
+ def test_parses_rotation
100
+ session = Parser.new
101
+
102
+ assert_equal 'inverted', session.parse_output(['eDP1 connected primary 1920x1080+0+0 inverted (normal left inverted right x axis y axis) 344mm x 193mm']).rotation
103
+ assert_equal 'left', session.parse_output(['eDP1 connected primary 1080x1920+0+0 left (normal left inverted right x axis y axis) 344mm x 193mm']).rotation
104
+ assert_equal 'right', session.parse_output(['eDP1 connected primary 1080x1920+0+0 right (normal left inverted right x axis y axis) 344mm x 193mm']).rotation
105
+ assert_equal 'normal', session.parse_output(['eDP1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 344mm x 193mm']).rotation
106
+ end
107
+
108
+ def test_when_rotated_returns_original_resolution
109
+ session = Parser.new
110
+
111
+ assert_equal '1920x1080', session.parse_output(['eDP1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 344mm x 193mm']).resolution
112
+ assert_equal '1920x1080', session.parse_output(['eDP1 connected primary 1920x1080+0+0 inverted (normal left inverted right x axis y axis) 344mm x 193mm']).resolution
113
+ assert_equal '1920x1080', session.parse_output(['eDP1 connected primary 1080x1920+0+0 left (normal left inverted right x axis y axis) 344mm x 193mm']).resolution
114
+ assert_equal '1920x1080', session.parse_output(['eDP1 connected primary 1080x1920+0+0 right (normal left inverted right x axis y axis) 344mm x 193mm']).resolution
115
+ end
99
116
  end
100
117
 
101
118
  class Parser::ParseModeTest < Minitest::Test
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["fernando.martinez@live.com.ar"]
11
11
  spec.summary = %q{ A ruby wrapper for Xrandr }
12
12
  spec.description = %q{ A ruby wrapper for Xrandr }
13
- spec.homepage = "https://github.com/f-3r/xrandr"
13
+ spec.homepage = "https://github.com/F-3r/xrandr.rb"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xrandr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernando Martínez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-01 00:00:00.000000000 Z
11
+ date: 2016-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -57,7 +57,7 @@ files:
57
57
  - test/output_test.rb
58
58
  - test/parser_test.rb
59
59
  - xrandr.gemspec
60
- homepage: https://github.com/f-3r/xrandr
60
+ homepage: https://github.com/F-3r/xrandr.rb
61
61
  licenses:
62
62
  - MIT
63
63
  metadata: {}
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  version: '0'
78
78
  requirements: []
79
79
  rubyforge_project:
80
- rubygems_version: 2.4.5.1
80
+ rubygems_version: 2.5.1
81
81
  signing_key:
82
82
  specification_version: 4
83
83
  summary: A ruby wrapper for Xrandr