[hackers] [tabbed] Fixed obscure miscalculation when a client is closed. || Alexander Sedov

From: <git_AT_suckless.org>
Date: Thu, 10 Oct 2013 18:47:07 +0200

commit 14beaabe6ccbdf12546f31edf931e30cbe9c0c82
Author: Alexander Sedov <alex0player_AT_gmail.com>
Date: Mon Jul 29 11:11:33 2013 +0400

    Fixed obscure miscalculation when a client is closed.
    
    This crops up whenever you just switched from tab # N+1 to tab # N
    and close current tab. unmanage() first decreases lastsel
    (so it becomes N) then erroneously tests it against sel and focuses first tab
    instead. One can see that focus() would never set lastsel == sel,
    so I took liberty to fix this annoying behaviour which happens to frequently
    with newposition = 0 and npisrelative = True settings.
    
    Signed-off-by: Christoph Lohmann <20h_AT_r-36.net>

diff --git a/tabbed.c b/tabbed.c
index 3df24c2..3a6e7f9 100644
--- a/tabbed.c
+++ b/tabbed.c
_AT_@ -171,12 +171,18 @@ void
 buttonpress(const XEvent *e) {
         const XButtonPressedEvent *ev = &e->xbutton;
         int i;
+ int fc;
         Arg arg;
 
- if((getfirsttab() != 0 && ev->x < TEXTW(before)) || ev->x < 0)
+ fc = getfirsttab();
+
+ if((fc > 0 && ev->x < TEXTW(before)) || ev->x < 0)
                 return;
 
- for(i = 0; i < nclients; i++) {
+ if(ev->y < 0 || ev-> y > bh)
+ return;
+
+ for(i = (fc > 0) ? fc : 0; i < nclients; i++) {
                 if(clients[i]->tabx > ev->x) {
                         switch(ev->button) {
                         case Button1:
_AT_@ -1053,7 +1059,11 @@ unmanage(int c) {
                 }
 
                 if(c == sel) {
- if(lastsel > 0 && lastsel != sel) {
+ /* Note that focus() will never set lastsel == sel,
+ * so if here lastsel == sel, it was decreased by above if() clause
+ * and was actually (sel + 1) before.
+ */
+ if(lastsel > 0) {
                                 focus(lastsel);
                         } else {
                                 focus(0);
Received on Thu Oct 10 2013 - 18:47:07 CEST

This archive was generated by hypermail 2.3.0 : Thu Oct 10 2013 - 18:48:24 CEST