From 4f0813c94d839dc577189a8056f0cf506a4285d3 Mon Sep 17 00:00:00 2001 From: Ryan McBride Date: Thu, 15 Jan 2009 08:27:56 +0000 Subject: [PATCH] next/prev window swap logic that sucks less. --- scrotwm.c | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/scrotwm.c b/scrotwm.c index 66fb627..f1c498d 100644 --- a/scrotwm.c +++ b/scrotwm.c @@ -458,36 +458,26 @@ swapwin(union arg *args) switch (args->id) { case SWM_ARG_ID_SWAPPREV: target = TAILQ_PREV(ws[current_ws].focus, ws_win_list, entry); - if (target == NULL) - target = TAILQ_LAST(&ws[current_ws].winlist, - ws_win_list); - if (target == ws[current_ws].focus) - return; TAILQ_REMOVE(&ws[current_ws].winlist, ws[current_ws].focus, entry); - TAILQ_INSERT_BEFORE(target, ws[current_ws].focus, entry); + if (target == NULL) + TAILQ_INSERT_TAIL(&ws[current_ws].winlist, + ws[current_ws].focus, entry); + else + TAILQ_INSERT_BEFORE(target, ws[current_ws].focus, + entry); break; - case SWM_ARG_ID_SWAPNEXT: { - int loop = 0; - + case SWM_ARG_ID_SWAPNEXT: target = TAILQ_NEXT(ws[current_ws].focus, entry); - if (target == NULL) { - loop = 1; - target = TAILQ_FIRST(&ws[current_ws].winlist); - } - if (target == ws[current_ws].focus) - return; TAILQ_REMOVE(&ws[current_ws].winlist, ws[current_ws].focus, entry); - TAILQ_INSERT_AFTER(&ws[current_ws].winlist, target, - ws[current_ws].focus, entry); - if (loop) { - TAILQ_REMOVE(&ws[current_ws].winlist, target, entry); - TAILQ_INSERT_TAIL(&ws[current_ws].winlist, - target, entry); - } + if (target == NULL) + TAILQ_INSERT_HEAD(&ws[current_ws].winlist, + ws[current_ws].focus, entry); + else + TAILQ_INSERT_AFTER(&ws[current_ws].winlist, target, + ws[current_ws].focus, entry); break; - } case SWM_ARG_ID_SWAPMAIN: target = TAILQ_FIRST(&ws[current_ws].winlist); if (target == ws[current_ws].focus) -- 1.7.10.4