+ /* 4: attach the new split container to the workspace */
+ DLOG("Attaching new split to ws\n");
+ con_attach(new, con, false);
+
+ if (old_focused)
+ con_focus(old_focused);
+
+ con = new;
+ set_focus = false;
+ }
+
+ /* 1: detach the container from its parent */
+ /* TODO: refactor this with tree_close() */
+ TAILQ_REMOVE(&(con->parent->nodes_head), con, nodes);
+ TAILQ_REMOVE(&(con->parent->focus_head), con, focused);
+
+ con_fix_percent(con->parent);
+
+ /* 2: create a new container to render the decoration on, add
+ * it as a floating window to the workspace */
+ Con *nc = con_new(NULL);
+ /* we need to set the parent afterwards instead of passing it as an
+ * argument to con_new() because nc would be inserted into the tiling layer
+ * otherwise. */
+ nc->parent = con_get_workspace(con);
+
+ /* check if the parent container is empty and close it if so */
+ if ((con->parent->type == CT_CON || con->parent->type == CT_FLOATING_CON) && con_num_children(con->parent) == 0) {
+ DLOG("Old container empty after setting this child to floating, closing\n");
+ tree_close(con->parent, DONT_KILL_WINDOW, false);
+ }
+
+ char *name;
+ asprintf(&name, "[i3 con] floatingcon around %p", con);
+ x_set_name(nc, name);
+ free(name);
+
+ /* find the height for the decorations */
+ int deco_height = config.font.height + 5;
+
+ DLOG("Original rect: (%d, %d) with %d x %d\n", con->rect.x, con->rect.y, con->rect.width, con->rect.height);
+ Rect zero = { 0, 0, 0, 0 };
+ nc->rect = con->geometry;
+ /* If the geometry was not set (split containers), we need to determine a
+ * sensible one by combining the geometry of all children */
+ if (memcmp(&(nc->rect), &zero, sizeof(Rect)) == 0) {
+ DLOG("Geometry not set, combining children\n");
+ Con *child;
+ TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
+ DLOG("child geometry: %d x %d\n", child->geometry.width, child->geometry.height);
+ nc->rect.width += child->geometry.width;
+ nc->rect.height = max(nc->rect.height, child->geometry.height);
+ }
+ }
+ /* Raise the width/height to at least 75x50 (minimum size for windows) */
+ nc->rect.width = max(nc->rect.width, 75);
+ nc->rect.height = max(nc->rect.height, 50);
+ /* add pixels for the decoration */
+ /* TODO: don’t add them when the user automatically puts new windows into
+ * 1pixel/borderless mode */
+ nc->rect.height += deco_height + 4;
+ nc->rect.width += 4;
+ DLOG("Floating rect: (%d, %d) with %d x %d\n", nc->rect.x, nc->rect.y, nc->rect.width, nc->rect.height);
+ nc->orientation = NO_ORIENTATION;
+ nc->type = CT_FLOATING_CON;
+ TAILQ_INSERT_TAIL(&(nc->parent->floating_head), nc, floating_windows);
+ TAILQ_INSERT_TAIL(&(nc->parent->focus_head), nc, focused);
+
+ /* 3: attach the child to the new parent container */
+ con->parent = nc;
+ con->percent = 1.0;
+ con->floating = FLOATING_USER_ON;
+
+ /* Some clients (like GIMP’s color picker window) get mapped
+ * to (0, 0), so we push them to a reasonable position
+ * (centered over their leader) */
+ if (nc->rect.x == 0 && nc->rect.y == 0) {
+ Con *leader;
+ if (con->window && con->window->leader != XCB_NONE &&
+ (leader = con_by_window_id(con->window->leader)) != NULL) {
+ DLOG("Centering above leader\n");
+ nc->rect.x = leader->rect.x + (leader->rect.width / 2) - (nc->rect.width / 2);
+ nc->rect.y = leader->rect.y + (leader->rect.height / 2) - (nc->rect.height / 2);
+ } else {
+ /* center the window on workspace as fallback */
+ Con *ws = nc->parent;
+ nc->rect.x = ws->rect.x + (ws->rect.width / 2) - (nc->rect.width / 2);
+ nc->rect.y = ws->rect.y + (ws->rect.height / 2) - (nc->rect.height / 2);
+ }
+ }