summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client.c45
-rw-r--r--event.c14
-rw-r--r--wm.c9
-rw-r--r--wm.h5
4 files changed, 44 insertions, 29 deletions
diff --git a/client.c b/client.c
index 62f4d98..8aca2e2 100644
--- a/client.c
+++ b/client.c
@@ -3,6 +3,7 @@
3 * See LICENSE file for license details. 3 * See LICENSE file for license details.
4 */ 4 */
5 5
6#include <stdlib.h>
6#include <string.h> 7#include <string.h>
7#include <X11/Xatom.h> 8#include <X11/Xatom.h>
8 9
@@ -36,10 +37,10 @@ update_client_name(Client *c)
36 XFree(name.value); 37 XFree(name.value);
37} 38}
38 39
39Client * 40void
40create_client(Window w, XWindowAttributes *wa) 41manage(Window w, XWindowAttributes *wa)
41{ 42{
42 Client *c; 43 Client *c, **l;
43 XSetWindowAttributes twa; 44 XSetWindowAttributes twa;
44 long msize; 45 long msize;
45 46
@@ -68,24 +69,44 @@ create_client(Window w, XWindowAttributes *wa)
68 DefaultDepth(dpy, screen), CopyFromParent, 69 DefaultDepth(dpy, screen), CopyFromParent,
69 DefaultVisual(dpy, screen), 70 DefaultVisual(dpy, screen),
70 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa); 71 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
72
73 for(l=&clients; *l; l=&(*l)->next);
74 c->next = *l; /* *l == nil */
75 *l = c;
76 XMapRaised(dpy, c->win);
77 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
71 XFlush(dpy); 78 XFlush(dpy);
79}
72 80
73#if 0 81static int
74 for(t=&client, i=0; *t; t=&(*t)->next, i++); 82dummy_error_handler(Display *dpy, XErrorEvent *error)
75 c->next = *t; /* *t == nil */ 83{
76 *t = c; 84 return 0;
77#endif
78 return c;
79} 85}
80 86
81void 87void
82manage(Client *c) 88unmanage(Client *c)
83{ 89{
84 XMapRaised(dpy, c->win); 90 Client **l;
85 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); 91
92 XGrabServer(dpy);
93 XSetErrorHandler(dummy_error_handler);
94
95 XUnmapWindow(dpy, c->win);
96 XDestroyWindow(dpy, c->title);
97
98 for(l=&clients; *l && *l != c; l=&(*l)->next);
99 eassert(*l == c);
100 *l = c->next;
101 free(c);
102
86 XFlush(dpy); 103 XFlush(dpy);
104 XSetErrorHandler(error_handler);
105 XUngrabServer(dpy);
106 /*flush_masked_events(EnterWindowMask); ? */
87} 107}
88 108
109
89Client * 110Client *
90getclient(Window w) 111getclient(Window w)
91{ 112{
diff --git a/event.c b/event.c
index 909012d..870ed4a 100644
--- a/event.c
+++ b/event.c
@@ -159,12 +159,8 @@ maprequest(XEvent *e)
159 return; 159 return;
160 } 160 }
161 161
162 /*if(!client_of_win(ev->window))*/ 162 if(!getclient(ev->window))
163 /*manage(create_client(ev->window, &wa));*/ 163 manage(ev->window, &wa);
164 XMapRaised(dpy, ev->window);
165 XMoveResizeWindow(dpy, ev->window, rect.x, rect.y, rect.width, rect.height - barrect.height);
166 XSetInputFocus(dpy, ev->window, RevertToPointerRoot, CurrentTime);
167 XFlush(dpy);
168} 164}
169 165
170static void 166static void
@@ -185,11 +181,9 @@ propertynotify(XEvent *e)
185static void 181static void
186unmapnotify(XEvent *e) 182unmapnotify(XEvent *e)
187{ 183{
188#if 0
189 Client *c; 184 Client *c;
190 XUnmapEvent *ev = &e->xunmap; 185 XUnmapEvent *ev = &e->xunmap;
191 186
192 if((c = client_of_win(ev->window))) 187 if((c = getclient(ev->window)))
193 destroy_client(c); 188 unmanage(c);
194#endif
195} 189}
diff --git a/wm.c b/wm.c
index 8c5814f..ef4721d 100644
--- a/wm.c
+++ b/wm.c
@@ -20,19 +20,18 @@ Atom net_atom[NetLast];
20Cursor cursor[CurLast]; 20Cursor cursor[CurLast];
21XRectangle rect, barrect; 21XRectangle rect, barrect;
22Bool running = True; 22Bool running = True;
23Client *clients = NULL;
24 23
25char *bartext, tag[256]; 24char *bartext, tag[256];
26int screen, sel_screen; 25int screen, sel_screen;
27 26
28/* draw structs */
29Brush brush = {0}; 27Brush brush = {0};
28Client *clients = NULL;
30 29
31enum { WM_PROTOCOL_DELWIN = 1 }; 30enum { WM_PROTOCOL_DELWIN = 1 };
32 31
33static Bool other_wm_running; 32static Bool other_wm_running;
34static int (*x_error_handler) (Display *, XErrorEvent *);
35static char version[] = "gridwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; 33static char version[] = "gridwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
34static int (*x_error_handler) (Display *, XErrorEvent *);
36 35
37static void 36static void
38usage() 37usage()
@@ -56,7 +55,7 @@ scan_wins()
56 if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1)) 55 if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
57 continue; 56 continue;
58 if(wa.map_state == IsViewable) 57 if(wa.map_state == IsViewable)
59 manage(create_client(wins[i], &wa)); 58 manage(wins[i], &wa);
60 } 59 }
61 } 60 }
62 if(wins) 61 if(wins)
@@ -69,7 +68,7 @@ scan_wins()
69 * Other types of errors call Xlib's default error handler, which 68 * Other types of errors call Xlib's default error handler, which
70 * calls exit(). 69 * calls exit().
71 */ 70 */
72static int 71int
73error_handler(Display *dpy, XErrorEvent *error) 72error_handler(Display *dpy, XErrorEvent *error)
74{ 73{
75 if(error->error_code == BadWindow 74 if(error->error_code == BadWindow
diff --git a/wm.h b/wm.h
index 9ea74fe..68c30da 100644
--- a/wm.h
+++ b/wm.h
@@ -65,8 +65,8 @@ extern void run(char *arg);
65extern void quit(char *arg); 65extern void quit(char *arg);
66 66
67/* client.c */ 67/* client.c */
68extern Client *create_client(Window w, XWindowAttributes *wa); 68extern void manage(Window w, XWindowAttributes *wa);
69extern void manage(Client *c); 69void unmanage(Client *c);
70extern Client * getclient(Window w); 70extern Client * getclient(Window w);
71 71
72/* key.c */ 72/* key.c */
@@ -74,3 +74,4 @@ extern void update_keys();
74extern void keypress(XEvent *e); 74extern void keypress(XEvent *e);
75 75
76/* wm.c */ 76/* wm.c */
77extern int error_handler(Display *dpy, XErrorEvent *error);