fusuma-plugin-wmctrl 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/fusuma-wmctrl +93 -0
- data/lib/fusuma/plugin/executors/wmctrl_executor.rb +2 -2
- data/lib/fusuma/plugin/wmctrl/version.rb +1 -1
- data/lib/fusuma/plugin/wmctrl/window.rb +18 -12
- data/lib/fusuma/plugin/wmctrl/workspace.rb +154 -147
- data/spec/fusuma/plugin/plugin/executors/wmctrl_executor_spec.rb +3 -3
- data/spec/fusuma/plugin/plugin/wmctrl/workspace_spec.rb +2 -2
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5143de56caec58bc113092172aab1b6ad257e245376ff43633fa994adc77a5d8
|
4
|
+
data.tar.gz: 9956dd5820be73525c539a6c1dc67435b4562a8bd116cd05d98db22608189518
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa40be6a49d1d002916280d2b41d0943cca6f555390f5d9a4dd53821a01ebc2d70984aef90b3546d4fcbe835e613c8b8913ddaeb1f59f4674a078003692e4737
|
7
|
+
data.tar.gz: c5d5f213771f20985d2fbffd8ad4d269b3b095abfe6f1ecc874281fc47657f3aabf778155bd2cfb6035db031ccefc9d0b421f47261607f87068ec7afc159d1f7
|
data/exe/fusuma-wmctrl
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'optparse'
|
5
|
+
require_relative '../lib/fusuma/plugin/wmctrl/window.rb'
|
6
|
+
require_relative '../lib/fusuma/plugin/wmctrl/workspace.rb'
|
7
|
+
require_relative '../lib/fusuma/plugin/wmctrl/version.rb'
|
8
|
+
|
9
|
+
option = {}
|
10
|
+
opt = OptionParser.new
|
11
|
+
|
12
|
+
opt.on('--wrap-navigation',
|
13
|
+
'circular navigation between workspaces') do |v|
|
14
|
+
option[:wrap_navigation] = v
|
15
|
+
end
|
16
|
+
|
17
|
+
opt.on('--matrix-col-size=3',
|
18
|
+
'For grid-style workspace, move up, down, left or right.'
|
19
|
+
) do |v|
|
20
|
+
option[:matrix_col_size] = v.to_i
|
21
|
+
end
|
22
|
+
|
23
|
+
opt.on('--workspace=prev|next|up|down|left|right',
|
24
|
+
'move workspace') do |v|
|
25
|
+
option[:workspace] = v
|
26
|
+
end
|
27
|
+
|
28
|
+
opt.on('--window=prev|next|up|down|left|right',
|
29
|
+
'move window') do |v|
|
30
|
+
option[:window] = v
|
31
|
+
end
|
32
|
+
|
33
|
+
opt.on('--version', 'Show version') do |v|
|
34
|
+
option[:version] = v
|
35
|
+
end
|
36
|
+
|
37
|
+
opt.parse!(ARGV)
|
38
|
+
|
39
|
+
if option[:workspace]
|
40
|
+
workspace = Fusuma::Plugin::Wmctrl::Workspace.new(
|
41
|
+
wrap_navigation: option[:wrap_navigation], matrix_col_size: option[:matrix_col_size]
|
42
|
+
)
|
43
|
+
|
44
|
+
command = case property = option[:workspace]
|
45
|
+
when 'prev', 'next'
|
46
|
+
workspace.move_command(direction: property)
|
47
|
+
when 'left', 'right', 'up', 'down'
|
48
|
+
workspace.move_command_for_matrix(direction: property)
|
49
|
+
else
|
50
|
+
raise "#{property} is invalid key"
|
51
|
+
end
|
52
|
+
`#{command}`
|
53
|
+
|
54
|
+
return
|
55
|
+
end
|
56
|
+
|
57
|
+
if option[:window]
|
58
|
+
workspace = Fusuma::Plugin::Wmctrl::Workspace.new(
|
59
|
+
wrap_navigation: option[:wrap_navigation], matrix_col_size: option[:matrix_col_size]
|
60
|
+
)
|
61
|
+
window = Fusuma::Plugin::Wmctrl::Window.new
|
62
|
+
|
63
|
+
command = case property = option[:window]
|
64
|
+
when 'prev', 'next'
|
65
|
+
workspace.move_window_command(direction: property)
|
66
|
+
when 'left', 'right', 'up', 'down'
|
67
|
+
workspace.move_window_command_for_matrix(direction: property)
|
68
|
+
when 'maximized'
|
69
|
+
window.maximized(method: 'toggle')
|
70
|
+
when 'close'
|
71
|
+
window.close
|
72
|
+
when 'fullscreen'
|
73
|
+
window.fullscreen(method: 'toggle')
|
74
|
+
else
|
75
|
+
raise "#{property} is invalid key"
|
76
|
+
end
|
77
|
+
|
78
|
+
`#{command}`
|
79
|
+
|
80
|
+
return
|
81
|
+
end
|
82
|
+
|
83
|
+
if option[:version]
|
84
|
+
puts Fusuma::Plugin::Wmctrl::VERSION
|
85
|
+
return
|
86
|
+
end
|
87
|
+
|
88
|
+
param = ARGV.first
|
89
|
+
|
90
|
+
if param.nil?
|
91
|
+
warn 'fusuma-wmctrl require aruguments'
|
92
|
+
exit 1
|
93
|
+
end
|
@@ -23,11 +23,11 @@ module Fusuma
|
|
23
23
|
|
24
24
|
def initialize
|
25
25
|
super()
|
26
|
-
@workspace = Workspace.new(
|
26
|
+
@workspace = Wmctrl::Workspace.new(
|
27
27
|
wrap_navigation: config_params(:'wrap-navigation'),
|
28
28
|
matrix_col_size: config_params(:'matrix-col-size')
|
29
29
|
)
|
30
|
-
@window = Window.new
|
30
|
+
@window = Wmctrl::Window.new
|
31
31
|
end
|
32
32
|
|
33
33
|
# execute wmctrl command
|
@@ -1,18 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
module Fusuma
|
4
|
+
module Plugin
|
5
|
+
module Wmctrl
|
6
|
+
# Manage Window
|
7
|
+
class Window
|
8
|
+
# @param method [String] "toggle" or "add" or "remove"
|
9
|
+
def maximized(method:)
|
10
|
+
"wmctrl -r :ACTIVE: -b #{method},maximized_vert,maximized_horz"
|
11
|
+
end
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
+
def close
|
14
|
+
'wmctrl -c :ACTIVE:'
|
15
|
+
end
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
# @param method [String] "toggle" or "add" or "remove"
|
18
|
+
def fullscreen(method:)
|
19
|
+
"wmctrl -r :ACTIVE: -b #{method},fullscreen"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
17
23
|
end
|
18
24
|
end
|
@@ -1,153 +1,160 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
3
|
+
module Fusuma
|
4
|
+
module Plugin
|
5
|
+
module Wmctrl
|
6
|
+
# Manage workspace
|
7
|
+
class Workspace
|
8
|
+
class MissingMatrixOption < StandardError; end
|
9
|
+
|
10
|
+
def initialize(wrap_navigation: nil, matrix_col_size: nil)
|
11
|
+
@wrap_navigation = wrap_navigation
|
12
|
+
@matrix_col_size = matrix_col_size
|
13
|
+
end
|
14
|
+
|
15
|
+
# get next workspace number
|
16
|
+
# @return [Integer]
|
17
|
+
def next_workspace_num(step:)
|
18
|
+
current_workspace_num, total_workspace_num = workspace_values
|
19
|
+
|
20
|
+
next_workspace_num = current_workspace_num + step
|
21
|
+
|
22
|
+
return next_workspace_num unless @wrap_navigation
|
23
|
+
|
24
|
+
if next_workspace_num.negative?
|
25
|
+
next_workspace_num = total_workspace_num - 1
|
26
|
+
elsif next_workspace_num >= total_workspace_num
|
27
|
+
next_workspace_num = 0
|
28
|
+
else
|
29
|
+
next_workspace_num
|
30
|
+
end
|
31
|
+
next_workspace_num
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [Array<Integer>]
|
35
|
+
def matrix_size(total_workspace_num)
|
36
|
+
must_have_matrix_option!
|
37
|
+
col_size = @matrix_col_size
|
38
|
+
row_size = (total_workspace_num / col_size)
|
39
|
+
[row_size.to_i, col_size.to_i]
|
40
|
+
end
|
41
|
+
|
42
|
+
def must_have_matrix_option!
|
43
|
+
return if @matrix_col_size
|
44
|
+
|
45
|
+
# FIXME: move to executor
|
46
|
+
warn(<<~ERRRORMESSAGE)
|
47
|
+
Please set matrix-col-size to config.yml
|
48
|
+
|
49
|
+
```config.yaml
|
50
|
+
plugin:
|
51
|
+
executors:
|
52
|
+
wmctrl_executor:
|
53
|
+
matrix-col-size: 2
|
54
|
+
```
|
55
|
+
ERRRORMESSAGE
|
56
|
+
raise MissingMatrixOption, 'You need to set matrix option to config.yml'
|
57
|
+
end
|
58
|
+
|
59
|
+
# @return [Integer]
|
60
|
+
# @raise RuntimeError
|
61
|
+
def next_workspace_num_for_matrix(direction:)
|
62
|
+
must_have_matrix_option!
|
63
|
+
current_workspace_num, total_workspace_num = workspace_values
|
64
|
+
row_size, col_size = matrix_size(total_workspace_num)
|
65
|
+
x = current_workspace_num % col_size
|
66
|
+
y = current_workspace_num / col_size
|
67
|
+
case direction
|
68
|
+
when 'right'
|
69
|
+
if x < col_size - 1
|
70
|
+
current_workspace_num + 1
|
71
|
+
elsif @wrap_navigation
|
72
|
+
current_workspace_num - (col_size - 1)
|
73
|
+
else
|
74
|
+
current_workspace_num
|
75
|
+
end
|
76
|
+
when 'left'
|
77
|
+
if x.positive?
|
78
|
+
current_workspace_num - 1
|
79
|
+
elsif @wrap_navigation
|
80
|
+
current_workspace_num + (col_size - 1)
|
81
|
+
else
|
82
|
+
current_workspace_num
|
83
|
+
end
|
84
|
+
when 'down'
|
85
|
+
if y < row_size - 1
|
86
|
+
current_workspace_num + col_size
|
87
|
+
elsif @wrap_navigation
|
88
|
+
(current_workspace_num + col_size) - total_workspace_num
|
89
|
+
else
|
90
|
+
current_workspace_num
|
91
|
+
end
|
92
|
+
when 'up'
|
93
|
+
if y.positive?
|
94
|
+
current_workspace_num - col_size
|
95
|
+
elsif @wrap_navigation
|
96
|
+
total_workspace_num + (current_workspace_num - col_size)
|
97
|
+
else
|
98
|
+
current_workspace_num
|
99
|
+
end
|
100
|
+
else
|
101
|
+
raise "#{direction} is invalid key"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def move_command(direction:)
|
106
|
+
workspace_num = case direction
|
107
|
+
when 'next'
|
108
|
+
next_workspace_num(step: 1)
|
109
|
+
when 'prev'
|
110
|
+
next_workspace_num(step: -1)
|
111
|
+
else
|
112
|
+
raise "#{direction} is invalid key"
|
113
|
+
end
|
114
|
+
"wmctrl -s #{workspace_num}"
|
115
|
+
end
|
116
|
+
|
117
|
+
def move_command_for_matrix(direction:)
|
118
|
+
workspace_num = next_workspace_num_for_matrix(direction: direction)
|
119
|
+
"wmctrl -s #{workspace_num}"
|
120
|
+
end
|
121
|
+
|
122
|
+
def move_window_command(direction:)
|
123
|
+
workspace_num = case direction
|
124
|
+
when 'next'
|
125
|
+
next_workspace_num(step: 1)
|
126
|
+
when 'prev'
|
127
|
+
next_workspace_num(step: -1)
|
128
|
+
else
|
129
|
+
raise "#{direction} is invalid key"
|
130
|
+
end
|
131
|
+
"wmctrl -r :ACTIVE: -t #{workspace_num} ; wmctrl -s #{workspace_num}"
|
132
|
+
end
|
133
|
+
|
134
|
+
def move_window_command_for_matrix(direction:)
|
135
|
+
workspace_num = next_workspace_num_for_matrix(direction: direction)
|
136
|
+
"wmctrl -r :ACTIVE: -t #{workspace_num} ; wmctrl -s #{workspace_num}"
|
137
|
+
end
|
138
|
+
|
139
|
+
private
|
140
|
+
|
141
|
+
# get current workspace and total workspace numbers
|
142
|
+
# @return [Integer, Integer]
|
143
|
+
def workspace_values
|
144
|
+
wmctrl_output = `wmctrl -d`.split("\n")
|
145
|
+
|
146
|
+
current_line = wmctrl_output.grep(/\*/).first
|
147
|
+
# NOTE: stderror when failed to get desktop
|
148
|
+
# `Cannot get current desktop properties. \
|
149
|
+
# (_NET_CURRENT_DESKTOP or _WIN_WORKSPACE property)`
|
150
|
+
return [0, 1] if current_line.nil?
|
151
|
+
|
152
|
+
current_workspace_num = current_line.chars.first.to_i
|
153
|
+
total_workspace_num = wmctrl_output.length
|
154
|
+
|
155
|
+
[current_workspace_num, total_workspace_num]
|
156
|
+
end
|
79
157
|
end
|
80
|
-
when 'down'
|
81
|
-
if y < row_size - 1
|
82
|
-
current_workspace_num + col_size
|
83
|
-
elsif @wrap_navigation
|
84
|
-
(current_workspace_num + col_size) - total_workspace_num
|
85
|
-
else
|
86
|
-
current_workspace_num
|
87
|
-
end
|
88
|
-
when 'up'
|
89
|
-
if y.positive?
|
90
|
-
current_workspace_num - col_size
|
91
|
-
elsif @wrap_navigation
|
92
|
-
total_workspace_num + (current_workspace_num - col_size)
|
93
|
-
else
|
94
|
-
current_workspace_num
|
95
|
-
end
|
96
|
-
else
|
97
|
-
raise "#{direction} is invalid key"
|
98
158
|
end
|
99
159
|
end
|
100
|
-
|
101
|
-
def move_command(direction:)
|
102
|
-
workspace_num = case direction
|
103
|
-
when 'next'
|
104
|
-
next_workspace_num(step: 1)
|
105
|
-
when 'prev'
|
106
|
-
next_workspace_num(step: -1)
|
107
|
-
else
|
108
|
-
raise "#{direction} is invalid key"
|
109
|
-
end
|
110
|
-
"wmctrl -s #{workspace_num}"
|
111
|
-
end
|
112
|
-
|
113
|
-
def move_command_for_matrix(direction:)
|
114
|
-
workspace_num = next_workspace_num_for_matrix(direction: direction)
|
115
|
-
"wmctrl -s #{workspace_num}"
|
116
|
-
end
|
117
|
-
|
118
|
-
def move_window_command(direction:)
|
119
|
-
workspace_num = case direction
|
120
|
-
when 'next'
|
121
|
-
next_workspace_num(step: 1)
|
122
|
-
when 'prev'
|
123
|
-
next_workspace_num(step: -1)
|
124
|
-
else
|
125
|
-
raise "#{direction} is invalid key"
|
126
|
-
end
|
127
|
-
"wmctrl -r :ACTIVE: -t #{workspace_num} ; wmctrl -s #{workspace_num}"
|
128
|
-
end
|
129
|
-
|
130
|
-
def move_window_command_for_matrix(direction:)
|
131
|
-
workspace_num = next_workspace_num_for_matrix(direction: direction)
|
132
|
-
"wmctrl -r :ACTIVE: -t #{workspace_num} ; wmctrl -s #{workspace_num}"
|
133
|
-
end
|
134
|
-
|
135
|
-
private
|
136
|
-
|
137
|
-
# get current workspace and total workspace numbers
|
138
|
-
# @return [Integer, Integer]
|
139
|
-
def workspace_values
|
140
|
-
wmctrl_output = `wmctrl -d`.split("\n")
|
141
|
-
|
142
|
-
current_line = wmctrl_output.grep(/\*/).first
|
143
|
-
# NOTE: stderror when failed to get desktop
|
144
|
-
# `Cannot get current desktop properties. \
|
145
|
-
# (_NET_CURRENT_DESKTOP or _WIN_WORKSPACE property)`
|
146
|
-
return [0, 1] if current_line.nil?
|
147
|
-
|
148
|
-
current_workspace_num = current_line.chars.first.to_i
|
149
|
-
total_workspace_num = wmctrl_output.length
|
150
|
-
|
151
|
-
[current_workspace_num, total_workspace_num]
|
152
|
-
end
|
153
160
|
end
|
@@ -13,8 +13,8 @@ module Fusuma
|
|
13
13
|
module Executors
|
14
14
|
RSpec.describe WmctrlExecutor do
|
15
15
|
before do
|
16
|
-
@workspace = double(Workspace)
|
17
|
-
allow(Workspace)
|
16
|
+
@workspace = double(Wmctrl::Workspace)
|
17
|
+
allow(Wmctrl::Workspace)
|
18
18
|
.to receive(:new)
|
19
19
|
.and_return(@workspace)
|
20
20
|
|
@@ -317,7 +317,7 @@ module Fusuma
|
|
317
317
|
end
|
318
318
|
|
319
319
|
it 'should wrap-navigation mode' do
|
320
|
-
expect(Workspace).to receive(:new).with(
|
320
|
+
expect(Wmctrl::Workspace).to receive(:new).with(
|
321
321
|
wrap_navigation: true,
|
322
322
|
matrix_col_size: nil
|
323
323
|
)
|
@@ -135,7 +135,7 @@ module Fusuma
|
|
135
135
|
it 'raises InvalidOption' do
|
136
136
|
expect do
|
137
137
|
@workspace.next_workspace_num_for_matrix(direction: 'prev')
|
138
|
-
end.to raise_error(Workspace::
|
138
|
+
end.to raise_error(Wmctrl::Workspace::MissingMatrixOption)
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
@@ -227,7 +227,7 @@ module Fusuma
|
|
227
227
|
@workspace = Workspace.new(matrix_col_size: nil)
|
228
228
|
stub_workspace_values(current: 1, total: 3)
|
229
229
|
end
|
230
|
-
it { expect { @workspace.matrix_size(3) }.to raise_error Workspace::
|
230
|
+
it { expect { @workspace.matrix_size(3) }.to raise_error Workspace::MissingMatrixOption }
|
231
231
|
end
|
232
232
|
end
|
233
233
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fusuma-plugin-wmctrl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- iberianpig
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fusuma
|
@@ -27,7 +27,8 @@ dependencies:
|
|
27
27
|
description: fusuma-plugin-wmctrl is Fusuma plugin for window manager.
|
28
28
|
email:
|
29
29
|
- yhkyky@gmail.com
|
30
|
-
executables:
|
30
|
+
executables:
|
31
|
+
- fusuma-wmctrl
|
31
32
|
extensions: []
|
32
33
|
extra_rdoc_files: []
|
33
34
|
files:
|
@@ -35,6 +36,7 @@ files:
|
|
35
36
|
- README.md
|
36
37
|
- bin/console
|
37
38
|
- bin/setup
|
39
|
+
- exe/fusuma-wmctrl
|
38
40
|
- fusuma-plugin-wmctrl.gemspec
|
39
41
|
- lib/fusuma/plugin/executors/wmctrl_executor.rb
|
40
42
|
- lib/fusuma/plugin/wmctrl.rb
|
@@ -65,13 +67,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
67
|
- !ruby/object:Gem::Version
|
66
68
|
version: '0'
|
67
69
|
requirements: []
|
68
|
-
rubygems_version: 3.1
|
70
|
+
rubygems_version: 3.0.3.1
|
69
71
|
signing_key:
|
70
72
|
specification_version: 4
|
71
73
|
summary: Wmctrl plugin for Fusuma
|
72
74
|
test_files:
|
73
|
-
- spec/fusuma/plugin/plugin/wmctrl/workspace_spec.rb
|
74
|
-
- spec/fusuma/plugin/plugin/executors/wmctrl_executor_spec.rb
|
75
|
-
- spec/fusuma/plugin/wmctrl_spec.rb
|
76
75
|
- spec/helpers/config_helper.rb
|
77
76
|
- spec/spec_helper.rb
|
77
|
+
- spec/fusuma/plugin/wmctrl_spec.rb
|
78
|
+
- spec/fusuma/plugin/plugin/executors/wmctrl_executor_spec.rb
|
79
|
+
- spec/fusuma/plugin/plugin/wmctrl/workspace_spec.rb
|