From: Cedric Staub Date: Fri, 15 Jan 2010 15:30:28 +0000 (+0100) Subject: Feature: Cycle through workspaces X-Git-Tag: 3.e~6^2~163 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=c606d93630c46a030a7f0046319dd649e7cffe57;p=i3%2Fi3 Feature: Cycle through workspaces On command pw/nw, cycle through all workspaces (starting from previous/next one) until we reach the current one again. --- diff --git a/src/commands.c b/src/commands.c index 92b4aa8c..8205d224 100644 --- a/src/commands.c +++ b/src/commands.c @@ -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;