desktopen 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +54 -0
- data/LICENSE.txt +20 -0
- data/Rakefile +26 -0
- data/VERSION +1 -0
- data/bin/desktopen +81 -0
- data/lib/desktopen.rb +91 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 86a058e23c875190ed028da726f4adf2d79ccc01
|
4
|
+
data.tar.gz: d407ae62f4f66ef3555465285d3dfd583b96ec35
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c9ea518a5c2fdc6c28caef50fb32aef2e1392995d022064563349c4ca277bce9ff6f74da9f0328b8c135d28fd7f89f4b53ebf3292300c7b7d500be57610be0c5
|
7
|
+
data.tar.gz: dc5887574bdfee4b7942df719c48117e1adf0be53dc8bf4056fc444cf3b3aba2d82a7d88128483a0c542cfdabc6d114c656f54fec123d4f2169ed62fc20021f8
|
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "bundler", "~> 1.0"
|
10
|
+
gem "jeweler", "~> 2.0.1"
|
11
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.4.0)
|
5
|
+
builder (3.2.2)
|
6
|
+
descendants_tracker (0.0.4)
|
7
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
8
|
+
faraday (0.9.2)
|
9
|
+
multipart-post (>= 1.2, < 3)
|
10
|
+
git (1.2.9.1)
|
11
|
+
github_api (0.13.1)
|
12
|
+
addressable (~> 2.4.0)
|
13
|
+
descendants_tracker (~> 0.0.4)
|
14
|
+
faraday (~> 0.8, < 0.10)
|
15
|
+
hashie (>= 3.4)
|
16
|
+
multi_json (>= 1.7.5, < 2.0)
|
17
|
+
oauth2
|
18
|
+
hashie (3.4.3)
|
19
|
+
highline (1.7.8)
|
20
|
+
jeweler (2.0.1)
|
21
|
+
builder
|
22
|
+
bundler (>= 1.0)
|
23
|
+
git (>= 1.2.5)
|
24
|
+
github_api
|
25
|
+
highline (>= 1.6.15)
|
26
|
+
nokogiri (>= 1.5.10)
|
27
|
+
rake
|
28
|
+
rdoc
|
29
|
+
json (1.8.3)
|
30
|
+
jwt (1.5.2)
|
31
|
+
mini_portile2 (2.0.0)
|
32
|
+
multi_json (1.11.2)
|
33
|
+
multi_xml (0.5.5)
|
34
|
+
multipart-post (2.0.0)
|
35
|
+
nokogiri (1.6.7.2)
|
36
|
+
mini_portile2 (~> 2.0.0.rc2)
|
37
|
+
oauth2 (1.0.0)
|
38
|
+
faraday (>= 0.8, < 0.10)
|
39
|
+
jwt (~> 1.0)
|
40
|
+
multi_json (~> 1.3)
|
41
|
+
multi_xml (~> 0.5)
|
42
|
+
rack (~> 1.2)
|
43
|
+
rack (1.6.4)
|
44
|
+
rake (10.5.0)
|
45
|
+
rdoc (4.2.1)
|
46
|
+
json (~> 1.4)
|
47
|
+
thread_safe (0.3.5)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
ruby
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
bundler (~> 1.0)
|
54
|
+
jeweler (~> 2.0.1)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2016 Roman Snitko
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
+
gem.name = "desktopen"
|
18
|
+
gem.homepage = "http://github.com/snitko/desktopen"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{A simple CLI util to open and position X windows}
|
21
|
+
gem.description = %Q{A simple CLI util to open and position X windows.}
|
22
|
+
gem.email = "roman.snitko@gmail.com"
|
23
|
+
gem.authors = ["Roman Snitko"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.5.0
|
data/bin/desktopen
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# This program opens windows and places them in the correct
|
4
|
+
# positions on correct viewports.
|
5
|
+
#
|
6
|
+
# Usage:
|
7
|
+
#
|
8
|
+
# owin ["command name --with --all --the args"] [viewport] [ fullscreen | [Width] [Height] [X-pos] [Y-pos] [screen number] ]
|
9
|
+
#
|
10
|
+
# How it works:
|
11
|
+
#
|
12
|
+
# 1. Gets screen resolution (xrandr)
|
13
|
+
# 2. Gets the number of viewports
|
14
|
+
# 3. Calculates 0,0 coordinates for each viewport
|
15
|
+
#
|
16
|
+
# 4. Opens the window, get its ID
|
17
|
+
# 5. Uses wmctrl to set window position
|
18
|
+
|
19
|
+
require 'optparse'
|
20
|
+
require_relative '../lib/desktopen'
|
21
|
+
|
22
|
+
options = {}
|
23
|
+
OptionParser.new do |opts|
|
24
|
+
|
25
|
+
opts.banner = "Usage: desktopen command_name [--fullscreen | -x N -y N -w N -h N] --viewport=N --display=N"
|
26
|
+
|
27
|
+
opts.on("-f", "--fullscreen", "Open window in fullscreen") do |v|
|
28
|
+
options[:fullscreen] = v
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on("-x N", "X position of the top-left corner of the window") do |v|
|
32
|
+
options[:x] = v
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.on("-y N", "Y position of the top-left corner of the window") do |v|
|
36
|
+
options[:y] = v
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on("-w N", "window width") do |v|
|
40
|
+
options[:w] = v
|
41
|
+
end
|
42
|
+
|
43
|
+
opts.on("-h N", "window height") do |v|
|
44
|
+
options[:h] = v
|
45
|
+
end
|
46
|
+
|
47
|
+
opts.on("-v N", "--viewport=N", "viewport number to place the window at") do |v|
|
48
|
+
options[:viewport] = v
|
49
|
+
end
|
50
|
+
|
51
|
+
opts.on("-d N", "--display=N", "display to place the window at") do |v|
|
52
|
+
exit("Sorry, only up to 2 displays are currently supported!") if v.to_i > 2
|
53
|
+
options[:display] = v
|
54
|
+
end
|
55
|
+
|
56
|
+
opts.on("-t N", "--repos-timeout=N", "timeout before repositioning a window, default 1 (second)") do |v|
|
57
|
+
options[:repos_timeout] = v
|
58
|
+
end
|
59
|
+
|
60
|
+
end.parse!
|
61
|
+
|
62
|
+
# Run the command and open that window.
|
63
|
+
old_window_ids_list = window_ids_list
|
64
|
+
pid = spawn("#{ARGV[0]}")
|
65
|
+
@find_window_by_pid_attempt = 0
|
66
|
+
|
67
|
+
# Give the process some time to load, otherwise we can start moving the window before
|
68
|
+
# it's properly opened and this may result in mispositioning.
|
69
|
+
# The sleep time obviously depends on the system, for slower PCs it should be set to a larger number.
|
70
|
+
sleep options[:repos_timeout] || 1
|
71
|
+
|
72
|
+
position_and_resize_active_window(
|
73
|
+
window_id: find_opened_window(old_window_ids_list),
|
74
|
+
viewport: options[:viewport],
|
75
|
+
display: options[:display],
|
76
|
+
fullscreen: options[:fullscreen],
|
77
|
+
x: options[:x],
|
78
|
+
y: options[:y],
|
79
|
+
w: options[:w],
|
80
|
+
h: options[:h]
|
81
|
+
)
|
data/lib/desktopen.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
def current_screen_resolution
|
2
|
+
@current_screen_resolution ||= `xrandr`.split("\n").first.match(/current (\d+) x (\d+),/)[1..2].map(&:to_i)
|
3
|
+
end
|
4
|
+
|
5
|
+
def full_desktop_resolution
|
6
|
+
return @full_desktop_resolution if @full_desktop_resolution
|
7
|
+
@full_desktop_resolution = []
|
8
|
+
`wmctrl -d`.split("\n").each do |line|
|
9
|
+
if line.match(/\* DG/)
|
10
|
+
@full_desktop_resolution = line.match(/\* DG: (\d+)x(\d+)/)[1..2].map(&:to_i)
|
11
|
+
break;
|
12
|
+
end
|
13
|
+
end
|
14
|
+
@full_desktop_resolution
|
15
|
+
end
|
16
|
+
|
17
|
+
def viewports_matrix
|
18
|
+
return @viewports_matrix if @viewports_matrix
|
19
|
+
columns = full_desktop_resolution[0]/current_screen_resolution[0]
|
20
|
+
rows = full_desktop_resolution[1]/current_screen_resolution[1]
|
21
|
+
{ columns: columns, rows: rows }
|
22
|
+
end
|
23
|
+
|
24
|
+
def viewports_coordinates
|
25
|
+
return @viewports_coordinates if @viewports_coordinates
|
26
|
+
@viewports_coordinates = []
|
27
|
+
|
28
|
+
x,y = current_screen_resolution
|
29
|
+
|
30
|
+
viewports_matrix[:rows].times do |ri|
|
31
|
+
viewports_matrix[:columns].times do |ci|
|
32
|
+
@viewports_coordinates << [x*ci, y*ri]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
@viewports_coordinates
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_absolute_coordrinates_for_viewport(viewport, x, y)
|
39
|
+
viewport_x = viewports_coordinates[viewport-1].first
|
40
|
+
viewport_y = viewports_coordinates[viewport-1].last
|
41
|
+
[viewport_x + x, viewport_y + y]
|
42
|
+
end
|
43
|
+
|
44
|
+
def position_and_resize_active_window(window_id:, x:, y:, w:, h:, viewport:, display: nil, fullscreen: nil)
|
45
|
+
if fullscreen
|
46
|
+
#display = y
|
47
|
+
x, y = get_absolute_coordrinates_for_viewport(viewport.to_i, 10, 10)
|
48
|
+
`wmctrl -i -r #{window_id} -e "0,#{x},#{y},700,500"`
|
49
|
+
unless maximized?(window_id)
|
50
|
+
`wmctrl -i -r #{window_id} -b toggle,maximized_vert,maximized_horz`
|
51
|
+
end
|
52
|
+
else
|
53
|
+
x, y = get_absolute_coordrinates_for_viewport(viewport.to_i, x.to_i, y.to_i)
|
54
|
+
# Unmaximize first
|
55
|
+
if maximized?(window_id)
|
56
|
+
`wmctrl -i -r #{window_id} -b toggle,maximized_vert,maximized_horz`
|
57
|
+
end
|
58
|
+
`wmctrl -i -r #{window_id} -e "0,#{x.to_i},#{y.to_i},#{w.to_i},#{h.to_i}"`
|
59
|
+
end
|
60
|
+
|
61
|
+
# Moving to screen 2
|
62
|
+
move_to_screen_on_the_right(window_id, x.to_i, y.to_i) if display.to_i == 2
|
63
|
+
end
|
64
|
+
|
65
|
+
def maximized?(window_id)
|
66
|
+
`xwininfo -all -id #{window_id} | grep Maximized`.split("\n").size == 2
|
67
|
+
end
|
68
|
+
|
69
|
+
def window_ids_list
|
70
|
+
`wmctrl -l`.split("\n").map { |line| line.gsub(/\s.*\Z/, '') }
|
71
|
+
end
|
72
|
+
|
73
|
+
def find_opened_window(old_window_ids_list)
|
74
|
+
new_windows = window_ids_list - old_window_ids_list
|
75
|
+
if @find_window_by_pid_attempt < 50 && new_windows.empty?
|
76
|
+
sleep(0.1)
|
77
|
+
@find_window_by_pid_attempt += 1
|
78
|
+
find_opened_window(old_window_ids_list)
|
79
|
+
else
|
80
|
+
new_windows.last
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Moves window to another screen (in case you have two monitors, for example).
|
85
|
+
# Currently doesn't support more than that because I don't personally need it
|
86
|
+
# and it complicates things quite a bit.
|
87
|
+
def move_to_screen_on_the_right(window_id, current_x, current_y)
|
88
|
+
window_id = window_id.sub('0x', '').to_i(16) # converting to dec
|
89
|
+
`/usr/bin/xdotool windowmove #{window_id} #{current_x + @current_screen_resolution[0]/2} #{current_y}`
|
90
|
+
end
|
91
|
+
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: desktopen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Roman Snitko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jeweler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.0.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.0.1
|
41
|
+
description: A simple CLI util to open and position X windows.
|
42
|
+
email: roman.snitko@gmail.com
|
43
|
+
executables:
|
44
|
+
- desktopen
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files:
|
47
|
+
- LICENSE.txt
|
48
|
+
files:
|
49
|
+
- ".document"
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
52
|
+
- LICENSE.txt
|
53
|
+
- Rakefile
|
54
|
+
- VERSION
|
55
|
+
- bin/desktopen
|
56
|
+
- lib/desktopen.rb
|
57
|
+
homepage: http://github.com/snitko/desktopen
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.4.5
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: A simple CLI util to open and position X windows
|
81
|
+
test_files: []
|