]> git.sur5r.net Git - i3/i3/blobdiff - src/scratchpad.c
fix crash: send non-floating window with floating parent to scratchpad (thanks pkordy)
[i3/i3] / src / scratchpad.c
index 6bba823fa2893512ad1f66924414935b08f0c744..7b30909554040360233317dd7f70bdeedb9ff28b 100644 (file)
@@ -39,11 +39,17 @@ void scratchpad_move(Con *con) {
         return;
     }
 
-    /* 1: Ensure the window is floating. From now on, we deal with the
-     * CT_FLOATING_CON. We use automatic == false because the user made the
-     * choice that this window should be a scratchpad (and floating). */
-    floating_enable(con, false);
-    con = con->parent;
+    /* 1: Ensure the window or any parent is floating. From now on, we deal
+     * with the CT_FLOATING_CON. We use automatic == false because the user
+     * made the choice that this window should be a scratchpad (and floating).
+     */
+    Con *maybe_floating_con = con_inside_floating(con);
+    if (maybe_floating_con == NULL) {
+        floating_enable(con, false);
+        con = con->parent;
+    } else {
+        con = maybe_floating_con;
+    }
 
     /* 2: Send the window to the __i3_scratch workspace, mainting its
      * coordinates and not warping the pointer. */
@@ -60,7 +66,8 @@ void scratchpad_move(Con *con) {
 
     /* 4: Fix focus. Normally, when moving a window to a different output, the
      * destination output gets focused. In this case, we don’t want that. */
-    con_focus(focus_next);
+    if (con_get_workspace(focus_next) == con_get_workspace(focused))
+        con_focus(focus_next);
 }
 
 /*
@@ -77,6 +84,16 @@ void scratchpad_show(Con *con) {
     Con *__i3_scratch = workspace_get("__i3_scratch", NULL);
     Con *floating;
 
+    /* If the current con or any of its parents are in fullscreen mode, we
+     * first need to disable it before showing the scratchpad con. */
+    Con *fs = focused;
+    while (fs && fs->fullscreen_mode == CF_NONE)
+        fs = fs->parent;
+
+    if (fs->type != CT_WORKSPACE) {
+        con_toggle_fullscreen(focused, CF_OUTPUT);
+    }
+
     /* If this was 'scratchpad show' without criteria, we check if the
      * currently focused window is a scratchpad window and should be hidden
      * again. */