]> git.sur5r.net Git - i3/i3/blobdiff - src/workspace.c
Implement 'fullscreen global'
[i3/i3] / src / workspace.c
index 385921a40ff42c11f3c9c1a2aa9de5fe980ac834..4021dd14419abbdf01bf6534ff52638171a18454 100644 (file)
@@ -41,7 +41,7 @@ Con *workspace_get(const char *num, bool *created) {
         LOG("got output %p with content %p\n", output, content);
         /* We need to attach this container after setting its type. con_attach
          * will handle CT_WORKSPACEs differently */
-        workspace = con_new(NULL);
+        workspace = con_new(NULL, NULL);
         char *name;
         asprintf(&name, "[i3 con] workspace %s", num);
         x_set_name(workspace, name);
@@ -95,7 +95,7 @@ bool workspace_is_visible(Con *ws) {
     Con *output = con_get_output(ws);
     if (output == NULL)
         return false;
-    Con *fs = con_get_fullscreen_con(output);
+    Con *fs = con_get_fullscreen_con(output, CF_OUTPUT);
     LOG("workspace visible? fs = %p, ws = %p\n", fs, ws);
     return (fs == ws);
 }
@@ -231,6 +231,32 @@ void workspace_show(const char *num) {
     ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"focus\"}");
 }
 
+/*
+ * Focuses the next workspace.
+ *
+ */
+void workspace_next() {
+    Con *ws = con_get_workspace(focused);
+    Con *next = TAILQ_NEXT(ws, nodes);
+    if (!next)
+        next = TAILQ_FIRST(&(ws->parent->nodes_head));
+
+    workspace_show(next->name);
+}
+
+/*
+ * Focuses the previous workspace.
+ *
+ */
+void workspace_prev() {
+    Con *ws = con_get_workspace(focused);
+    Con *prev = TAILQ_PREV(ws, nodes_head, nodes);
+    if (!prev)
+        prev = TAILQ_LAST(&(ws->parent->nodes_head), nodes_head);
+
+    workspace_show(prev->name);
+}
+
 static bool get_urgency_flag(Con *con) {
     Con *child;
     TAILQ_FOREACH(child, &(con->nodes_head), nodes)
@@ -266,7 +292,7 @@ void workspace_update_urgent_flag(Con *ws) {
  */
 void ws_force_orientation(Con *ws, orientation_t orientation) {
     /* 1: create a new split container */
-    Con *split = con_new(NULL);
+    Con *split = con_new(NULL, NULL);
     split->parent = ws;
 
     /* 2: copy layout and orientation from workspace */
@@ -296,3 +322,45 @@ void ws_force_orientation(Con *ws, orientation_t orientation) {
     if (old_focused)
         con_focus(old_focused);
 }
+
+/*
+ * Called when a new con (with a window, not an empty or split con) should be
+ * attached to the workspace (for example when managing a new window or when
+ * moving an existing window to the workspace level).
+ *
+ * Depending on the workspace_layout setting, this function either returns the
+ * workspace itself (default layout) or creates a new stacked/tabbed con and
+ * returns that.
+ *
+ */
+Con *workspace_attach_to(Con *ws) {
+    DLOG("Attaching a window to workspace %p / %s\n", ws, ws->name);
+
+    if (config.default_layout == L_DEFAULT) {
+        DLOG("Default layout, just attaching it to the workspace itself.\n");
+        return ws;
+    }
+
+    DLOG("Non-default layout, creating a new split container\n");
+    /* 1: create a new split container */
+    Con *new = con_new(NULL, NULL);
+    new->parent = ws;
+
+    /* 2: set the requested layout on the split con */
+    new->layout = config.default_layout;
+
+    /* 3: While the layout is irrelevant in stacked/tabbed mode, it needs
+     * to be set. Otherwise, this con will not be interpreted as a split
+     * container. */
+    if (config.default_orientation == NO_ORIENTATION) {
+        new->orientation = (ws->rect.height > ws->rect.width) ? VERT : HORIZ;
+    } else {
+        new->orientation = config.default_orientation;
+    }
+
+    /* 4: attach the new split container to the workspace */
+    DLOG("Attaching new split %p to workspace %p\n", new, ws);
+    con_attach(new, ws, false);
+
+    return new;
+}