]> git.sur5r.net Git - i3/i3/blobdiff - src/floating.c
Bugfix: don’t kill parent when currently in tree_close() for a child of this parent
[i3/i3] / src / floating.c
index ab41ed609d255cdae57e39b3e5c17e3036b2ee8c..005f2092c48fffd420c5a523975bcb1f6cff4dc7 100644 (file)
@@ -32,7 +32,16 @@ void floating_enable(Con *con, bool automatic) {
     /* 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);
+
+    char *name;
+    asprintf(&name, "[i3 con] floatingcon around %p", con);
+    x_set_name(nc, name);
+    free(name);
+
     nc->rect = con->rect;
     /* add pixels for the decoration */
     /* TODO: don’t add them when the user automatically puts new windows into
@@ -53,9 +62,18 @@ void floating_enable(Con *con, bool automatic) {
      * to (0, 0), so we push them to a reasonable position
      * (centered over their leader) */
     if (nc->rect.x == 0 && nc->rect.y == 0) {
-        /* TODO: client_leader support */
-        nc->rect.x = 400;
-        nc->rect.y = 400;
+        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);
+        }
     }
 
     TAILQ_INSERT_TAIL(&(nc->nodes_head), con, nodes);
@@ -77,7 +95,7 @@ void floating_disable(Con *con, bool automatic) {
     /* 2: kill parent container */
     TAILQ_REMOVE(&(con->parent->parent->floating_head), con->parent, floating_windows);
     TAILQ_REMOVE(&(con->parent->parent->focus_head), con->parent, focused);
-    tree_close(con->parent, false);
+    tree_close(con->parent, false, false);
 
     /* 3: re-attach to previous parent */
     con->parent = con->old_parent;