From a22b4c1008c18f8cff303e84c5fb4c0f43e3a72c Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 25 Sep 2007 12:41:36 +0200 Subject: [PATCH] new feature: add swap{next,prev} for reordering visible windows --- awesomerc | 2 ++ client.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ client.h | 2 ++ config.c | 2 ++ 4 files changed, 76 insertions(+) diff --git a/awesomerc b/awesomerc index f44835e69..f29731ade 100644 --- a/awesomerc +++ b/awesomerc @@ -70,6 +70,8 @@ awesome: (("Mod4"), "b", "togglebar"), (("Mod4"), "j", "focusnext"), (("Mod4"), "k", "focusprev"), + (("Mod4", "Shift"), "j", "swapnext"), + (("Mod4", "Shift"), "k", "swapprev"), (("Mod4", "Control"), "j", "focusnextscreen"), (("Mod4", "Control"), "k", "focusprevscreen"), (("Mod4"), "h", "setmwfact", "-0.05"), diff --git a/client.c b/client.c index f0d817e41..044dce9fb 100644 --- a/client.c +++ b/client.c @@ -182,6 +182,39 @@ setclienttrans(Client *c, double opacity) XSync(c->display, False); } +/** Swap two client in the linked list clients + * \param c1 first client + * \param c2 second client + */ +static void +client_swap(Client *c1, Client *c2) +{ + Client *tmp; + + tmp = c1->next; + c1->next = c2->next; + c2->next = (tmp == c2 ? c1 : tmp); + + tmp = c2->prev; + c2->prev = c1->prev; + c1->prev = (tmp == c1 ? c2 : tmp ); + + if(c1->next) + c1->next->prev = c1; + + if(c1->prev) + c1->prev->next = c1; + + if(c2->next) + c2->next->prev = c2; + + if(c2->prev) + c2->prev->next = c2; + + if(clients == c1) + clients = c2; +} + /** Attach client to the beginning of the clients stack * \param c the client */ @@ -742,3 +775,40 @@ uicb_setborder(Display *disp __attribute__ ((unused)), awesomeconf->borderpx = 0; } +void +uicb_swapnext(Display *disp, + DC *drawcontext, + awesome_config *awesomeconf, + const char *arg __attribute__ ((unused))) +{ + Client *next; + + if(!sel) + return; + + for(next = sel->next; next && !isvisible(next, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); next = next->next); + if(next) + { + client_swap(sel, next); + arrange(disp, drawcontext, awesomeconf); + } +} + +void +uicb_swapprev(Display *disp, + DC *drawcontext, + awesome_config *awesomeconf, + const char *arg __attribute__ ((unused))) +{ + Client *prev; + + if(!sel) + return; + + for(prev = sel->prev; prev && !isvisible(prev, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); prev = prev->prev); + if(prev) + { + client_swap(prev, sel); + arrange(disp, drawcontext, awesomeconf); + } +} diff --git a/client.h b/client.h index 686980e07..137fda5d5 100644 --- a/client.h +++ b/client.h @@ -72,5 +72,7 @@ UICB_PROTO(uicb_killclient); UICB_PROTO(uicb_moveresize); UICB_PROTO(uicb_settrans); UICB_PROTO(uicb_setborder); +UICB_PROTO(uicb_swapnext); +UICB_PROTO(uicb_swapprev); #endif diff --git a/config.c b/config.c index 2b71c1b70..1a1459723 100644 --- a/config.c +++ b/config.c @@ -89,6 +89,8 @@ static const NameFuncLink KeyfuncList[] = { {"moveresize", uicb_moveresize}, {"settrans", uicb_settrans}, {"setborder", uicb_setborder}, + {"swapnext", uicb_swapnext}, + {"swapprev", uicb_swapprev}, /* tag.c */ {"tag", uicb_tag}, {"togglefloating", uicb_togglefloating},