diff options
Diffstat (limited to '')
| -rw-r--r-- | client.c | 45 | ||||
| -rw-r--r-- | event.c | 14 | ||||
| -rw-r--r-- | wm.c | 9 | ||||
| -rw-r--r-- | wm.h | 5 |
4 files changed, 44 insertions, 29 deletions
| @@ -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 | ||
| 39 | Client * | 40 | void |
| 40 | create_client(Window w, XWindowAttributes *wa) | 41 | manage(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 | 81 | static int |
| 74 | for(t=&client, i=0; *t; t=&(*t)->next, i++); | 82 | dummy_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 | ||
| 81 | void | 87 | void |
| 82 | manage(Client *c) | 88 | unmanage(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 | |||
| 89 | Client * | 110 | Client * |
| 90 | getclient(Window w) | 111 | getclient(Window w) |
| 91 | { | 112 | { |
| @@ -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 | ||
| 170 | static void | 166 | static void |
| @@ -185,11 +181,9 @@ propertynotify(XEvent *e) | |||
| 185 | static void | 181 | static void |
| 186 | unmapnotify(XEvent *e) | 182 | unmapnotify(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 | } |
| @@ -20,19 +20,18 @@ Atom net_atom[NetLast]; | |||
| 20 | Cursor cursor[CurLast]; | 20 | Cursor cursor[CurLast]; |
| 21 | XRectangle rect, barrect; | 21 | XRectangle rect, barrect; |
| 22 | Bool running = True; | 22 | Bool running = True; |
| 23 | Client *clients = NULL; | ||
| 24 | 23 | ||
| 25 | char *bartext, tag[256]; | 24 | char *bartext, tag[256]; |
| 26 | int screen, sel_screen; | 25 | int screen, sel_screen; |
| 27 | 26 | ||
| 28 | /* draw structs */ | ||
| 29 | Brush brush = {0}; | 27 | Brush brush = {0}; |
| 28 | Client *clients = NULL; | ||
| 30 | 29 | ||
| 31 | enum { WM_PROTOCOL_DELWIN = 1 }; | 30 | enum { WM_PROTOCOL_DELWIN = 1 }; |
| 32 | 31 | ||
| 33 | static Bool other_wm_running; | 32 | static Bool other_wm_running; |
| 34 | static int (*x_error_handler) (Display *, XErrorEvent *); | ||
| 35 | static char version[] = "gridwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; | 33 | static char version[] = "gridwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; |
| 34 | static int (*x_error_handler) (Display *, XErrorEvent *); | ||
| 36 | 35 | ||
| 37 | static void | 36 | static void |
| 38 | usage() | 37 | usage() |
| @@ -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 | */ |
| 72 | static int | 71 | int |
| 73 | error_handler(Display *dpy, XErrorEvent *error) | 72 | error_handler(Display *dpy, XErrorEvent *error) |
| 74 | { | 73 | { |
| 75 | if(error->error_code == BadWindow | 74 | if(error->error_code == BadWindow |
| @@ -65,8 +65,8 @@ extern void run(char *arg); | |||
| 65 | extern void quit(char *arg); | 65 | extern void quit(char *arg); |
| 66 | 66 | ||
| 67 | /* client.c */ | 67 | /* client.c */ |
| 68 | extern Client *create_client(Window w, XWindowAttributes *wa); | 68 | extern void manage(Window w, XWindowAttributes *wa); |
| 69 | extern void manage(Client *c); | 69 | void unmanage(Client *c); |
| 70 | extern Client * getclient(Window w); | 70 | extern Client * getclient(Window w); |
| 71 | 71 | ||
| 72 | /* key.c */ | 72 | /* key.c */ |
| @@ -74,3 +74,4 @@ extern void update_keys(); | |||
| 74 | extern void keypress(XEvent *e); | 74 | extern void keypress(XEvent *e); |
| 75 | 75 | ||
| 76 | /* wm.c */ | 76 | /* wm.c */ |
| 77 | extern int error_handler(Display *dpy, XErrorEvent *error); | ||
