From 984145243d1759052120466bf409948a797d03cc Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Sat, 29 Oct 2011 16:49:05 +0200 Subject: [PATCH] Add working reload (without global replacement) --- src/client.c | 3 ++- src/wmfs.c | 44 ++++++++++++++++++++++++++++---------------- src/wmfs.h | 4 ++-- wmfsrc2 | 3 ++- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/client.c b/src/client.c index 2366472..2c902a0 100644 --- a/src/client.c +++ b/src/client.c @@ -904,7 +904,8 @@ client_remove(struct client *c) { XGrabServer(W->dpy); XSetErrorHandler(wmfs_error_handler_dummy); - XReparentWindow(W->dpy, c->win, W->root, c->geo.x, c->geo.y); + XReparentWindow(W->dpy, c->win, W->root, c->rgeo.x, c->rgeo.y); + WIN_STATE(c->win, Map); XDestroyWindow(W->dpy, c->frame); if(c->titlebar) diff --git a/src/wmfs.c b/src/wmfs.c index 4c96c33..7179a04 100644 --- a/src/wmfs.c +++ b/src/wmfs.c @@ -261,7 +261,7 @@ wmfs_loop(void) { if(FD_ISSET(fd, &iset)) { - while(XPending(W->dpy)) + while(W->running && XPending(W->dpy)) { XNextEvent(W->dpy, &ev); EVENT_HANDLE(&ev); @@ -289,6 +289,7 @@ wmfs_quit(void) { struct keybind *k; struct theme *t; + struct client *c; /* Will free: * @@ -298,17 +299,14 @@ wmfs_quit(void) screen_free(); XFreeGC(W->dpy, W->rgc); - XCloseDisplay(W->dpy); - /* Conf stuffs */ - while(!SLIST_EMPTY(&W->h.keybind)) + while(!SLIST_EMPTY(&W->h.client)) { - k = SLIST_FIRST(&W->h.keybind); - SLIST_REMOVE_HEAD(&W->h.keybind, next); - free((void*)k->cmd); - free(k); + c = SLIST_FIRST(&W->h.client); + client_remove(c); } + /* Conf stuffs */ while(!SLIST_EMPTY(&W->h.theme)) { t = SLIST_FIRST(&W->h.theme); @@ -317,18 +315,24 @@ wmfs_quit(void) free(t); } + while(!SLIST_EMPTY(&W->h.keybind)) + { + k = SLIST_FIRST(&W->h.keybind); + SLIST_REMOVE_HEAD(&W->h.keybind, next); + free((void*)k->cmd); + free(k); + } + /* FIFO stuffs */ if(W->fifo.fd > 0) { close(W->fifo.fd); unlink(W->fifo.path); } - free(W->fifo.path); - - free(W->net_atom); - free(W); W->running = false; + + XCloseDisplay(W->dpy); } /** Reload WMFS binary @@ -337,21 +341,25 @@ void uicb_reload(Uicb cmd) { (void)cmd; - /* TODO */ + + W->running = false; + W->reload = true; } void uicb_quit(Uicb cmd) { (void)cmd; + W->running = false; } int main(int argc, char **argv) { - W = (struct wmfs*)xcalloc(1, sizeof(struct wmfs)); + bool r; + W = (struct wmfs*)xcalloc(1, sizeof(struct wmfs)); /* Get X display */ if(!(W->dpy = XOpenDisplay(NULL))) @@ -380,10 +388,14 @@ main(int argc, char **argv) /* Core */ wmfs_init(); wmfs_scan(); - wmfs_loop(); - wmfs_quit(); + r = W->reload; + free(W); + + if(r) + execvp(argv[0], argv); + return 1; } diff --git a/src/wmfs.h b/src/wmfs.h index be912ca..7ba6f8d 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -222,7 +222,8 @@ struct wmfs Flags numlockmask; GC gc, rgc; Atom *net_atom; - bool running; + char **argv; + bool running, reload; /* FIFO stuffs */ struct @@ -258,7 +259,6 @@ void wmfs_quit(void); void uicb_reload(Uicb cmd); void uicb_quit(Uicb cmd); - /* Single global variable */ struct wmfs *W; diff --git a/wmfsrc2 b/wmfsrc2 index 3d3faa0..d72a5ea 100644 --- a/wmfsrc2 +++ b/wmfsrc2 @@ -105,7 +105,8 @@ [keys] [key] mod = {"Super"} key = "Return" func = "spawn" cmd = "xterm" [/key] - [key] mod = {"Control","Alt"} key = "q" func = "quit" [/key] + [key] mod = {"Control", "Alt"} key = "q" func = "quit" [/key] + [key] mod = {"Control", "Alt"} key = "r" func = " reload" [/key] [key] mod = {"Super"} key = "1" func = "tag_set" cmd = "1" [/key] [key] mod = {"Super"} key = "2" func = "tag_set" cmd = "2" [/key] [key] mod = {"Super"} key = "3" func = "tag_set" cmd = "3" [/key]