dwm-meillo

diff client.c @ 10:703255003abb

changed how manage client works
author Anselm R. Garbe <garbeam@wmii.de>
date Tue, 11 Jul 2006 13:02:22 +0200
parents d567f430a81d
children 5cc5e55a132d
line diff
     1.1 --- a/client.c	Tue Jul 11 12:52:57 2006 +0200
     1.2 +++ b/client.c	Tue Jul 11 13:02:22 2006 +0200
     1.3 @@ -3,6 +3,7 @@
     1.4   * See LICENSE file for license details.
     1.5   */
     1.6  
     1.7 +#include <stdlib.h>
     1.8  #include <string.h>
     1.9  #include <X11/Xatom.h>
    1.10  
    1.11 @@ -36,10 +37,10 @@
    1.12  	XFree(name.value);
    1.13  }
    1.14  
    1.15 -Client *
    1.16 -create_client(Window w, XWindowAttributes *wa)
    1.17 +void
    1.18 +manage(Window w, XWindowAttributes *wa)
    1.19  {
    1.20 -	Client *c;
    1.21 +	Client *c, **l;
    1.22  	XSetWindowAttributes twa;
    1.23  	long msize;
    1.24  
    1.25 @@ -68,24 +69,44 @@
    1.26  			DefaultDepth(dpy, screen), CopyFromParent,
    1.27  			DefaultVisual(dpy, screen),
    1.28  			CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
    1.29 -	XFlush(dpy);
    1.30  
    1.31 -#if 0
    1.32 -	for(t=&client, i=0; *t; t=&(*t)->next, i++);
    1.33 -	c->next = *t; /* *t == nil */
    1.34 -	*t = c;
    1.35 -#endif
    1.36 -	return c;
    1.37 -}
    1.38 -
    1.39 -void
    1.40 -manage(Client *c)
    1.41 -{
    1.42 +	for(l=&clients; *l; l=&(*l)->next);
    1.43 +	c->next = *l; /* *l == nil */
    1.44 +	*l = c;
    1.45  	XMapRaised(dpy, c->win);
    1.46  	XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
    1.47  	XFlush(dpy);
    1.48  }
    1.49  
    1.50 +static int
    1.51 +dummy_error_handler(Display *dpy, XErrorEvent *error)
    1.52 +{
    1.53 +	return 0;
    1.54 +}
    1.55 +
    1.56 +void
    1.57 +unmanage(Client *c)
    1.58 +{
    1.59 +	Client **l;
    1.60 +
    1.61 +	XGrabServer(dpy);
    1.62 +	XSetErrorHandler(dummy_error_handler);
    1.63 +
    1.64 +	XUnmapWindow(dpy, c->win);
    1.65 +	XDestroyWindow(dpy, c->title);
    1.66 +
    1.67 +	for(l=&clients; *l && *l != c; l=&(*l)->next);
    1.68 +	eassert(*l == c);
    1.69 +	*l = c->next;
    1.70 +	free(c);
    1.71 +
    1.72 +	XFlush(dpy);
    1.73 +	XSetErrorHandler(error_handler);
    1.74 +	XUngrabServer(dpy);
    1.75 +	/*flush_masked_events(EnterWindowMask); ? */
    1.76 +}
    1.77 +
    1.78 +
    1.79  Client *
    1.80  getclient(Window w)
    1.81  {