diff options
Diffstat (limited to 'sway/workspace.c')
-rw-r--r-- | sway/workspace.c | 61 |
1 files changed, 26 insertions, 35 deletions
diff --git a/sway/workspace.c b/sway/workspace.c index 4c8bb62f..ca9f5ef0 100644 --- a/sway/workspace.c +++ b/sway/workspace.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include "config.h" | 11 | #include "config.h" |
12 | #include "stringop.h" | 12 | #include "stringop.h" |
13 | #include "focus.h" | 13 | #include "focus.h" |
14 | #include "util.h" | ||
14 | 15 | ||
15 | char *workspace_next_name(void) { | 16 | char *workspace_next_name(void) { |
16 | sway_log(L_DEBUG, "Workspace: Generating new name"); | 17 | sway_log(L_DEBUG, "Workspace: Generating new name"); |
@@ -102,31 +103,27 @@ void workspace_output_next() { | |||
102 | } | 103 | } |
103 | 104 | ||
104 | void workspace_next() { | 105 | void workspace_next() { |
105 | // Get the index of the workspace in the current output, and change the view to index+1 workspace. | 106 | // Get the index of the workspace in the current output, and change the focus to index+1 workspace. |
106 | // if we're currently focused on the last workspace in the output, change focus to there | 107 | // if we're currently focused on the last workspace in the output, change focus to the next output |
107 | // and call workspace_output_next(), as long as another output actually exists | 108 | // and call workspace_output_next() |
109 | |||
108 | swayc_t *current_output = swayc_active_workspace()->parent; | 110 | swayc_t *current_output = swayc_active_workspace()->parent; |
109 | int i; | 111 | int i; |
110 | for (i = 0; i < current_output->children->length - 1; i++) { | 112 | for (i = 0; i < current_output->children->length - 1; i++) { |
111 | if (strcmp((((swayc_t *)current_output->children->items[i])->name), swayc_active_workspace()->name) == 0) { | 113 | if (current_output->children->items[i] == swayc_active_workspace()) { |
112 | workspace_switch(current_output->children->items[i + 1]); | 114 | workspace_switch(current_output->children->items[i + 1]); |
113 | return; | 115 | return; |
114 | } | 116 | } |
115 | } | 117 | } |
116 | if (root_container.children->length > 1) { | 118 | |
117 | for (i = 0; i < root_container.children->length - 1; i++) { | 119 | int num_outputs = root_container.children->length; |
118 | if (root_container.children->items[i] == current_output) { | 120 | for (i = 0; i < num_outputs; i++) { |
119 | workspace_switch(((swayc_t *)root_container.children->items[i + 1])->focused); | 121 | if (root_container.children->items[i] == current_output) { |
120 | workspace_output_next(); | 122 | swayc_t *next_output = root_container.children->items[wrap(++i, num_outputs)]; |
121 | return; | 123 | workspace_switch(next_output->focused); |
122 | } | 124 | workspace_output_next(); |
125 | return; | ||
123 | } | 126 | } |
124 | // If we're at the last output, then go to the first | ||
125 | workspace_switch(((swayc_t *)root_container.children->items[0])->focused); | ||
126 | workspace_output_next(); | ||
127 | return; | ||
128 | } else { | ||
129 | workspace_switch(current_output->children->items[0]); | ||
130 | } | 127 | } |
131 | } | 128 | } |
132 | 129 | ||
@@ -145,34 +142,28 @@ void workspace_output_prev() { | |||
145 | } | 142 | } |
146 | 143 | ||
147 | void workspace_prev() { | 144 | void workspace_prev() { |
148 | // Get the index of the workspace in the current output, and change the view to index-1 workspace. | 145 | // Get the index of the workspace in the current output, and change the focus to index-1 workspace. |
149 | // if we're currently focused on the last workspace in the output, change focus to there | 146 | // if we're currently focused on the first workspace in the output, change focus to the previous output |
150 | // and call workspace_output_next(), as long as another output actually exists | 147 | // and call workspace_output_prev() |
151 | 148 | ||
152 | swayc_t *current_output = swayc_active_workspace()->parent; | 149 | swayc_t *current_output = swayc_active_workspace()->parent; |
153 | int i; | 150 | int i; |
154 | for (i = 1; i < current_output->children->length; i++) { | 151 | for (i = 1; i < current_output->children->length; i++) { |
155 | if (strcmp((((swayc_t *)current_output->children->items[i])->name), swayc_active_workspace()->name) == 0) { | 152 | if (current_output->children->items[i] == swayc_active_workspace()) { |
156 | workspace_switch(current_output->children->items[i - 1]); | 153 | workspace_switch(current_output->children->items[i - 1]); |
157 | return; | 154 | return; |
158 | } | 155 | } |
159 | } | 156 | } |
160 | if (root_container.children->length > 1) { | 157 | |
161 | for (i = 1; i < root_container.children->length; i++) { | 158 | int num_outputs = root_container.children->length; |
162 | if (root_container.children->items[i] == current_output) { | 159 | for (i = 0; i < num_outputs; i++) { |
163 | workspace_switch(((swayc_t *)root_container.children->items[i - 1])->focused); | 160 | if (root_container.children->items[i] == current_output) { |
164 | workspace_output_next(); | 161 | swayc_t *prev_output = root_container.children->items[wrap(--i, num_outputs)]; |
165 | return; | 162 | workspace_switch(prev_output->focused); |
166 | } | 163 | workspace_output_prev(); |
164 | return; | ||
167 | } | 165 | } |
168 | // If we're at the first output, then go to the last | ||
169 | workspace_switch(((swayc_t *)root_container.children->items[root_container.children->length-1])->focused); | ||
170 | workspace_output_next(); | ||
171 | return; | ||
172 | } else { | ||
173 | workspace_switch(current_output->children->items[current_output->children->length - 1]); | ||
174 | } | 166 | } |
175 | |||
176 | } | 167 | } |
177 | 168 | ||
178 | void workspace_switch(swayc_t *workspace) { | 169 | void workspace_switch(swayc_t *workspace) { |