]> git.sur5r.net Git - i3/i3/commitdiff
refactor workspace_show and friends
authorNoe Rubinstein <noe.rubinstein@gmail.com>
Sun, 2 Oct 2011 15:54:23 +0000 (17:54 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Sun, 2 Oct 2011 20:57:00 +0000 (21:57 +0100)
include/workspace.h
src/cmdparse.y
src/con.c
src/randr.c
src/tree.c
src/workspace.c

index aebf13656d866e8b15e3de5a03678f3bb9f3baed..7eee9d3d798b2054655884486fd453a8d12019f2 100644 (file)
@@ -47,19 +47,20 @@ void workspace_set_name(Workspace *ws, const char *name);
 bool workspace_is_visible(Con *ws);
 
 /** Switches to the given workspace */
-void workspace_show(const char *num);
+void workspace_show(Con *ws);
+void workspace_show_by_name(const char *num);
 
 /**
- * Focuses the next workspace.
+ * Returns the next workspace.
  *
  */
-void workspace_next();
+Con* workspace_next();
 
 /**
- * Focuses the previous workspace.
+ * Returns the previous workspace.
  *
  */
-void workspace_prev();
+Con* workspace_prev();
 
 #if 0
 /**
index 04e8b3ca3f4cb0a8f66337a2132b5e2ceb90223f..252f6dff4c1511753336cb7913e0566d1b6766bf 100644 (file)
@@ -440,7 +440,7 @@ focus:
         int count = 0;
         TAILQ_FOREACH(current, &owindows, owindows) {
             Con *ws = con_get_workspace(current->con);
-            workspace_show(ws->name);
+            workspace_show(ws);
             LOG("focusing %p / %s\n", current->con, current->con->name);
             con_focus(current->con);
             count++;
@@ -561,18 +561,18 @@ optional_kill_mode:
 workspace:
     TOK_WORKSPACE TOK_NEXT
     {
-        workspace_next();
+        workspace_show(workspace_next());
         tree_render();
     }
     | TOK_WORKSPACE TOK_PREV
     {
-        workspace_prev();
+        workspace_show(workspace_prev());
         tree_render();
     }
     | TOK_WORKSPACE STR
     {
         printf("should switch to workspace %s\n", $2);
-        workspace_show($2);
+        workspace_show_by_name($2);
         free($2);
 
         tree_render();
index 8fbedd3d608561e9346942184335256a65d2a0c1..805d33b8c36f05a845db439ef8432142a3947d9e 100644 (file)
--- a/src/con.c
+++ b/src/con.c
@@ -632,7 +632,7 @@ void con_move_to_workspace(Con *con, Con *workspace, bool fix_coordinates, bool
          * focused. Must do before attaching because workspace_show checks to see
          * if focused container is in its area. */
         if (workspace_is_visible(workspace)) {
-            workspace_show(workspace->name);
+            workspace_show(workspace);
 
             /* Don’t warp if told so (when dragging floating windows with the
              * mouse for example) */
@@ -668,7 +668,7 @@ void con_move_to_workspace(Con *con, Con *workspace, bool fix_coordinates, bool
         /* Descend focus stack in case focus_next is a workspace which can
          * occur if we move to the same workspace.  Also show current workspace
          * to ensure it is focused. */
-        workspace_show(con_get_workspace(focus_next)->name);
+        workspace_show(con_get_workspace(focus_next));
         con_focus(con_descend_focused(focus_next));
     }
 
index 2b8757e5c25dc674647df2728d5f0fb1b1c1f352..f5f5d19828dc44010da43c960e3fbd5e3f4d5d17 100644 (file)
@@ -363,7 +363,7 @@ void init_ws_for_output(Output *output, Con *content) {
         if (visible && (previous = TAILQ_NEXT(workspace, focused))) {
             LOG("Switching to previously used workspace \"%s\" on output \"%s\"\n",
                 previous->name, workspace_out->name);
-            workspace_show(previous->name);
+            workspace_show(previous);
         }
 
         con_detach(workspace);
@@ -390,7 +390,7 @@ void init_ws_for_output(Output *output, Con *content) {
         if (!visible) {
             visible = TAILQ_FIRST(&(content->nodes_head));
             focused = content;
-            workspace_show(visible->name);
+            workspace_show(visible);
         }
         return;
     }
@@ -403,7 +403,7 @@ void init_ws_for_output(Output *output, Con *content) {
         LOG("Initializing first assigned workspace \"%s\" for output \"%s\"\n",
             assignment->name, assignment->output);
         focused = content;
-        workspace_show(assignment->name);
+        workspace_show_by_name(assignment->name);
         return;
     }
 
index 4baba58eed118118a85d99818c901ac6c603942d..8c73b6ab57eff07531b90e3c96faabe6eaadd668 100644 (file)
@@ -420,7 +420,7 @@ static bool _tree_next(Con *con, char way, orientation_t orientation, bool wrap)
         if (!workspace)
             return false;
 
-        workspace_show(workspace->name);
+        workspace_show(workspace);
         Con *focus = con_descend_direction(workspace, direction);
         if (focus) {
             con_focus(focus);
index 325644598453e98b337f756ccd988fd21dbb3223..a89029c49d55cc76203c50b50e60f8a303b102fb 100644 (file)
@@ -180,11 +180,8 @@ static void workspace_reassign_sticky(Con *con) {
  * Switches to the given workspace
  *
  */
-void workspace_show(const char *num) {
-    Con *workspace, *current, *old = NULL;
-
-    bool changed_num_workspaces;
-    workspace = workspace_get(num, &changed_num_workspaces);
+void workspace_show_changed(Con *workspace, bool changed_num_workspaces) {
+    Con *current, *old = NULL;
 
     /* disable fullscreen for the other workspaces and get the workspace we are
      * currently on. */
@@ -238,11 +235,22 @@ void workspace_show(const char *num) {
     ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"focus\"}");
 }
 
+void workspace_show(Con *workspace) { 
+    workspace_show_changed(workspace, false);
+}
+
+void workspace_show_by_name(const char *num) {
+    Con *workspace;
+    bool changed_num_workspaces;
+    workspace = workspace_get(num, &changed_num_workspaces);
+    workspace_show_changed(workspace, changed_num_workspaces);
+}
+
 /*
  * Focuses the next workspace.
  *
  */
-void workspace_next() {
+Con* workspace_next() {
     Con *current = con_get_workspace(focused);
     Con *next = NULL;
     Con *output;
@@ -277,7 +285,7 @@ void workspace_next() {
                     found_current = 1;
                 } else if (child->num == -1 && (current->num != -1 || found_current)) {
                     next = child;
-                    goto workspace_next_show;
+                    goto workspace_next_end;
                 }
             }
     }
@@ -292,16 +300,15 @@ void workspace_next() {
                     next = child;
             }
     }
-
-workspace_next_show:
-    workspace_show(next->name);
+workspace_next_end:
+    return next;
 }
 
 /*
  * Focuses the previous workspace.
  *
  */
-void workspace_prev() {
+Con* workspace_prev() {
     Con *current = con_get_workspace(focused);
     Con *prev = NULL;
     Con *output;
@@ -336,7 +343,7 @@ void workspace_prev() {
                     found_current = 1;
                 } else if (child->num == -1 && (current->num != -1 || found_current)) {
                     prev = child;
-                    goto workspace_prev_show;
+                    goto workspace_prev_end;
                 }
             }
     }
@@ -352,8 +359,8 @@ void workspace_prev() {
             }
     }
 
-workspace_prev_show:
-    workspace_show(prev->name);
+workspace_prev_end:
+    return prev;
 }
 
 static bool get_urgency_flag(Con *con) {