dumon 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/Copyrights ADDED
@@ -0,0 +1,4 @@
1
+ Icon set (DevCom Network Set 1)
2
+ -------------------------------
3
+ Copyright (c) DevCom. All rights reserved.
4
+ - downloaded from findicons.com (http://findicons.com/pack/256/devcom_network_set_1)
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # dumon
2
+
3
+ Dual monitor manager for Linux with GTK2 based user interface represented by system tray icon and its context menu.
4
+
5
+ ## SCREENSHOTS
6
+
7
+ [![](https://raw.github.com/veny/dumon/master/screenshots/tray_icon.png)](https://raw.github.com/veny/dumon/master/screenshots/tray_icon.png)
8
+
9
+ [![](https://raw.github.com/veny/dumon/master/screenshots/basic_menu.png)](https://raw.github.com/veny/dumon/master/screenshots/basic_menu.png)
10
+
11
+ [![](https://raw.github.com/veny/dumon/master/screenshots/resolution_menu.png)](https://raw.github.com/veny/dumon/master/screenshots/resolution_menu.png)
12
+
13
+ [![](https://raw.github.com/veny/dumon/master/screenshots/mirror_menu.png)](https://raw.github.com/veny/dumon/master/screenshots/mirror_menu.png)
14
+
15
+
16
+ ## INSTALL
17
+
18
+ > sudo gem install dumon
19
+
20
+ * gem published on http://rubygems.org/gems/dumon
21
+
22
+
23
+ ## FEATURES/PROBLEMS
24
+
25
+ * only for Linux
26
+ * currently supports only two output devices
27
+ * currently works only with 'xrandr' (command line interface to RandR extension)
28
+
29
+ ## REQUIREMENTS
30
+
31
+ * Ruby 1.9.x
32
+ * ruby-gtk2 1.2.x
33
+ * xrandr 1.3.x
34
+
35
+ ## AUTHOR
36
+
37
+ * vaclav.sykora@gmail.com
38
+ * https://plus.google.com/115674031373998885915
39
+
40
+ ## LICENSE
41
+
42
+ * Apache License, Version 2.0, http://www.apache.org/licenses/
43
+ * see LICENSE file for more details...
data/bin/dumon ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'dumon'
data/dumon.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $:.unshift File.expand_path('../lib', __FILE__)
4
+ require 'dumon/version'
5
+
6
+ Gem::Specification.new do |s|
7
+
8
+ s.name = %q{dumon}
9
+ s.version = Dumon::VERSION
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new('> 1.3.1') if s.respond_to? :required_rubygems_version=
12
+ s.authors = ['Vaclav Sykora']
13
+ s.date = Dumon::VERSION_HISTORY[0][1]
14
+ s.description = %q{Dual monitor manager for Linux with GTK2 based user interface represented by system tray icon and its context menu.}
15
+ s.email = %q{vaclav.sykora@gmail.com}
16
+
17
+ s.files = `git ls-files`.split("\n").select { |item| item unless item.start_with? 'screenshot' }
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ puts "XX #{s.executables}"
21
+ s.require_paths = ["lib"]
22
+
23
+ s.extra_rdoc_files = [
24
+ "LICENSE",
25
+ "README.md"
26
+ ]
27
+ s.homepage = %q{http://github.com/veny/dumon}
28
+ s.rdoc_options = ['--charset=UTF-8']
29
+ s.require_paths = ['lib']
30
+ s.rubygems_version = %q{1.3.7}
31
+ s.summary = %q{Dual monitor manager for Linux.}
32
+
33
+ s.add_dependency(%q<gtk2>, ["~> 1.2.0"])
34
+ # s.add_development_dependency(%q<json>, ["~> 1.5.1"])
35
+
36
+ end
@@ -0,0 +1,167 @@
1
+ module Dumon
2
+
3
+ ###
4
+ # This class represents a base class defining how concrete sub-classes manage
5
+ # output devices available on your system.
6
+ class OutDeviceManager
7
+
8
+ ###
9
+ # System tool to be used for output devices management.
10
+ attr_accessor :stool
11
+
12
+ ###
13
+ # Cached information about current output devices.
14
+ # Format: {output_name=>{:default=>"AxB",:current=>"CxD",:resolutions=>[...], ...}
15
+ # Sample: {
16
+ # "LVDS1"=>{:resolutions=>["1600x900", "1024x768"], :default=>"1600x900"},
17
+ # "VGA1" =>{:resolutions=>["1920x1080", "720x400"], :default=>"1920x1080", :current=>"1920x1080"}
18
+ # }
19
+ attr_accessor :outputs
20
+
21
+ ###
22
+ # Reads info about current accessible output devices and their settings.
23
+ def read
24
+ raise NotImplementedError, 'this should be overridden by concrete sub-class'
25
+ end
26
+
27
+ ###
28
+ # Switch to given single output device with given resolution.
29
+ def single(output, resolution, type=nil)
30
+ raise NotImplementedError, 'this should be overridden by concrete sub-class'
31
+ end
32
+
33
+ ###
34
+ # Mirrors output on all devices with given resolution.
35
+ def mirror(resolution)
36
+ raise NotImplementedError, 'this should be overridden by concrete sub-class'
37
+ end
38
+
39
+ ###
40
+ # Distributes output to given devices with given order and resolution.
41
+ # *param* outputs in form [["LVDS1", "1600x900"], [VGA1", "1920x1080"]]
42
+ def sequence(outputs)
43
+ raise NotImplementedError, 'this should be overridden by concrete sub-class'
44
+ end
45
+
46
+ ###
47
+ # Gets default resolution of given output device.
48
+ def default_resolution(output)
49
+ raise 'no outputs' if self.outputs.nil? or self.outputs.empty?
50
+ raise "unknown output: #{output}" unless self.outputs.keys.include?(output)
51
+ raise "no default resolution, output: #{output}" unless self.outputs[output].keys.include?(:default)
52
+
53
+ self.outputs[output][:default]
54
+ end
55
+
56
+ ###
57
+ # Gets list of common resolutions of all output devices.
58
+ def common_resolutions
59
+ raise 'no outputs' if self.outputs.nil? or self.outputs.empty?
60
+
61
+ rslt = []
62
+ o1 = self.outputs.keys.first
63
+ self.outputs[o1][:resolutions].each do |res|
64
+ self.outputs.keys.each do |o|
65
+ next if o === o1
66
+ rslt << res if self.outputs[o][:resolutions].include?(res)
67
+ end
68
+ end
69
+
70
+ rslt
71
+ end
72
+
73
+ end
74
+
75
+
76
+ ###
77
+ # This class manages output devices via *xrandr* system tool.
78
+ class XrandrManager < OutDeviceManager
79
+
80
+ ###
81
+ # Constructor.
82
+ # Checks whether the 'xrandr' system tool is there.
83
+ def initialize
84
+ paths = ['xrandr', '/usr/bin/xrandr']
85
+ paths.each do |path|
86
+ begin
87
+ `#{path}`
88
+ self.stool = path
89
+ Dumon.logger.info "System tool found: #{path}"
90
+ break
91
+ rescue => e
92
+ Dumon.logger.warn "unknown tool: #{path}, message: #{e.message}"
93
+ end
94
+ end
95
+
96
+ raise "no system tool found, checked for #{paths}" if self.stool.nil?
97
+
98
+ self.read
99
+ end
100
+
101
+ def read #:nodoc:
102
+ rslt = {}
103
+ output = nil
104
+ xrandr_out = `#{self.stool} -q`
105
+ xrandr_out.each_line do |line|
106
+ if line =~ /^\w+ connected /
107
+ output = line[/^\w+/]
108
+ rslt[output] = {:resolutions => []}
109
+ end
110
+ if line =~ /^\s+[0-9x]+\s+\d+/ and not output.nil?
111
+ resolution = line[/[0-9x]+/]
112
+ rslt[output][:default] = resolution if line.include? '+'
113
+ rslt[output][:current] = resolution if line.include? '*'
114
+ rslt[output][:resolutions] << resolution
115
+ end
116
+ end
117
+
118
+ Dumon::logger.debug "Outputs found: #{rslt}"
119
+ self.outputs = rslt
120
+ rslt
121
+ end
122
+
123
+ def single(output, resolution, type=nil) #:nodoc:
124
+ self.read if self.outputs.nil? or self.outputs.empty?
125
+ raise "uknown output: #{output}" unless self.outputs.keys.include?(output)
126
+
127
+ resolution = self.default_resolution(output) if resolution.nil?
128
+
129
+ cmd = "#{self.stool} --output #{output} --mode #{resolution} --pos 0x0"
130
+ self.outputs.keys.each do |o|
131
+ cmd << " --output #{o} --off" unless o === output
132
+ end
133
+
134
+ Dumon::logger.debug "Command: #{cmd}"
135
+ `#{cmd}`
136
+ end
137
+
138
+ def mirror(resolution) #:nodoc:
139
+ self.read if self.outputs.nil? or self.outputs.empty?
140
+
141
+ cmd = "#{self.stool}"
142
+ self.outputs.keys.each { |o| cmd << " --output #{o} --mode #{resolution}" }
143
+
144
+ Dumon::logger.debug "Command: #{cmd}"
145
+ `#{cmd}`
146
+ end
147
+
148
+ def sequence(outputs) #:nodoc:
149
+ raise 'not an array' unless outputs.kind_of?(Array)
150
+ outputs.each { |pair| raise 'item not a pair' if !pair.kind_of?(Array) and pair.size != 2 }
151
+
152
+ cmd = "#{self.stool}"
153
+ for i in 0..outputs.size - 1
154
+ output = outputs[i][0]
155
+ resolution = outputs[i][1]
156
+ resolution = self.default_resolution(output) if resolution.nil?
157
+ cmd << " --output #{output} --mode #{resolution}"
158
+ cmd << " --right-of #{outputs[i - 1][0]}" if i > 0
159
+ end
160
+
161
+ Dumon::logger.debug "Command: #{cmd}"
162
+ `#{cmd}`
163
+ end
164
+
165
+ end
166
+
167
+ end
data/lib/dumon/ui.rb ADDED
@@ -0,0 +1,170 @@
1
+ module Dumon
2
+
3
+ ###
4
+ # This class represents Dumon's user interface.
5
+ class Ui
6
+
7
+ ###
8
+ # Output manager used to manipulate the output.
9
+ attr_accessor :omanager
10
+
11
+ ###
12
+ # Renders the UI.
13
+ # Abstract method to be overridden by concrete sub-class.
14
+ def render
15
+ raise NotImplementedError, 'this should be overridden by concrete sub-class'
16
+ end
17
+
18
+ ###
19
+ # Quits the application.
20
+ def quit
21
+ Dumon::logger.info "Terminted..."
22
+ end
23
+
24
+ end
25
+
26
+
27
+ ###
28
+ # This class represents Dumon's user interface based on Gtk library.
29
+ class GtkUi < Ui
30
+
31
+ ###
32
+ # Constructor.
33
+ # Initializes the Gtk stuff.
34
+ def initialize
35
+ super
36
+ Gtk.init
37
+ end
38
+
39
+ def render #:nodoc:
40
+ Gtk.main
41
+ end
42
+
43
+ def quit #:nodoc:
44
+ super
45
+ Gtk.main_quit
46
+ end
47
+
48
+ end
49
+
50
+
51
+ ###
52
+ # This class represents a user interface represented by system tray icon and its context menu.
53
+ class Tray < GtkUi
54
+
55
+ def initialize #:nodoc:
56
+ super
57
+
58
+ # storage of preferred resolution for next rendering (will be cleared by output changing)
59
+ # {"LVDS1" => "1600x900", "VGA1" => "800x600"}
60
+ @selected_resolution = {}
61
+
62
+ @tray = Gtk::StatusIcon.new
63
+ @tray.visible = true
64
+ @tray.pixbuf = Gdk::Pixbuf.new(::File.join(::File.dirname(__FILE__), '..', 'monitor.png'))
65
+ @tray.tooltip = "Dual Monitor Manager"
66
+
67
+ @tray.signal_connect('popup-menu') do |w, button, activate_time|
68
+ menu = self.create_menu
69
+ menu.show_all
70
+ menu.popup(nil, nil, button, activate_time)
71
+ end
72
+ end
73
+
74
+ ###
75
+ # Reads info about currently usable outputs and construct corresponding structure of context menu.
76
+ def create_menu
77
+ outputs = self.omanager.read
78
+
79
+ rslt = Gtk::Menu.new
80
+
81
+ # resolutions (submenu)
82
+ outputs.keys.each do |o|
83
+ item = Gtk::MenuItem.new(o)
84
+ submenu = Gtk::Menu.new
85
+ item.set_submenu(submenu)
86
+
87
+ # to be marked with '*'
88
+ defres = self.omanager.default_resolution(o)
89
+
90
+ # radio buttons group
91
+ radios = []
92
+
93
+ outputs[o][:resolutions].each do |res|
94
+ si = Gtk::RadioMenuItem.new(radios, defres === res ? "#{res} [*]" : res)
95
+ si.active = (@selected_resolution[o] === res or (@selected_resolution[o].nil? and outputs[o][:current] === res))
96
+ radios << si
97
+ si.signal_connect('activate') do
98
+ # only store your preferred resolution for next rendering
99
+ @selected_resolution[o] = res if si.active? # only activation, ignore deactivation
100
+ end
101
+ submenu.append(si)
102
+ end
103
+ rslt.append(item)
104
+ end
105
+
106
+ # separator
107
+ item = Gtk::SeparatorMenuItem.new
108
+ rslt.append(item)
109
+
110
+ # outputs
111
+ outputs.keys.each do |o|
112
+ item = Gtk::MenuItem.new("only #{o}")
113
+ item.signal_connect('activate') do
114
+ self.omanager.single(o, @selected_resolution[o])
115
+ # clear preferred resolution, by next rendering will be read from real state
116
+ @selected_resolution.clear
117
+ end
118
+ rslt.append(item)
119
+ end
120
+
121
+ # mirror
122
+ item = Gtk::MenuItem.new('mirror')
123
+ if outputs.keys.size > 1
124
+ submenu = Gtk::Menu.new
125
+ item.set_submenu(submenu)
126
+ else
127
+ item.sensitive = false
128
+ end
129
+
130
+ self.omanager.common_resolutions.each do |res|
131
+ si = Gtk::MenuItem.new(res)
132
+ si.signal_connect('activate') { self.omanager.mirror(res) }
133
+ submenu.append(si)
134
+ end
135
+ rslt.append(item)
136
+
137
+ # sequence (currently supporting only 2 output devices)
138
+ if outputs.keys.size >= 2
139
+ o0 = outputs.keys[0]
140
+ o1 = outputs.keys[1]
141
+ item = Gtk::MenuItem.new("#{o0} left of #{o1}")
142
+ item.signal_connect('activate') do
143
+ self.omanager.sequence([[o0, @selected_resolution[o0]], [o1, @selected_resolution[o1]]])
144
+ # clear preferred resolution, by next rendering will be read from real state
145
+ @selected_resolution.clear
146
+ end
147
+ rslt.append(item)
148
+ item = Gtk::MenuItem.new("#{o1} left of #{o0}")
149
+ item.signal_connect('activate') do
150
+ self.omanager.sequence([[o1, @selected_resolution[o1]], [o0, @selected_resolution[o0]]])
151
+ # clear preferred resolution, by next rendering will be read from real state
152
+ @selected_resolution.clear
153
+ end
154
+ rslt.append(item)
155
+ end
156
+
157
+ # separator
158
+ item = Gtk::SeparatorMenuItem.new
159
+ rslt.append(item)
160
+ # Quit
161
+ item = Gtk::ImageMenuItem.new(Gtk::Stock::QUIT)
162
+ item.signal_connect('activate') { self.quit }
163
+ rslt.append(item)
164
+
165
+ rslt
166
+ end
167
+
168
+ end
169
+
170
+ end
@@ -0,0 +1,13 @@
1
+ module Dumon
2
+
3
+ # Version history.
4
+ VERSION_HISTORY = [
5
+ ['0.1.2', '2013-02-01', 'Refactoring: class name optimalization'],
6
+ ['0.1.1', '2013-01-28', 'Release candidate supporting two output devices'],
7
+ ['0.1.0', '2013-01-21', 'Initial version on Ruby-1.9.3p374']
8
+ ]
9
+
10
+ # Current version.
11
+ VERSION = VERSION_HISTORY[0][0]
12
+
13
+ end
data/lib/dumon.rb ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'logger'
4
+ require 'gtk2'
5
+ require 'dumon/version'
6
+
7
+
8
+ ###
9
+ # This module represents the entry point of Dumon tool.
10
+ module Dumon
11
+
12
+ autoload :XrandrManager, 'dumon/omanager'
13
+ autoload :Tray, 'dumon/ui'
14
+
15
+ class << self
16
+
17
+ ###
18
+ # Logger used for logging output.
19
+ attr_accessor :logger
20
+
21
+ end
22
+
23
+ end
24
+
25
+
26
+ # Configuration of logging.
27
+ Dumon::logger = Logger.new(STDOUT)
28
+ Dumon::logger.level = Logger::INFO
29
+ #Dumon::logger.level = Logger::DEBUG
30
+
31
+ Dumon::logger.info \
32
+ "Dumon #{Dumon::VERSION}, running on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
33
+
34
+
35
+ # start the app
36
+ omanager = Dumon::XrandrManager.new
37
+
38
+ ui = Dumon::Tray.new
39
+ ui.omanager = omanager
40
+ ui.render
data/lib/monitor.png ADDED
Binary file
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dumon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Vaclav Sykora
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: gtk2
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.2.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.2.0
30
+ description: Dual monitor manager for Linux with GTK2 based user interface represented
31
+ by system tray icon and its context menu.
32
+ email: vaclav.sykora@gmail.com
33
+ executables:
34
+ - dumon
35
+ extensions: []
36
+ extra_rdoc_files:
37
+ - LICENSE
38
+ - README.md
39
+ files:
40
+ - .gitignore
41
+ - Copyrights
42
+ - LICENSE
43
+ - README.md
44
+ - bin/dumon
45
+ - dumon.gemspec
46
+ - lib/dumon.rb
47
+ - lib/dumon/omanager.rb
48
+ - lib/dumon/ui.rb
49
+ - lib/dumon/version.rb
50
+ - lib/monitor.png
51
+ homepage: http://github.com/veny/dumon
52
+ licenses: []
53
+ post_install_message:
54
+ rdoc_options:
55
+ - --charset=UTF-8
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>'
68
+ - !ruby/object:Gem::Version
69
+ version: 1.3.1
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 1.8.23
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Dual monitor manager for Linux.
76
+ test_files: []