added "toggle" option to "split" command

as requested in #1814
This commit is contained in:
Johannes Lange 2016-01-04 17:31:47 +01:00
parent a9f31b9dc9
commit 8bfd06c3dd
5 changed files with 62 additions and 13 deletions

View File

@ -1750,20 +1750,24 @@ get placed below the current one (splitv).
If you apply this command to a split container with the same orientation, If you apply this command to a split container with the same orientation,
nothing will happen. If you use a different orientation, the split containers nothing will happen. If you use a different orientation, the split containers
orientation will be changed (if it does not have more than one window). Use orientation will be changed (if it does not have more than one window).
+layout toggle split+ to change the layout of any split container from splitv The +toggle+ option will toggle the orientation of the split container if it
to splith or vice-versa. contains a single window. Otherwise it makes the current window a split
container with opposite orientation compared to the parent container.
Use +layout toggle split+ to change the layout of any split container from
splitv to splith or vice-versa.
*Syntax*: *Syntax*:
------------------------- --------------------------------
split vertical|horizontal split vertical|horizontal|toggle
------------------------- --------------------------------
*Example*: *Example*:
------------------------------ -------------------------------
bindsym $mod+v split vertical bindsym $mod+v split vertical
bindsym $mod+h split horizontal bindsym $mod+h split horizontal
------------------------------ bindsym $mod+t split toggle
-------------------------------
=== Manipulating layout === Manipulating layout

View File

@ -157,7 +157,7 @@ void cmd_floating(I3_CMD, const char *floating_mode);
void cmd_move_workspace_to_output(I3_CMD, const char *name); void cmd_move_workspace_to_output(I3_CMD, const char *name);
/** /**
* Implementation of 'split v|h|vertical|horizontal'. * Implementation of 'split v|h|t|vertical|horizontal|toggle'.
* *
*/ */
void cmd_split(I3_CMD, const char *direction); void cmd_split(I3_CMD, const char *direction);

View File

@ -191,9 +191,9 @@ state STICKY:
action = 'enable', 'disable', 'toggle' action = 'enable', 'disable', 'toggle'
-> call cmd_sticky($action) -> call cmd_sticky($action)
# split v|h|vertical|horizontal # split v|h|t|vertical|horizontal|toggle
state SPLIT: state SPLIT:
direction = 'horizontal', 'vertical', 'v', 'h' direction = 'horizontal', 'vertical', 'toggle', 'v', 'h', 't'
-> call cmd_split($direction) -> call cmd_split($direction)
# floating enable|disable|toggle # floating enable|disable|toggle

View File

@ -1228,7 +1228,7 @@ void cmd_move_workspace_to_output(I3_CMD, const char *name) {
} }
/* /*
* Implementation of 'split v|h|vertical|horizontal'. * Implementation of 'split v|h|t|vertical|horizontal|toggle'.
* *
*/ */
void cmd_split(I3_CMD, const char *direction) { void cmd_split(I3_CMD, const char *direction) {
@ -1243,7 +1243,22 @@ void cmd_split(I3_CMD, const char *direction) {
} }
DLOG("matching: %p / %s\n", current->con, current->con->name); DLOG("matching: %p / %s\n", current->con, current->con->name);
tree_split(current->con, (direction[0] == 'v' ? VERT : HORIZ)); if (direction[0] == 't') {
layout_t current_layout;
if (current->con->type == CT_WORKSPACE) {
current_layout = current->con->layout;
} else {
current_layout = current->con->parent->layout;
}
/* toggling split orientation */
if (current_layout == L_SPLITH) {
tree_split(current->con, VERT);
} else {
tree_split(current->con, HORIZ);
}
} else {
tree_split(current->con, (direction[0] == 'v' ? VERT : HORIZ));
}
} }
cmd_output->needs_tree_render = true; cmd_output->needs_tree_render = true;

View File

@ -178,4 +178,34 @@ is(@{$content}, 2, 'two containers on workspace');
is(@{$fst->{nodes}}, 2, 'first child has two children'); is(@{$fst->{nodes}}, 2, 'first child has two children');
is(@{$snd->{nodes}}, 0, 'second child has no children'); is(@{$snd->{nodes}}, 0, 'second child has no children');
######################################################################
# Test split toggle
######################################################################
$tmp = fresh_workspace;
cmd 'split h';
cmd 'split toggle';
$ws = get_ws($tmp);
is($ws->{layout}, 'splitv', 'toggled workspace split');
$tmp = fresh_workspace;
cmd 'split h';
cmd 'split toggle';
cmd 'split toggle';
$ws = get_ws($tmp);
is($ws->{layout}, 'splith', 'toggled workspace back and forth');
cmd 'open';
cmd 'open';
cmd 'split toggle';
$content = get_ws_content($tmp);
my $second = $content->[1];
is($second->{layout}, 'splitv', 'toggled container orientation to vertical');
cmd 'split toggle';
$content = get_ws_content($tmp);
$second = $content->[1];
is($second->{layout}, 'splith', 'toggled container orientation back to horizontal');
done_testing; done_testing;