]> git.sur5r.net Git - i3/i3/blobdiff - src/con.c
Implement dock mode, update testsuite
[i3/i3] / src / con.c
index c04d281e909161a9cfc05756294ad5d020be3837..b1e652a28f8499616e5caf34f1a6b29d0df22224 100644 (file)
--- a/src/con.c
+++ b/src/con.c
@@ -24,6 +24,8 @@ char *colors[] = {
     "#aa00aa"
 };
 
+static void con_on_remove_child(Con *con);
+
 /*
  * Create a new container (and attach it to the given parent, if not NULL).
  * This function initializes the data structures and creates the appropriate
@@ -32,6 +34,7 @@ char *colors[] = {
  */
 Con *con_new(Con *parent) {
     Con *new = scalloc(sizeof(Con));
+    new->on_remove_child = con_on_remove_child;
     TAILQ_INSERT_TAIL(&all_cons, new, all_cons);
     new->type = CT_CON;
     new->border_style = config.default_border;
@@ -223,10 +226,32 @@ Con *con_get_workspace(Con *con) {
     Con *result = con;
     while (result != NULL && result->type != CT_WORKSPACE)
         result = result->parent;
-    assert(result != NULL);
     return result;
 }
 
+/*
+ * Searches parenst of the given 'con' until it reaches one with the specified
+ * 'orientation'. Aborts when it comes across a floating_con.
+ *
+ */
+Con *con_parent_with_orientation(Con *con, orientation_t orientation) {
+    DLOG("Searching for parent of Con %p with orientation %d\n", con, orientation);
+    Con *parent = con->parent;
+    if (parent->type == CT_FLOATING_CON)
+        return NULL;
+    while (con_orientation(parent) != orientation) {
+        DLOG("Need to go one level further up\n");
+        parent = parent->parent;
+        /* Abort when we reach a floating con */
+        if (parent && parent->type == CT_FLOATING_CON)
+            parent = NULL;
+        if (parent == NULL)
+            break;
+    }
+    DLOG("Result: %p\n", parent);
+    return parent;
+}
+
 /*
  * helper data structure for the breadth-first-search in
  * con_get_fullscreen_con()
@@ -522,14 +547,7 @@ void con_move_to_workspace(Con *con, Con *workspace) {
     /* 8: keep focus on the current workspace */
     con_focus(focus_next);
 
-    /* 9: check if the parent container is empty now and close it */
-    if (parent->type != CT_WORKSPACE &&
-        TAILQ_EMPTY(&(parent->nodes_head))) {
-        DLOG("Closing empty parent container\n");
-        /* TODO: check if this container would swallow any other client and
-         * don’t close it automatically. */
-        tree_close(parent, false, false);
-    }
+    CALL(parent, on_remove_child);
 }
 
 /*
@@ -675,6 +693,8 @@ Rect con_border_style_rect(Con *con) {
  * borderless and the only element in the tabbed container, the border is not
  * rendered.
  *
+ * For children of a CT_DOCKAREA, the border style is always none.
+ *
  */
 int con_border_style(Con *con) {
     Con *fs = con_get_fullscreen_con(con->parent);
@@ -689,6 +709,9 @@ int con_border_style(Con *con) {
     if (con->parent->layout == L_TABBED && con->border_style != BS_NORMAL)
         return (con_num_children(con->parent) == 1 ? con->border_style : BS_NORMAL);
 
+    if (con->parent->type == CT_DOCKAREA)
+        return BS_NONE;
+
     return con->border_style;
 }
 
@@ -744,3 +767,32 @@ void con_set_layout(Con *con, int layout) {
 
     con->layout = layout;
 }
+
+/*
+ * Callback which will be called when removing a child from the given con.
+ * Kills the container if it is empty and replaces it with the child if there
+ * is exactly one child.
+ *
+ */
+static void con_on_remove_child(Con *con) {
+    DLOG("on_remove_child\n");
+
+    /* Every container 'above' (in the hierarchy) the workspace content should
+     * not be closed when the last child was removed */
+    if (con->type == CT_WORKSPACE ||
+        con->type == CT_OUTPUT ||
+        con->type == CT_ROOT ||
+        con->type == CT_DOCKAREA) {
+        DLOG("not handling, type = %d\n", con->type);
+        return;
+    }
+
+    /* TODO: check if this container would swallow any other client and
+     * don’t close it automatically. */
+    int children = con_num_children(con);
+    if (children == 0) {
+        DLOG("Container empty, closing\n");
+        tree_close(con, false, false);
+        return;
+    }
+}