Class: Workspace
- Inherits:
-
Object
- Object
- Workspace
- Defined in:
- lib/fusuma/plugin/wmctrl/workspace.rb
Overview
Manage workspace
Defined Under Namespace
Classes: InvalidOption
Instance Method Summary collapse
-
#initialize(wrap_navigation: nil, matrix_col_size: nil) ⇒ Workspace
constructor
A new instance of Workspace.
- #matrix_size(total_workspace_num) ⇒ Array<Integer>
- #move_command(direction:) ⇒ Object
- #move_command_for_matrix(direction:) ⇒ Object
- #move_window_command(direction:) ⇒ Object
- #move_window_command_for_matrix(direction:) ⇒ Object
- #must_have_matrix_option! ⇒ Object
-
#next_workspace_num(step:) ⇒ Integer
get next workspace number.
- #next_workspace_num_for_matrix(direction:) ⇒ Integer
Constructor Details
#initialize(wrap_navigation: nil, matrix_col_size: nil) ⇒ Workspace
Returns a new instance of Workspace.
7 8 9 10 |
# File 'lib/fusuma/plugin/wmctrl/workspace.rb', line 7 def initialize(wrap_navigation: nil, matrix_col_size: nil) = @matrix_col_size = matrix_col_size end |
Instance Method Details
#matrix_size(total_workspace_num) ⇒ Array<Integer>
32 33 34 35 36 37 |
# File 'lib/fusuma/plugin/wmctrl/workspace.rb', line 32 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
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/fusuma/plugin/wmctrl/workspace.rb', line 101 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 "wmctrl -s #{workspace_num}" end |
#move_command_for_matrix(direction:) ⇒ Object
113 114 115 116 |
# File 'lib/fusuma/plugin/wmctrl/workspace.rb', line 113 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
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/fusuma/plugin/wmctrl/workspace.rb', line 118 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 "wmctrl -r :ACTIVE: -t #{workspace_num} ; wmctrl -s #{workspace_num}" end |
#move_window_command_for_matrix(direction:) ⇒ Object
130 131 132 133 |
# File 'lib/fusuma/plugin/wmctrl/workspace.rb', line 130 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
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fusuma/plugin/wmctrl/workspace.rb', line 39 def must_have_matrix_option! return if @matrix_col_size warn(" Please set matrix-col-size to config.yml\n\n ```config.yaml\n plugin:\n executors:\n wmctrl_executor:\n matrix-col-size: 2\n ```\n ERRRORMESSAGE\n raise InvalidOption, 'You need to set matrix option to config.yml'\nend\n") |
#next_workspace_num(step:) ⇒ Integer
get next workspace number
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fusuma/plugin/wmctrl/workspace.rb', line 14 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 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
57 58 59 60 61 62 63 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 |
# File 'lib/fusuma/plugin/wmctrl/workspace.rb', line 57 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 current_workspace_num - (col_size - 1) else current_workspace_num end when 'left' if x.positive? current_workspace_num - 1 elsif current_workspace_num + (col_size - 1) else current_workspace_num end when 'down' if y < row_size - 1 current_workspace_num + col_size elsif (current_workspace_num + col_size) - total_workspace_num else current_workspace_num end when 'up' if y.positive? current_workspace_num - col_size elsif total_workspace_num + (current_workspace_num - col_size) else current_workspace_num end else raise "#{direction} is invalid key" end end |