Split workspace instead of changing orientation
Patch status: merged
Patch by Mats
Long description:
Move all children of the workspace into a new container if there is more than one otherwise simply change the orientation. fixes #922
To apply this patch, use:
curl http://cr.i3wm.org/patch/13/raw.patch | git am
b/src/tree.c
18 |
@@ -366,17 +366,23 @@ void tree_close_con(kill_window_t kill_window) { |
19 |
* |
20 |
*/ |
21 |
void tree_split(Con *con, orientation_t orientation) { |
22 |
- /* for a workspace, we just need to change orientation */ |
23 |
- if (con->type == CT_WORKSPACE) { |
24 |
- DLOG("Workspace, simply changing orientation to %d\n", orientation); |
25 |
- con->layout = (orientation == HORIZ) ? L_SPLITH : L_SPLITV; |
26 |
- return; |
27 |
- } |
28 |
- else if (con->type == CT_FLOATING_CON) { |
29 |
+ if (con->type == CT_FLOATING_CON) { |
30 |
DLOG("Floating containers can't be split.\n"); |
31 |
return; |
32 |
} |
33 |
|
34 |
+ if (con->type == CT_WORKSPACE) { |
35 |
+ if (con_num_children(con) < 2) { |
36 |
+ DLOG("Just changing orientation of workspace\n"); |
37 |
+ con->layout = (orientation == HORIZ) ? L_SPLITH : L_SPLITV; |
38 |
+ return; |
39 |
+ } else { |
40 |
+ /* if there is more than one container on the workspace |
41 |
+ * move them into a new container and handle this instead */ |
42 |
+ con = workspace_encapsulate(con); |
43 |
+ } |
44 |
+ } |
45 |
+ |
46 |
Con *parent = con->parent; |
47 |
|
48 |
/* Force re-rendering to make the indicator border visible. */ |
b/testcases/t/122-split.t
53 |
@@ -158,4 +158,24 @@ is(get_output_content()->{layout}, 'splith', 'content container layout ok'); |
54 |
cmd 'layout stacked'; |
55 |
is(get_output_content()->{layout}, 'splith', 'content container layout still ok'); |
56 |
|
57 |
+###################################################################### |
58 |
+# Splitting a workspace that has more than one child |
59 |
+###################################################################### |
60 |
+ |
61 |
+$tmp = fresh_workspace; |
62 |
+ |
63 |
+cmd 'open'; |
64 |
+cmd 'open'; |
65 |
+cmd 'focus parent'; |
66 |
+cmd 'split v'; |
67 |
+cmd 'open'; |
68 |
+ |
69 |
+my $content = get_ws_content($tmp); |
70 |
+my $fst = $content->[0]; |
71 |
+my $snd = $content->[1]; |
72 |
+ |
73 |
+is(@{$content}, 2, 'two containers on workspace'); |
74 |
+is(@{$fst->{nodes}}, 2, 'first child has two children'); |
75 |
+is(@{$snd->{nodes}}, 0, 'second child has no children'); |
76 |
+ |
77 |
done_testing; |