From e4110591aeaaf14c782e6245a77637baf26b4500 Mon Sep 17 00:00:00 2001 From: Ivan Kanakarakis Date: Wed, 7 Dec 2011 16:16:35 +0200 Subject: fix remove_window()->removeclient() function and calls rename remove_window to removeclient fix logic - no need to loop fix calls to remove_window->removeclient to pass the client as argument, not the window --- dminiwm.c | 69 +++++++++++++++++++++++++++------------------------------------ 1 file changed, 29 insertions(+), 40 deletions(-) diff --git a/dminiwm.c b/dminiwm.c index 1d21ac6..265498c 100644 --- a/dminiwm.c +++ b/dminiwm.c @@ -121,7 +121,7 @@ static void next_win(const Arg arg); static void prev_win(const Arg arg); static void cleanup(void); static void quit(const Arg arg); -static void remove_window(Window w); +static void removeclient(client *c); static void resize_master(const Arg arg); static void resize_stack(const Arg arg); static void save_desktop(int i); @@ -217,49 +217,35 @@ void add_window(Window w) { XSelectInput(dis, c->win, EnterWindowMask); } -void remove_window(Window w) { - client *c; - - /* FIXME: change this ugly code */ - for(c=head;c;c=c->next) { - - if(c->win == w) { - if(c->prev == NULL && c->next == NULL) { - free(head); - head = NULL; - current = NULL; - save_desktop(current_desktop); - return; - } - - if(c->prev == NULL) { - head = c->next; - c->next->prev = NULL; - current = c->next; - } - else if(c->next == NULL) { - c->prev->next = NULL; - current = c->prev; - } - else { - c->prev->next = c->next; - c->next->prev = c->prev; - current = c->prev; - } - - free(c); - save_desktop(current_desktop); - tile(); - update_current(); - return; +void removeclient(client *c) { + if(c->prev == NULL) { /* w is head */ + if(c->next == NULL) { /* head is only window on screen */ + free(head); + head = NULL; + } else { /* more windows on screen */ + head->next->prev = NULL; + head = head->next; + } + current = head; + } else { /* w is on stack */ + if(c->next == NULL) { /* w is last window on screen */ + c->prev->next = NULL; + } else { /* w is somewhere in the middle */ + c->next->prev = c->prev; + c->prev->next = c->next; } + current = c->prev; } + + save_desktop(current_desktop); + tile(); + update_current(); } void killclient(const Arg arg) { if(current == NULL) return; deletewindow(current->win); - remove_window(current->win); + removeclient(current); } void next_win(const Arg arg) { @@ -391,7 +377,7 @@ void client_to_desktop(const Arg arg) { // Remove client from current desktop select_desktop(cd); XUnmapWindow(dis, cc->win); - remove_window(cc->win); + removeclient(cc); save_desktop(cd); tile(); update_current(); @@ -733,11 +719,14 @@ void destroynotify(XEvent *e) { for(j=0;jnext) - if(ev->window == c->win) + if(ev->window == c->win) { i++; + break; + } if(i != 0) { - remove_window(ev->window); + //remove_window(ev->window); + removeclient(c); select_desktop(tmp); return; } -- cgit v1.3.1