*/
Con *con_for_window(i3Window *window, Match **store_match);
+/**
+ * Returns the number of children of this container.
+ *
+ */
+int con_num_children(Con *con);
+
/**
* Attaches the given container to the given parent. This happens when moving
* a container or when inserting a new container at a specific place in the
return NULL;
}
+/*
+ * Returns the number of children of this container.
+ *
+ */
+int con_num_children(Con *con) {
+ Con *child;
+ int children = 0;
+
+ TAILQ_FOREACH(child, &(con->nodes_head), nodes)
+ children++;
+
+ return children;
+}
+
/*
* Updates the percent attribute of the children of the given container. This
* function needs to be called when a window is added or removed from a
*/
void con_fix_percent(Con *con, int action) {
Con *child;
- int children = 0;
- TAILQ_FOREACH(child, &(con->nodes_head), nodes)
- children++;
+ int children = con_num_children(con);
/* TODO: better document why this math works */
double fix;
if (action == WINDOW_ADD)
if (con->border_style == BS_NONE)
return (Rect){0, 0, 0, 0};
+
+ assert(false);
}
void render_con(Con *con) {
printf("currently rendering node %p / %s / layout %d\n",
con, con->name, con->layout);
- int children = 0;
- Con *child;
- TAILQ_FOREACH(child, &(con->nodes_head), nodes)
- children++;
+ int children = con_num_children(con);
printf("children: %d, orientation = %d\n", children, con->orientation);
/* Copy container rect, subtract container border */
return;
}
+ Con *child;
TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
/* default layout */
void tree_move(char way, orientation_t orientation) {
/* 1: get the first parent with the same orientation */
Con *parent = focused->parent;
+ Con *old_parent = parent;
if (focused->type == CT_WORKSPACE)
return;
bool level_changed = false;
TAILQ_INSERT_HEAD(&(next->parent->focus_head), focused, focused);
/* TODO: don’t influence focus handling? */
}
+
+ if (con_num_children(old_parent) == 0) {
+ DLOG("Old container empty after moving. Let's close it\n");
+ tree_close(old_parent, false);
+ }
}
# 3) move a container inside another container
# 4) move a container in a different direction so that we need to go up in tree
#
-use i3test tests => 16;
+use i3test tests => 17;
use X11::XCB qw(:all);
my $i3 = i3("/tmp/nestedcons");
$content = get_ws_content($tmp);
is(@{$content}, 2, 'two nodes on this workspace');
+######################################################################
+# 4) Move a container horizontally when inside a vertical split container.
+# The container will be moved to the workspace level and the old vsplit
+# container needs to be closed. Verify that it will be closed.
+######################################################################
+
+my $otmp = get_unused_workspace();
+$i3->command("workspace $otmp")->recv;
+
+$i3->command("open")->recv;
+$i3->command("split v")->recv;
+$i3->command("move after h")->recv;
+
+$content = get_ws_content($otmp);
+is(@{$content}, 1, 'only one nodes on this workspace');
+
diag( "Testing i3, Perl $], $^X" );