diff options
author | Luminarys <kizunanohikari@gmail.com> | 2015-08-19 19:57:24 -0500 |
---|---|---|
committer | Luminarys <kizunanohikari@gmail.com> | 2015-08-19 19:57:39 -0500 |
commit | 29b6b2f37b3a3ec05c48c00103360b2297912e69 (patch) | |
tree | a44c2c33d7e707979a7837424e0674d624ccb812 | |
parent | Improve key handling somewhat (diff) | |
download | sway-29b6b2f37b3a3ec05c48c00103360b2297912e69.tar.gz sway-29b6b2f37b3a3ec05c48c00103360b2297912e69.tar.zst sway-29b6b2f37b3a3ec05c48c00103360b2297912e69.zip |
Fixed mode_toggle
-rw-r--r-- | sway/commands.c | 51 |
1 files changed, 39 insertions, 12 deletions
diff --git a/sway/commands.c b/sway/commands.c index f87ab0e5..f3553b03 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -231,19 +231,7 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) { | |||
231 | return true; | 231 | return true; |
232 | } | 232 | } |
233 | set_focused_container(view); | 233 | set_focused_container(view); |
234 | } else if (strcasecmp(argv[0], "mode_toggle") == 0) { | ||
235 | if (get_focused_view(active_workspace)->is_floating) { | ||
236 | if (active_workspace->children->length > 0) { | ||
237 | set_focused_container(get_focused_view(active_workspace->children->items[0])); | ||
238 | } | ||
239 | } else { | ||
240 | if (active_workspace->floating->length > 0) { | ||
241 | swayc_t *floating = active_workspace->floating->items[active_workspace->floating->length-1]; | ||
242 | set_focused_container(get_focused_view(floating)); | ||
243 | } | ||
244 | } | ||
245 | } | 234 | } |
246 | |||
247 | return true; | 235 | return true; |
248 | } | 236 | } |
249 | 237 | ||
@@ -272,6 +260,8 @@ static bool cmd_floating_mod(struct sway_config *config, int argc, char **argv) | |||
272 | } | 260 | } |
273 | 261 | ||
274 | static bool cmd_focus(struct sway_config *config, int argc, char **argv) { | 262 | static bool cmd_focus(struct sway_config *config, int argc, char **argv) { |
263 | static int floating_toggled_index = 0; | ||
264 | static int tiled_toggled_index = 0; | ||
275 | if (!checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1)) { | 265 | if (!checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1)) { |
276 | return false; | 266 | return false; |
277 | } | 267 | } |
@@ -285,7 +275,44 @@ static bool cmd_focus(struct sway_config *config, int argc, char **argv) { | |||
285 | return move_focus(MOVE_DOWN); | 275 | return move_focus(MOVE_DOWN); |
286 | } else if (strcasecmp(argv[0], "parent") == 0) { | 276 | } else if (strcasecmp(argv[0], "parent") == 0) { |
287 | return move_focus(MOVE_PARENT); | 277 | return move_focus(MOVE_PARENT); |
278 | } else if (strcasecmp(argv[0], "mode_toggle") == 0) { | ||
279 | int i; | ||
280 | swayc_t *focused = get_focused_view(active_workspace); | ||
281 | if (focused->is_floating) { | ||
282 | if (active_workspace->children->length > 0) { | ||
283 | for (i = 0;i < active_workspace->floating->length; i++) { | ||
284 | if (active_workspace->floating->items[i] == focused) { | ||
285 | floating_toggled_index = i; | ||
286 | break; | ||
287 | } | ||
288 | } | ||
289 | if (active_workspace->children->length > tiled_toggled_index) { | ||
290 | set_focused_container(get_focused_view(active_workspace->children->items[tiled_toggled_index])); | ||
291 | } else { | ||
292 | set_focused_container(get_focused_view(active_workspace->children->items[0])); | ||
293 | tiled_toggled_index = 0; | ||
294 | } | ||
295 | } | ||
296 | } else { | ||
297 | if (active_workspace->floating->length > 0) { | ||
298 | for (i = 0;i < active_workspace->children->length; i++) { | ||
299 | if (active_workspace->children->items[i] == focused) { | ||
300 | tiled_toggled_index = i; | ||
301 | break; | ||
302 | } | ||
303 | } | ||
304 | if (active_workspace->floating->length > floating_toggled_index) { | ||
305 | swayc_t *floating = active_workspace->floating->items[floating_toggled_index]; | ||
306 | set_focused_container(get_focused_view(floating)); | ||
307 | } else { | ||
308 | swayc_t *floating = active_workspace->floating->items[active_workspace->floating->length - 1]; | ||
309 | set_focused_container(get_focused_view(floating)); | ||
310 | tiled_toggled_index = active_workspace->floating->length - 1; | ||
311 | } | ||
312 | } | ||
313 | } | ||
288 | } | 314 | } |
315 | |||
289 | return true; | 316 | return true; |
290 | } | 317 | } |
291 | 318 | ||