Class: Fusuma::Plugin::Wmctrl::Workspace
- Inherits:
-
Object
- Object
- Fusuma::Plugin::Wmctrl::Workspace
show all
- Defined in:
- lib/fusuma/plugin/wmctrl/workspace.rb
Overview
Defined Under Namespace
Classes: MissingMatrixOption
Instance Method Summary
collapse
Constructor Details
#initialize(wrap_navigation: nil, matrix_col_size: nil) ⇒ Workspace
Returns a new instance of Workspace.
10
11
12
13
|
# File 'lib/fusuma/plugin/wmctrl/workspace.rb', line 10
def initialize(wrap_navigation: nil, matrix_col_size: nil)
@wrap_navigation = wrap_navigation
@matrix_col_size = matrix_col_size
end
|
Instance Method Details
#matrix_size(total_workspace_num) ⇒ Array<Integer>
36
37
38
39
40
41
|
# File 'lib/fusuma/plugin/wmctrl/workspace.rb', line 36
def matrix_size(total_workspace_num)
must_have_matrix_option!
col_size = @matrix_col_size
row_size = (total_workspace_num / col_size)
[row_size.to_i, col_size.to_i]
end
|
#move_command(direction:) ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/fusuma/plugin/wmctrl/workspace.rb', line 108
def move_command(direction:)
workspace_num = case direction
when "next"
next_workspace_num(step: 1)
when "prev"
next_workspace_num(step: -1)
else
raise "#{direction} is invalid key"
end
workspace_num = 0 if workspace_num.negative?
"wmctrl -s #{workspace_num}"
end
|
#move_command_for_matrix(direction:) ⇒ Object
123
124
125
126
|
# File 'lib/fusuma/plugin/wmctrl/workspace.rb', line 123
def move_command_for_matrix(direction:)
workspace_num = next_workspace_num_for_matrix(direction: direction)
"wmctrl -s #{workspace_num}"
end
|
#move_window_command(direction:) ⇒ Object
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/fusuma/plugin/wmctrl/workspace.rb', line 128
def move_window_command(direction:)
workspace_num = case direction
when "next"
next_workspace_num(step: 1)
when "prev"
next_workspace_num(step: -1)
else
raise "#{direction} is invalid key"
end
workspace_num = 0 if workspace_num.negative?
"wmctrl -r :ACTIVE: -t #{workspace_num} ; wmctrl -s #{workspace_num}"
end
|
#move_window_command_for_matrix(direction:) ⇒ Object
144
145
146
147
|
# File 'lib/fusuma/plugin/wmctrl/workspace.rb', line 144
def move_window_command_for_matrix(direction:)
workspace_num = next_workspace_num_for_matrix(direction: direction)
"wmctrl -r :ACTIVE: -t #{workspace_num} ; wmctrl -s #{workspace_num}"
end
|
#must_have_matrix_option! ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/fusuma/plugin/wmctrl/workspace.rb', line 44
def must_have_matrix_option!
return if @matrix_col_size
warn(<<~ERRRORMESSAGE)
Please set matrix-col-size to config.yml
```config.yaml
plugin:
executors:
wmctrl_executor:
matrix-col-size: 2
```
ERRRORMESSAGE
raise MissingMatrixOption, "You need to set matrix option to config.yml"
end
|
#next_workspace_num(step:) ⇒ Integer
get next workspace number
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/fusuma/plugin/wmctrl/workspace.rb', line 17
def next_workspace_num(step:)
current_workspace_num, total_workspace_num = workspace_values
next_workspace_num = current_workspace_num + step
return next_workspace_num unless @wrap_navigation
if next_workspace_num.negative?
next_workspace_num = total_workspace_num - 1
elsif next_workspace_num >= total_workspace_num
next_workspace_num = 0
else
next_workspace_num
end
next_workspace_num
end
|
#next_workspace_num_for_matrix(direction:) ⇒ Integer
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/fusuma/plugin/wmctrl/workspace.rb', line 64
def next_workspace_num_for_matrix(direction:)
must_have_matrix_option!
current_workspace_num, total_workspace_num = workspace_values
row_size, col_size = matrix_size(total_workspace_num)
x = current_workspace_num % col_size
y = current_workspace_num / col_size
case direction
when "right"
if x < col_size - 1
current_workspace_num + 1
elsif @wrap_navigation
current_workspace_num - (col_size - 1)
else
current_workspace_num
end
when "left"
if x.positive?
current_workspace_num - 1
elsif @wrap_navigation
current_workspace_num + (col_size - 1)
else
current_workspace_num
end
when "down"
if y < row_size - 1
current_workspace_num + col_size
elsif @wrap_navigation
(current_workspace_num + col_size) - total_workspace_num
else
current_workspace_num
end
when "up"
if y.positive?
current_workspace_num - col_size
elsif @wrap_navigation
total_workspace_num + (current_workspace_num - col_size)
else
current_workspace_num
end
else
raise "#{direction} is invalid key"
end
end
|