aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuminarys <kizunanohikari@gmail.com>2015-08-19 19:57:24 -0500
committerLuminarys <kizunanohikari@gmail.com>2015-08-19 19:57:39 -0500
commit29b6b2f37b3a3ec05c48c00103360b2297912e69 (patch)
treea44c2c33d7e707979a7837424e0674d624ccb812
parent1d8591d9026c19f5c308bed5961341b00aef69ca (diff)
Fixed mode_toggle
-rw-r--r--sway/commands.c51
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) {
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;
}