swm 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -8
- data/bin/swm +4 -2
- data/lib/swm.rb +2 -0
- data/lib/swm/commands/command.rb +40 -0
- data/lib/swm/commands/move_command.rb +1 -32
- data/lib/swm/commands/resize_command.rb +28 -0
- data/lib/swm/screen.rb +1 -1
- data/lib/swm/version.rb +1 -1
- data/lib/swm/window.rb +14 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6737404f8274bcc90d25baabc3dea109decebb3a
|
4
|
+
data.tar.gz: 46d9434f2c901bedb01808f0d49ac7afe55159e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c7792e75db029104688077385a794685967b49f7ec429f94a1cdecad1c8d6432a90906a7f477956b75cb9c051aced4bc0552a17f5555c9296640226aefc466d
|
7
|
+
data.tar.gz: e6ada0b85afd5c74868ee306ffe5ba503c6f8e89185f334b113afb936f94bc2a672cc4f93dbb6db574b879e6ab2823d15774d69bc3f0c89f33fc0d57310f6ba3
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# Simple Window Manager
|
2
2
|
|
3
|
-
NOTE: THIS IS NOT YET DONE!
|
4
|
-
|
5
3
|
SWM is a utility to place and resize windows, written for Ubuntu. It might work with other *nix distributions.
|
6
4
|
|
5
|
+
SWM has been confirmed _not_ to work with OS X. Please help fix this :)
|
6
|
+
|
7
7
|
## Installation
|
8
8
|
|
9
9
|
$ gem install swm
|
@@ -12,8 +12,8 @@ SWM is a utility to place and resize windows, written for Ubuntu. It might work
|
|
12
12
|
|
13
13
|
Some command line tools are needed:
|
14
14
|
|
15
|
-
- xdotool (for getting window id
|
16
|
-
- wmctrl (for moving and
|
15
|
+
- xdotool (for getting window id of current window)
|
16
|
+
- wmctrl (for moving and resizing windows)
|
17
17
|
- xdpyinfo (for getting screen dimensions)
|
18
18
|
- xwininfo (for getting window information)
|
19
19
|
|
@@ -21,10 +21,14 @@ Install these with apt-get if they are not on your system.
|
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
24
|
+
SWM is meant to be assigned to shortcuts and will always work on the currently active window.
|
25
|
+
|
26
|
+
For example, I have configured my `Super-1` - `Super-4` to place the current window in the four corners of my screen.
|
27
|
+
|
24
28
|
### Moving windows
|
25
29
|
|
26
|
-
Move windows with the move subcommand.
|
27
|
-
It accepts parameters x and y which can both be specified in percentages of free screen space.
|
30
|
+
Move windows with the `move` subcommand.
|
31
|
+
It accepts parameters `x` and `y` which can both be specified in percentages of free screen space.
|
28
32
|
|
29
33
|
Examples:
|
30
34
|
|
@@ -38,8 +42,8 @@ Will move the window to the left edge of the sceen, preserving the Y position
|
|
38
42
|
|
39
43
|
There are some predefined constants that can be used to specify position:
|
40
44
|
|
41
|
-
- For X these are: left
|
42
|
-
- For Y
|
45
|
+
- For X these are: `left`, `middle` and `right`.
|
46
|
+
- For Y it is: `top`, `middle`, `bottom`.
|
43
47
|
|
44
48
|
For example:
|
45
49
|
|
data/bin/swm
CHANGED
@@ -53,8 +53,10 @@ end
|
|
53
53
|
|
54
54
|
def get_resize_options
|
55
55
|
Trollop::options do
|
56
|
-
opt :
|
57
|
-
opt :
|
56
|
+
opt :x1, "The placement of the left edge: left, middle, right, or 0%-100%", type: String
|
57
|
+
opt :x2, "The placement of the right edge: left, middle, right, or 0%-100%", type: String
|
58
|
+
opt :y1, "The placement of the top edge: top, middle, bottom, or 0%-100%", type: String
|
59
|
+
opt :y2, "The placement of the bottom edge: top, middle, bottom, or 0%-100%", type: String
|
58
60
|
end
|
59
61
|
end
|
60
62
|
|
data/lib/swm.rb
CHANGED
@@ -2,4 +2,6 @@ require_relative "swm/version"
|
|
2
2
|
require_relative "swm/window"
|
3
3
|
require_relative "swm/screen"
|
4
4
|
require_relative "swm/command_runner"
|
5
|
+
require_relative "swm/commands/command"
|
6
|
+
require_relative "swm/commands/resize_command"
|
5
7
|
require_relative "swm/commands/move_command"
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Swm
|
2
|
+
class Command
|
3
|
+
def initialize(command_options = {}, global_options = {})
|
4
|
+
@command_options = command_options
|
5
|
+
@global_options = global_options
|
6
|
+
end
|
7
|
+
|
8
|
+
def run
|
9
|
+
raise "Override in sub derived class"
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_x_percentage(name = :x)
|
13
|
+
get_placement_percentage name, {
|
14
|
+
left: 0,
|
15
|
+
middle: 50,
|
16
|
+
right: 100
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_y_percentage(name = :y)
|
21
|
+
get_placement_percentage name, {
|
22
|
+
top: 0,
|
23
|
+
middle: 50,
|
24
|
+
bottom: 100
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_placement_percentage(name, constants)
|
29
|
+
raw_value = @command_options[name]
|
30
|
+
return nil if raw_value.nil?
|
31
|
+
if value = constants[raw_value.to_sym]
|
32
|
+
value
|
33
|
+
elsif /(\d+(\.\d+)?)\%/ =~ raw_value
|
34
|
+
$1.to_f
|
35
|
+
else
|
36
|
+
raise "Unknown placement option: #{raw_value}. Valid options are percentages (e.g. 30%) and [#{constants.map{|x| x.first.to_s}.join(' ')}]"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,9 +1,5 @@
|
|
1
1
|
module Swm
|
2
|
-
class MoveCommand
|
3
|
-
def initialize(command_options = {}, global_options = {})
|
4
|
-
@command_options = command_options
|
5
|
-
@global_options = global_options
|
6
|
-
end
|
2
|
+
class MoveCommand < Command
|
7
3
|
|
8
4
|
def run
|
9
5
|
window = Swm::Window.current
|
@@ -20,32 +16,5 @@ module Swm
|
|
20
16
|
window.move x, y
|
21
17
|
end
|
22
18
|
|
23
|
-
def get_x_percentage
|
24
|
-
get_placement_percentage :x, {
|
25
|
-
left: 0,
|
26
|
-
middle: 50,
|
27
|
-
right: 100
|
28
|
-
}
|
29
|
-
end
|
30
|
-
|
31
|
-
def get_y_percentage
|
32
|
-
get_placement_percentage :y, {
|
33
|
-
top: 0,
|
34
|
-
middle: 50,
|
35
|
-
bottom: 100
|
36
|
-
}
|
37
|
-
end
|
38
|
-
|
39
|
-
def get_placement_percentage(axis, constants)
|
40
|
-
raw_value = @command_options[axis]
|
41
|
-
return nil if raw_value.nil?
|
42
|
-
if value = constants[raw_value.to_sym]
|
43
|
-
value
|
44
|
-
elsif /(\d+(\.\d+)?)\%/ =~ raw_value
|
45
|
-
$1.to_f
|
46
|
-
else
|
47
|
-
raise "Unknown placement option: #{raw_value}. Valid options are percentages (e.g. 30%) and [#{constants.map{|x| x.first.to_s}.join(' ')}]"
|
48
|
-
end
|
49
|
-
end
|
50
19
|
end
|
51
20
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Swm
|
2
|
+
class ResizeCommand < Command
|
3
|
+
|
4
|
+
def run
|
5
|
+
x1 = get_x_percentage :x1
|
6
|
+
x2 = get_x_percentage :x2
|
7
|
+
y1 = get_y_percentage :y1
|
8
|
+
y2 = get_y_percentage :y2
|
9
|
+
|
10
|
+
screen_dimensions = Screen.dimensions
|
11
|
+
window = Swm::Window.current
|
12
|
+
|
13
|
+
x = y = width = height = nil
|
14
|
+
x = (screen_dimensions[0] * x1 / 100.0).to_i if x1
|
15
|
+
y = (screen_dimensions[1] * y1 / 100.0).to_i if y1
|
16
|
+
width = (screen_dimensions[0] * x2 / 100.0).to_i - (x || window.pos_x) if x2
|
17
|
+
height = (screen_dimensions[1] * y2 / 100.0).to_i - (y || window.pos_y) if y2
|
18
|
+
|
19
|
+
puts "x: #{x}"
|
20
|
+
puts "y: #{y}"
|
21
|
+
puts "width: #{width}"
|
22
|
+
puts "height: #{height}"
|
23
|
+
|
24
|
+
window.set x, y, width, height
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
data/lib/swm/screen.rb
CHANGED
data/lib/swm/version.rb
CHANGED
data/lib/swm/window.rb
CHANGED
@@ -27,8 +27,17 @@ module Swm
|
|
27
27
|
def move(x, y)
|
28
28
|
x ||= pos_x
|
29
29
|
y ||= pos_y
|
30
|
-
|
30
|
+
set x, y, nil, nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def set(x, y, w, h)
|
34
|
+
x ||= pos_x
|
35
|
+
y ||= pos_y
|
36
|
+
w ||= width
|
37
|
+
h ||= height
|
38
|
+
command = "wmctrl -i -r #{@id} -e 0,#{x},#{y},#{w},#{h}"
|
31
39
|
exec command
|
40
|
+
clear_cache
|
32
41
|
end
|
33
42
|
|
34
43
|
private
|
@@ -68,5 +77,9 @@ module Swm
|
|
68
77
|
def xwininfo_integer_property(name)
|
69
78
|
/#{name}: +(\d+)/.match(xwininfo)[1].to_i
|
70
79
|
end
|
80
|
+
|
81
|
+
def clear_cache
|
82
|
+
@xwininfo = nil
|
83
|
+
end
|
71
84
|
end
|
72
85
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lasse Skindstad Ebert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trollop
|
@@ -102,7 +102,9 @@ files:
|
|
102
102
|
- bin/swm
|
103
103
|
- lib/swm.rb
|
104
104
|
- lib/swm/command_runner.rb
|
105
|
+
- lib/swm/commands/command.rb
|
105
106
|
- lib/swm/commands/move_command.rb
|
107
|
+
- lib/swm/commands/resize_command.rb
|
106
108
|
- lib/swm/screen.rb
|
107
109
|
- lib/swm/version.rb
|
108
110
|
- lib/swm/window.rb
|
@@ -129,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
131
|
version: '0'
|
130
132
|
requirements: []
|
131
133
|
rubyforge_project:
|
132
|
-
rubygems_version: 2.0.
|
134
|
+
rubygems_version: 2.0.3
|
133
135
|
signing_key:
|
134
136
|
specification_version: 4
|
135
137
|
summary: Simple Window Manager for Ubuntu
|