aewl
changeset 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 | ea9c08ec4b48 |
files | client.c event.c wm.c wm.h |
diffstat | 4 files changed, 47 insertions(+), 32 deletions(-) [+] |
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 {
2.1 --- a/event.c Tue Jul 11 12:52:57 2006 +0200 2.2 +++ b/event.c Tue Jul 11 13:02:22 2006 +0200 2.3 @@ -159,12 +159,8 @@ 2.4 return; 2.5 } 2.6 2.7 - /*if(!client_of_win(ev->window))*/ 2.8 - /*manage(create_client(ev->window, &wa));*/ 2.9 - XMapRaised(dpy, ev->window); 2.10 - XMoveResizeWindow(dpy, ev->window, rect.x, rect.y, rect.width, rect.height - barrect.height); 2.11 - XSetInputFocus(dpy, ev->window, RevertToPointerRoot, CurrentTime); 2.12 - XFlush(dpy); 2.13 + if(!getclient(ev->window)) 2.14 + manage(ev->window, &wa); 2.15 } 2.16 2.17 static void 2.18 @@ -185,11 +181,9 @@ 2.19 static void 2.20 unmapnotify(XEvent *e) 2.21 { 2.22 -#if 0 2.23 Client *c; 2.24 XUnmapEvent *ev = &e->xunmap; 2.25 2.26 - if((c = client_of_win(ev->window))) 2.27 - destroy_client(c); 2.28 -#endif 2.29 + if((c = getclient(ev->window))) 2.30 + unmanage(c); 2.31 }
3.1 --- a/wm.c Tue Jul 11 12:52:57 2006 +0200 3.2 +++ b/wm.c Tue Jul 11 13:02:22 2006 +0200 3.3 @@ -20,19 +20,18 @@ 3.4 Cursor cursor[CurLast]; 3.5 XRectangle rect, barrect; 3.6 Bool running = True; 3.7 -Client *clients = NULL; 3.8 3.9 char *bartext, tag[256]; 3.10 int screen, sel_screen; 3.11 3.12 -/* draw structs */ 3.13 Brush brush = {0}; 3.14 +Client *clients = NULL; 3.15 3.16 enum { WM_PROTOCOL_DELWIN = 1 }; 3.17 3.18 static Bool other_wm_running; 3.19 +static char version[] = "gridwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; 3.20 static int (*x_error_handler) (Display *, XErrorEvent *); 3.21 -static char version[] = "gridwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; 3.22 3.23 static void 3.24 usage() 3.25 @@ -56,7 +55,7 @@ 3.26 if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1)) 3.27 continue; 3.28 if(wa.map_state == IsViewable) 3.29 - manage(create_client(wins[i], &wa)); 3.30 + manage(wins[i], &wa); 3.31 } 3.32 } 3.33 if(wins) 3.34 @@ -69,7 +68,7 @@ 3.35 * Other types of errors call Xlib's default error handler, which 3.36 * calls exit(). 3.37 */ 3.38 -static int 3.39 +int 3.40 error_handler(Display *dpy, XErrorEvent *error) 3.41 { 3.42 if(error->error_code == BadWindow
4.1 --- a/wm.h Tue Jul 11 12:52:57 2006 +0200 4.2 +++ b/wm.h Tue Jul 11 13:02:22 2006 +0200 4.3 @@ -65,8 +65,8 @@ 4.4 extern void quit(char *arg); 4.5 4.6 /* client.c */ 4.7 -extern Client *create_client(Window w, XWindowAttributes *wa); 4.8 -extern void manage(Client *c); 4.9 +extern void manage(Window w, XWindowAttributes *wa); 4.10 +void unmanage(Client *c); 4.11 extern Client * getclient(Window w); 4.12 4.13 /* key.c */ 4.14 @@ -74,3 +74,4 @@ 4.15 extern void keypress(XEvent *e); 4.16 4.17 /* wm.c */ 4.18 +extern int error_handler(Display *dpy, XErrorEvent *error);