]> git.sur5r.net Git - i3/i3/commitdiff
Feature: Cycle through workspaces
authorCedric Staub <cs.staub@cssx.ch>
Fri, 15 Jan 2010 15:30:28 +0000 (16:30 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Tue, 19 Jan 2010 11:10:45 +0000 (12:10 +0100)
On command pw/nw, cycle through all workspaces (starting from
previous/next one) until we reach the current one again.

src/commands.c

index 92b4aa8c98ddaa777402f17d6ed2c07d46474a1c..8205d224f57eb127b0794bbaf8f5a1a19bf90d32 100644 (file)
@@ -768,7 +768,15 @@ static void next_previous_workspace(xcb_connection_t *conn, int direction) {
         Workspace *ws = c_ws;
 
         if (direction == 'n') {
-                while ((ws = TAILQ_NEXT(ws, workspaces)) != TAILQ_END(workspaces_head)) {
+                while (1) {
+                        ws = TAILQ_NEXT(ws, workspaces);
+
+                        if (ws == TAILQ_END(workspaces))
+                                ws = TAILQ_FIRST(workspaces);
+
+                        if (ws == c_ws)
+                                return;
+
                         if (ws->screen == NULL)
                                 continue;
 
@@ -776,7 +784,15 @@ static void next_previous_workspace(xcb_connection_t *conn, int direction) {
                         return;
                 }
         } else if (direction == 'p') {
-                while ((ws = TAILQ_PREV(ws, workspaces_head, workspaces)) != TAILQ_END(workspaces)) {
+                while (1) {
+                        ws = TAILQ_PREV(ws, workspaces_head, workspaces);
+
+                        if (ws == TAILQ_END(workspaces))
+                                ws = TAILQ_LAST(workspaces, workspaces_head);
+
+                        if (ws == c_ws)
+                                return;
+
                         if (ws->screen == NULL)
                                 continue;