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.
---



Heyho,

In movetab() the current method is to switch two tabs with each other. If you
only use the +1 and -1 arguments from config.def.h, this works well and has the
expected effect in most cases. However when moveing a tab over one end of the
list, it just gets switched with the one on the other end of the list which is
surprising and strange if you expect the tab to _move_ as the function suggests.

The following patch fixes that by using memmove.

--Markus



 tabbed.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/tabbed.c b/tabbed.c
index 68281ac..cdd6bd3 100644
--- a/tabbed.c
+++ b/tabbed.c
@@ -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();
-- 
1.8.5.5


Reply via email to