[hackers] [tabbed] movetab(): Move selected tab instead of switching || Markus Teich

From: <git_AT_suckless.org>
Date: Tue, 14 Oct 2014 18:42:32 +0200

commit 829980f28aa91f4837e047bd9e3b599bf6d655a6
Author: Markus Teich <markus.teich_AT_stusta.mhn.de>
Date: Tue Oct 7 17:15:59 2014 +0200

    movetab(): Move selected tab instead of switching
    
    Before this patch, movetab() just switched positions of the selected tab with
    the new position. This resulted in unexpected behaviour when „moving“ a tab over
    one end of the list.
    
    Now tabs are moved correctly by the specified amount of indizes.
    
    Signed-off-by: Christoph Lohmann <20h_AT_r-36.net>

diff --git a/tabbed.c b/tabbed.c
index 68281ac..cdd6bd3 100644
--- a/tabbed.c
+++ b/tabbed.c
_AT_@ -795,19 +795,19 @@ movetab(const Arg *arg) {
         int c;
         Client *new;
 
- if(sel < 0 || (arg->i == 0))
- return;
-
- c = sel + arg->i;
- while(c >= nclients)
- c -= nclients;
- while(c < 0)
+ c = (sel + arg->i) % nclients;
+ if(c < 0)
                 c += nclients;
 
- new = clients[c];
- clients[c] = clients[sel];
- clients[sel] = new;
+ if(sel < 0 || (c == sel))
+ return;
 
+ new = clients[sel];
+ if(sel < c)
+ memmove(&clients[sel], &clients[sel+1], sizeof(Client *) * (c - sel));
+ else
+ memmove(&clients[c+1], &clients[c], sizeof(Client *) * (sel - c));
+ clients[c] = new;
         sel = c;
 
         drawbar();
Received on Tue Oct 14 2014 - 18:42:32 CEST

This archive was generated by hypermail 2.3.0 : Tue Oct 14 2014 - 18:48:17 CEST