dwm-meillo

annotate client.c @ 13:5cc5e55a132d

added protocol killing stuff
author Anselm R. Garbe <garbeam@wmii.de>
date Tue, 11 Jul 2006 16:14:22 +0200
parents 703255003abb
children 5c078b66347b
rev   line source
garbeam@5 1 /*
garbeam@5 2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
garbeam@5 3 * See LICENSE file for license details.
garbeam@5 4 */
garbeam@5 5
garbeam@10 6 #include <stdlib.h>
garbeam@5 7 #include <string.h>
garbeam@5 8 #include <X11/Xatom.h>
garbeam@5 9
garbeam@5 10 #include "util.h"
garbeam@5 11 #include "wm.h"
garbeam@5 12
garbeam@13 13 void
garbeam@13 14 update_name(Client *c)
garbeam@5 15 {
garbeam@5 16 XTextProperty name;
garbeam@5 17 int n;
garbeam@7 18 char **list = NULL;
garbeam@5 19
garbeam@5 20 name.nitems = 0;
garbeam@5 21 c->name[0] = 0;
garbeam@5 22 XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
garbeam@5 23 if(!name.nitems)
garbeam@5 24 XGetWMName(dpy, c->win, &name);
garbeam@5 25 if(!name.nitems)
garbeam@5 26 return;
garbeam@5 27 if(name.encoding == XA_STRING)
garbeam@5 28 strncpy(c->name, (char *)name.value, sizeof(c->name));
garbeam@5 29 else {
garbeam@5 30 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
garbeam@5 31 && n > 0 && *list)
garbeam@5 32 {
garbeam@5 33 strncpy(c->name, *list, sizeof(c->name));
garbeam@5 34 XFreeStringList(list);
garbeam@5 35 }
garbeam@5 36 }
garbeam@5 37 XFree(name.value);
garbeam@5 38 }
garbeam@5 39
garbeam@10 40 void
garbeam@13 41 focus(Client *c)
garbeam@13 42 {
garbeam@13 43 Client **l;
garbeam@13 44 for(l=&stack; *l && *l != c; l=&(*l)->snext);
garbeam@13 45 eassert(*l == c);
garbeam@13 46 *l = c->snext;
garbeam@13 47 c->snext = stack;
garbeam@13 48 stack = c;
garbeam@13 49 XRaiseWindow(dpy, c->win);
garbeam@13 50 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
garbeam@13 51 XFlush(dpy);
garbeam@13 52 }
garbeam@13 53
garbeam@13 54 void
garbeam@10 55 manage(Window w, XWindowAttributes *wa)
garbeam@5 56 {
garbeam@10 57 Client *c, **l;
garbeam@5 58 XSetWindowAttributes twa;
garbeam@5 59 long msize;
garbeam@5 60
garbeam@5 61 c = emallocz(sizeof(Client));
garbeam@5 62 c->win = w;
garbeam@5 63 c->r[RFloat].x = wa->x;
garbeam@5 64 c->r[RFloat].y = wa->y;
garbeam@5 65 c->r[RFloat].width = wa->width;
garbeam@5 66 c->r[RFloat].height = wa->height;
garbeam@5 67 c->border = wa->border_width;
garbeam@5 68 XSetWindowBorderWidth(dpy, c->win, 0);
garbeam@5 69 XGetTransientForHint(dpy, c->win, &c->trans);
garbeam@5 70 if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags)
garbeam@5 71 c->size.flags = PSize;
garbeam@5 72 c->fixedsize =
garbeam@5 73 (c->size.flags & PMinSize && c->size.flags & PMaxSize
garbeam@5 74 && c->size.min_width == c->size.max_width
garbeam@5 75 && c->size.min_height == c->size.max_height);
garbeam@13 76 update_name(c);
garbeam@5 77 twa.override_redirect = 1;
garbeam@5 78 twa.background_pixmap = ParentRelative;
garbeam@5 79 twa.event_mask = ExposureMask;
garbeam@5 80
garbeam@5 81 c->title = XCreateWindow(dpy, root, c->r[RFloat].x, c->r[RFloat].y,
garbeam@5 82 c->r[RFloat].width, barrect.height, 0,
garbeam@5 83 DefaultDepth(dpy, screen), CopyFromParent,
garbeam@5 84 DefaultVisual(dpy, screen),
garbeam@5 85 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
garbeam@5 86
garbeam@10 87 for(l=&clients; *l; l=&(*l)->next);
garbeam@10 88 c->next = *l; /* *l == nil */
garbeam@10 89 *l = c;
garbeam@13 90 c->snext = stack;
garbeam@13 91 stack = c;
garbeam@13 92 XMapWindow(dpy, c->win);
garbeam@13 93 focus(c);
garbeam@5 94 }
garbeam@9 95
garbeam@10 96 static int
garbeam@10 97 dummy_error_handler(Display *dpy, XErrorEvent *error)
garbeam@10 98 {
garbeam@10 99 return 0;
garbeam@10 100 }
garbeam@10 101
garbeam@10 102 void
garbeam@10 103 unmanage(Client *c)
garbeam@10 104 {
garbeam@10 105 Client **l;
garbeam@10 106
garbeam@10 107 XGrabServer(dpy);
garbeam@10 108 XSetErrorHandler(dummy_error_handler);
garbeam@10 109
garbeam@10 110 XUnmapWindow(dpy, c->win);
garbeam@10 111 XDestroyWindow(dpy, c->title);
garbeam@10 112
garbeam@10 113 for(l=&clients; *l && *l != c; l=&(*l)->next);
garbeam@10 114 eassert(*l == c);
garbeam@10 115 *l = c->next;
garbeam@13 116 for(l=&stack; *l && *l != c; l=&(*l)->snext);
garbeam@13 117 eassert(*l == c);
garbeam@13 118 *l = c->snext;
garbeam@10 119 free(c);
garbeam@10 120
garbeam@10 121 XFlush(dpy);
garbeam@10 122 XSetErrorHandler(error_handler);
garbeam@10 123 XUngrabServer(dpy);
garbeam@13 124 flush_events(EnterWindowMask);
garbeam@10 125 }
garbeam@10 126
garbeam@10 127
garbeam@9 128 Client *
garbeam@9 129 getclient(Window w)
garbeam@9 130 {
garbeam@9 131 Client *c;
garbeam@9 132 for(c = clients; c; c = c->next)
garbeam@9 133 if(c->win == w)
garbeam@9 134 return c;
garbeam@9 135 return NULL;
garbeam@9 136 }
garbeam@13 137