"#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
*/
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;
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()
*
*/
void con_move_to_workspace(Con *con, Con *workspace) {
+ if (con->type == CT_WORKSPACE) {
+ DLOG("Moving workspaces is not yet implemented.\n");
+ return;
+ }
+
if (con_is_floating(con)) {
DLOG("Using FLOATINGCON instead\n");
con = con->parent;
con->percent = 0.0;
con_fix_percent(next);
- /* 7: keep focus on the current workspace */
+ /* 7: focus the con on the target workspace (the X focus is only updated by
+ * calling tree_render(), so for the "real" focus this is a no-op) */
+ con_focus(con);
+
+ /* 8: keep focus on the current workspace */
con_focus(focus_next);
- /* 8: 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);
}
/*
* 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);
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;
}
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;
+ }
+}