fusuma-plugin-wmctrl 1.0.1 → 1.2.0

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
  SHA256:
3
- metadata.gz: 206927fb10327c6ab0d7f07eeb06f01a29d7e41606a1531d6502cf84442a3d38
4
- data.tar.gz: be3df8f773fb4967ef9cc7a89adb36a2b1da12605ec76c9c25c3b36f39daa96b
3
+ metadata.gz: db960729f5b2efaf7a2836fbd09ca5ec52669cdf2e864c528cc97cac5f3d5992
4
+ data.tar.gz: ac6168d7203212c274fb646af071d3fc50ec7dcc9cf4f87b7431f4cd95a62ab5
5
5
  SHA512:
6
- metadata.gz: d295420ce0a75f51d1ced4057a067773f99b1a7c2fbb94f1fe222f2f315c13a00e41103ce50c0f17ce5ef1a0092672837ad762e7306c0e22c9bf8ee461c2c8f4
7
- data.tar.gz: d89d25b3270a470bff127e435d8e95caa3f1a4da462db098ef3b1634ba2ed9ac2faf3c722c0dec6190c556cb7c492110a9306a3b9807e0532a8ae7c756f87031
6
+ metadata.gz: 987c7d1241da28ce082ab83e3af20856ba2fa135f280a6780a17c195fb486dc60b2fe97839d033c618e54bb851f69e3fd35377e6af95812f779c3cb136102c6e
7
+ data.tar.gz: 1fa805963357ef94051a4264449cf6e294e4b080a0449cc465b289438e2cc67ec57a0a4ca788bfa1953a931672d7d2c41029796a9a9e46751e3fc395207ce4c9
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Fusuma::Plugin::Wmctrl [![Gem Version](https://badge.fury.io/rb/fusuma-plugin-wmctrl.svg)](https://badge.fury.io/rb/fusuma-plugin-wmctrl) [![Build Status](https://travis-ci.com/iberianpig/fusuma-plugin-wmctrl.svg?branch=master)](https://travis-ci.com/iberianpig/fusuma-plugin-wmctrl)
1
+ # Fusuma::Plugin::Remap [![Gem Version](https://badge.fury.io/rb/fusuma-plugin-wmctrl.svg)](https://badge.fury.io/rb/fusuma-plugin-wmctrl) [![Build Status](https://github.com/iberianpig/fusuma-plugin-wmctrl/actions/workflows/main.yml/badge.svg)](https://github.com/iberianpig/fusuma-plugin-wmctrl/actions/workflows/main.yml)
2
2
 
3
3
 
4
4
  Window Manager plugin for [Fusuma](https://github.com/iberianpig/fusuma)
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
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.required_ruby_version = '>= 2.5.1' # https://packages.ubuntu.com/search?keywords=ruby&searchon=names&exact=1&suite=all&section=main
26
26
  # support bionic (18.04LTS) 2.5.1
27
- spec.add_dependency 'fusuma', '~> 2.0'
27
+ spec.add_dependency 'fusuma', '>= 2.0'
28
28
  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
@@ -3,7 +3,7 @@
3
3
  module Fusuma
4
4
  module Plugin
5
5
  module Wmctrl
6
- VERSION = '1.0.1'
6
+ VERSION = '1.2.0'
7
7
  end
8
8
  end
9
9
  end
@@ -1,18 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Manage Window
4
- class Window
5
- # @param method [String] "toggle" or "add" or "remove"
6
- def maximized(method:)
7
- "wmctrl -r :ACTIVE: -b #{method},maximized_vert,maximized_horz"
8
- end
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
- def close
11
- 'wmctrl -c :ACTIVE:'
12
- end
13
+ def close
14
+ 'wmctrl -c :ACTIVE:'
15
+ end
13
16
 
14
- # @param method [String] "toggle" or "add" or "remove"
15
- def fullscreen(method:)
16
- "wmctrl -r :ACTIVE: -b #{method},fullscreen"
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
- # Manage workspace
4
- class Workspace
5
- class InvalidOption < StandardError; end
6
-
7
- def initialize(wrap_navigation: nil, matrix_col_size: nil)
8
- @wrap_navigation = wrap_navigation
9
- @matrix_col_size = matrix_col_size
10
- end
11
-
12
- # get next workspace number
13
- # @return [Integer]
14
- def next_workspace_num(step:)
15
- current_workspace_num, total_workspace_num = workspace_values
16
-
17
- next_workspace_num = current_workspace_num + step
18
-
19
- return next_workspace_num unless @wrap_navigation
20
-
21
- if next_workspace_num.negative?
22
- next_workspace_num = total_workspace_num - 1
23
- elsif next_workspace_num >= total_workspace_num
24
- next_workspace_num = 0
25
- else
26
- next_workspace_num
27
- end
28
- next_workspace_num
29
- end
30
-
31
- # @return [Array<Integer>]
32
- def matrix_size(total_workspace_num)
33
- must_have_matrix_option!
34
- col_size = @matrix_col_size
35
- row_size = (total_workspace_num / col_size)
36
- [row_size.to_i, col_size.to_i]
37
- end
38
-
39
- def must_have_matrix_option!
40
- return if @matrix_col_size
41
-
42
- warn(<<~ERRRORMESSAGE)
43
- Please set matrix-col-size to config.yml
44
-
45
- ```config.yaml
46
- plugin:
47
- executors:
48
- wmctrl_executor:
49
- matrix-col-size: 2
50
- ```
51
- ERRRORMESSAGE
52
- raise InvalidOption, 'You need to set matrix option to config.yml'
53
- end
54
-
55
- # @return [Integer]
56
- # @raise RuntimeError
57
- def next_workspace_num_for_matrix(direction:)
58
- must_have_matrix_option!
59
- current_workspace_num, total_workspace_num = workspace_values
60
- row_size, col_size = matrix_size(total_workspace_num)
61
- x = current_workspace_num % col_size
62
- y = current_workspace_num / col_size
63
- case direction
64
- when 'right'
65
- if x < col_size - 1
66
- current_workspace_num + 1
67
- elsif @wrap_navigation
68
- current_workspace_num - (col_size - 1)
69
- else
70
- current_workspace_num
71
- end
72
- when 'left'
73
- if x.positive?
74
- current_workspace_num - 1
75
- elsif @wrap_navigation
76
- current_workspace_num + (col_size - 1)
77
- else
78
- current_workspace_num
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::InvalidOption)
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::InvalidOption }
230
+ it { expect { @workspace.matrix_size(3) }.to raise_error Workspace::MissingMatrixOption }
231
231
  end
232
232
  end
233
233
  end
metadata CHANGED
@@ -1,33 +1,34 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fusuma-plugin-wmctrl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.2.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-10-03 00:00:00.000000000 Z
11
+ date: 2023-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fusuma
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
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.4
70
+ rubygems_version: 3.3.26
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
75
  - spec/fusuma/plugin/plugin/executors/wmctrl_executor_spec.rb
76
+ - spec/fusuma/plugin/plugin/wmctrl/workspace_spec.rb
75
77
  - spec/fusuma/plugin/wmctrl_spec.rb
76
78
  - spec/helpers/config_helper.rb
77
79
  - spec/spec_helper.rb