]> git.sur5r.net Git - i3/i3/blobdiff - src/workspace.c
Bugfix: When moving floating cons to other workspaces, attach them to the workspace
[i3/i3] / src / workspace.c
index 4d3c521896924f24d215e56dba79921ec20c68c3..8104aa89fc35d6da21765408718255e5d06a0473 100644 (file)
@@ -59,7 +59,18 @@ Con *workspace_get(const char *num, bool *created) {
             workspace->num = -1;
         else workspace->num = parsed_num;
         LOG("num = %d\n", workspace->num);
-        workspace->orientation = HORIZ;
+
+        /* If default_orientation is set to NO_ORIENTATION we
+         * determine workspace orientation from workspace size.
+         * Otherwise we just set the orientation to default_orientation. */
+        if (config.default_orientation == NO_ORIENTATION) {
+            workspace->orientation = (output->rect.height > output->rect.width) ? VERT : HORIZ;
+            DLOG("Auto orientation. Output resolution set to (%d,%d), setting orientation to %d.\n",
+                 workspace->rect.width, workspace->rect.height, workspace->orientation);
+        } else {
+            workspace->orientation = config.default_orientation;
+        }
+
         con_attach(workspace, content, false);
 
         ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"init\"}");
@@ -70,8 +81,6 @@ Con *workspace_get(const char *num, bool *created) {
         *created = false;
     }
 
-    //ewmh_update_workarea();
-
     return workspace;
 }
 
@@ -206,7 +215,8 @@ static void workspace_reassign_sticky(Con *con) {
 void workspace_show(const char *num) {
     Con *workspace, *current, *old = NULL;
 
-    workspace = workspace_get(num, NULL);
+    bool changed_num_workspaces;
+    workspace = workspace_get(num, &changed_num_workspaces);
 
     /* disable fullscreen for the other workspaces and get the workspace we are
      * currently on. */
@@ -217,18 +227,13 @@ void workspace_show(const char *num) {
     }
     assert(old != NULL);
 
-    /* Check if the the currently focused con is on the same Output as the
-     * workspace we chose as 'old'. If not, use the workspace of the currently
-     * focused con */
-    Con *ws = con_get_workspace(focused);
-    if (ws && ws->parent != old->parent)
-        old = ws;
-
     /* enable fullscreen for the target workspace. If it happens to be the
      * same one we are currently on anyways, we can stop here. */
     workspace->fullscreen_mode = CF_OUTPUT;
-    if (workspace == old)
+    if (workspace == con_get_workspace(focused)) {
+        DLOG("Not switching, already there.\n");
         return;
+    }
 
     workspace_reassign_sticky(workspace);
 
@@ -241,6 +246,7 @@ void workspace_show(const char *num) {
             LOG("Closing old workspace (%p / %s), it is empty\n", old, old->name);
             tree_close(old, false, false);
             ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"empty\"}");
+            changed_num_workspaces = true;
         }
     }
 
@@ -248,6 +254,11 @@ void workspace_show(const char *num) {
     workspace->fullscreen_mode = CF_OUTPUT;
     LOG("focused now = %p / %s\n", focused, focused->name);
 
+    /* Update the EWMH hints */
+    if (changed_num_workspaces)
+        ewmh_update_workarea();
+    ewmh_update_current_desktop();
+
     ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"focus\"}");
 #if 0