X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=client.c;h=8aca2e278b266fcc7414be06bba1e5de4400571f;hb=005362043d8b0bbf856f301c231d4f10c519b8c4;hp=a5141ea64b7ec6b394ed1d555bee97dda7aff063;hpb=439e15d09f6fa9271d3b49ef97194f0c80ebe161;p=dwm.git diff --git a/client.c b/client.c index a5141ea..8aca2e2 100644 --- a/client.c +++ b/client.c @@ -3,6 +3,7 @@ * See LICENSE file for license details. */ +#include #include #include @@ -14,7 +15,7 @@ update_client_name(Client *c) { XTextProperty name; int n; - char **list = 0; + char **list = NULL; name.nitems = 0; c->name[0] = 0; @@ -36,10 +37,10 @@ update_client_name(Client *c) XFree(name.value); } -Client * -create_client(Window w, XWindowAttributes *wa) +void +manage(Window w, XWindowAttributes *wa) { - Client *c; + Client *c, **l; XSetWindowAttributes twa; long msize; @@ -51,7 +52,6 @@ create_client(Window w, XWindowAttributes *wa) c->r[RFloat].height = wa->height; c->border = wa->border_width; XSetWindowBorderWidth(dpy, c->win, 0); - c->proto = win_proto(c->win); XGetTransientForHint(dpy, c->win, &c->trans); if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags) c->size.flags = PSize; @@ -59,7 +59,6 @@ create_client(Window w, XWindowAttributes *wa) (c->size.flags & PMinSize && c->size.flags & PMaxSize && c->size.min_width == c->size.max_width && c->size.min_height == c->size.max_height); - XAddToSaveSet(dpy, c->win); update_client_name(c); twa.override_redirect = 1; twa.background_pixmap = ParentRelative; @@ -70,20 +69,50 @@ create_client(Window w, XWindowAttributes *wa) DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa); + + for(l=&clients; *l; l=&(*l)->next); + c->next = *l; /* *l == nil */ + *l = c; + XMapRaised(dpy, c->win); + XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); XFlush(dpy); +} -#if 0 - for(t=&client, i=0; *t; t=&(*t)->next, i++); - c->next = *t; /* *t == nil */ - *t = c; -#endif - return c; +static int +dummy_error_handler(Display *dpy, XErrorEvent *error) +{ + return 0; } void -manage(Client *c) +unmanage(Client *c) { - XMapRaised(dpy, c->win); - XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); + Client **l; + + XGrabServer(dpy); + XSetErrorHandler(dummy_error_handler); + + XUnmapWindow(dpy, c->win); + XDestroyWindow(dpy, c->title); + + for(l=&clients; *l && *l != c; l=&(*l)->next); + eassert(*l == c); + *l = c->next; + free(c); + XFlush(dpy); + XSetErrorHandler(error_handler); + XUngrabServer(dpy); + /*flush_masked_events(EnterWindowMask); ? */ +} + + +Client * +getclient(Window w) +{ + Client *c; + for(c = clients; c; c = c->next) + if(c->win == w) + return c; + return NULL; }