From f36c830a493dff69725eb5cc84d9ae6d02226057 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Thu, 27 May 2010 22:10:14 -0400 Subject: [PATCH] Fix some bugs. --- cmd/wmii/client.c | 2 +- include/stuff/x11.h | 1 + lib/libstuff/x11/windows/destroywindow.c | 8 +++++++- lib/libstuff/x11/windows/findwin.c | 13 +++++++++---- lib/libstuff/x11/windows/window.c | 2 +- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/cmd/wmii/client.c b/cmd/wmii/client.c index adb5ba3f..fa60612a 100644 --- a/cmd/wmii/client.c +++ b/cmd/wmii/client.c @@ -314,7 +314,7 @@ client_destroy(Client *c) { event("DestroyClient %#C\n", c); event_flush(FocusChangeMask, true); - free(c->w.hints); + cleanupwindow(&c->w); free(c); } diff --git a/include/stuff/x11.h b/include/stuff/x11.h index 77be6557..50536828 100644 --- a/include/stuff/x11.h +++ b/include/stuff/x11.h @@ -239,6 +239,7 @@ void changeproperty(Window*, char*, char*, int width, uchar*, int); void clientmessage(Window*, char*, long, int, ClientMessageData); void copyimage(Image*, Rectangle, Image*, Point); Window* createwindow(Window*, Rectangle, int depth, uint class, WinAttr*, int valuemask); +void cleanupwindow(Window*); Window* createwindow_visual(Window*, Rectangle, int depth, Visual*, uint class, WinAttr*, int); void delproperty(Window*, char*); void destroywindow(Window*); diff --git a/lib/libstuff/x11/windows/destroywindow.c b/lib/libstuff/x11/windows/destroywindow.c index 2420d01f..8f5db933 100644 --- a/lib/libstuff/x11/windows/destroywindow.c +++ b/lib/libstuff/x11/windows/destroywindow.c @@ -4,15 +4,21 @@ #include "../x11.h" void -destroywindow(Window *w) { +cleanupwindow(Window *w) { assert(w->type == WWindow); sethandler(w, nil); while(w->handler_link) pophandler(w, w->handler_link->handler); + free(w->hints); if(w->xft) xft->drawdestroy(w->xft); if(w->gc) XFreeGC(display, w->gc); +} + +void +destroywindow(Window *w) { + cleanupwindow(w); XDestroyWindow(display, w->xid); free(w); } diff --git a/lib/libstuff/x11/windows/findwin.c b/lib/libstuff/x11/windows/findwin.c index ff012767..d9edd50e 100644 --- a/lib/libstuff/x11/windows/findwin.c +++ b/lib/libstuff/x11/windows/findwin.c @@ -2,13 +2,18 @@ * See LICENSE file for license details. */ #include "../x11.h" +#include Window* -findwin(XWindow w) { +findwin(XWindow xw) { + Window *w; void **e; - e = map_get(&windowmap, (ulong)w, false); - if(e) - return *e; + e = map_get(&windowmap, (ulong)xw, false); + if(e) { + w = *e; + assert(w->xid == xw); + return w; + } return nil; } diff --git a/lib/libstuff/x11/windows/window.c b/lib/libstuff/x11/windows/window.c index fce51fac..9b1b7533 100644 --- a/lib/libstuff/x11/windows/window.c +++ b/lib/libstuff/x11/windows/window.c @@ -7,7 +7,7 @@ Window* window(XWindow xw) { Window *w; - w = malloc(sizeof *w); + w = emallocz(sizeof *w); w->type = WWindow; w->xid = xw; return freelater(w);