commit 29b6b2f37b3a3ec05c48c00103360b2297912e69
parent 1d8591d9026c19f5c308bed5961341b00aef69ca
Author: Luminarys <kizunanohikari@gmail.com>
Date: Wed, 19 Aug 2015 19:57:24 -0500
Fixed mode_toggle
Diffstat:
1 file changed, 39 insertions(+), 12 deletions(-)
diff --git a/sway/commands.c b/sway/commands.c
@@ -231,19 +231,7 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) {
return true;
}
set_focused_container(view);
- } else if (strcasecmp(argv[0], "mode_toggle") == 0) {
- if (get_focused_view(active_workspace)->is_floating) {
- if (active_workspace->children->length > 0) {
- set_focused_container(get_focused_view(active_workspace->children->items[0]));
- }
- } else {
- if (active_workspace->floating->length > 0) {
- swayc_t *floating = active_workspace->floating->items[active_workspace->floating->length-1];
- set_focused_container(get_focused_view(floating));
- }
- }
}
-
return true;
}
@@ -272,6 +260,8 @@ static bool cmd_floating_mod(struct sway_config *config, int argc, char **argv)
}
static bool cmd_focus(struct sway_config *config, int argc, char **argv) {
+ static int floating_toggled_index = 0;
+ static int tiled_toggled_index = 0;
if (!checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1)) {
return false;
}
@@ -285,7 +275,44 @@ static bool cmd_focus(struct sway_config *config, int argc, char **argv) {
return move_focus(MOVE_DOWN);
} else if (strcasecmp(argv[0], "parent") == 0) {
return move_focus(MOVE_PARENT);
+ } else if (strcasecmp(argv[0], "mode_toggle") == 0) {
+ int i;
+ swayc_t *focused = get_focused_view(active_workspace);
+ if (focused->is_floating) {
+ if (active_workspace->children->length > 0) {
+ for (i = 0;i < active_workspace->floating->length; i++) {
+ if (active_workspace->floating->items[i] == focused) {
+ floating_toggled_index = i;
+ break;
+ }
+ }
+ if (active_workspace->children->length > tiled_toggled_index) {
+ set_focused_container(get_focused_view(active_workspace->children->items[tiled_toggled_index]));
+ } else {
+ set_focused_container(get_focused_view(active_workspace->children->items[0]));
+ tiled_toggled_index = 0;
+ }
+ }
+ } else {
+ if (active_workspace->floating->length > 0) {
+ for (i = 0;i < active_workspace->children->length; i++) {
+ if (active_workspace->children->items[i] == focused) {
+ tiled_toggled_index = i;
+ break;
+ }
+ }
+ if (active_workspace->floating->length > floating_toggled_index) {
+ swayc_t *floating = active_workspace->floating->items[floating_toggled_index];
+ set_focused_container(get_focused_view(floating));
+ } else {
+ swayc_t *floating = active_workspace->floating->items[active_workspace->floating->length - 1];
+ set_focused_container(get_focused_view(floating));
+ tiled_toggled_index = active_workspace->floating->length - 1;
+ }
+ }
+ }
}
+
return true;
}