dwm-meillo

annotate client.c @ 12:a2b399582afe

new stuff
author Anselm R. Garbe <garbeam@wmii.de>
date Tue, 11 Jul 2006 14:53:22 +0200
parents d567f430a81d
children 5cc5e55a132d
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@5 13 static void
garbeam@5 14 update_client_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@10 41 manage(Window w, XWindowAttributes *wa)
garbeam@5 42 {
garbeam@10 43 Client *c, **l;
garbeam@5 44 XSetWindowAttributes twa;
garbeam@5 45 long msize;
garbeam@5 46
garbeam@5 47 c = emallocz(sizeof(Client));
garbeam@5 48 c->win = w;
garbeam@5 49 c->r[RFloat].x = wa->x;
garbeam@5 50 c->r[RFloat].y = wa->y;
garbeam@5 51 c->r[RFloat].width = wa->width;
garbeam@5 52 c->r[RFloat].height = wa->height;
garbeam@5 53 c->border = wa->border_width;
garbeam@5 54 XSetWindowBorderWidth(dpy, c->win, 0);
garbeam@5 55 XGetTransientForHint(dpy, c->win, &c->trans);
garbeam@5 56 if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags)
garbeam@5 57 c->size.flags = PSize;
garbeam@5 58 c->fixedsize =
garbeam@5 59 (c->size.flags & PMinSize && c->size.flags & PMaxSize
garbeam@5 60 && c->size.min_width == c->size.max_width
garbeam@5 61 && c->size.min_height == c->size.max_height);
garbeam@5 62 update_client_name(c);
garbeam@5 63 twa.override_redirect = 1;
garbeam@5 64 twa.background_pixmap = ParentRelative;
garbeam@5 65 twa.event_mask = ExposureMask;
garbeam@5 66
garbeam@5 67 c->title = XCreateWindow(dpy, root, c->r[RFloat].x, c->r[RFloat].y,
garbeam@5 68 c->r[RFloat].width, barrect.height, 0,
garbeam@5 69 DefaultDepth(dpy, screen), CopyFromParent,
garbeam@5 70 DefaultVisual(dpy, screen),
garbeam@5 71 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
garbeam@5 72
garbeam@10 73 for(l=&clients; *l; l=&(*l)->next);
garbeam@10 74 c->next = *l; /* *l == nil */
garbeam@10 75 *l = c;
garbeam@5 76 XMapRaised(dpy, c->win);
garbeam@5 77 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
garbeam@5 78 XFlush(dpy);
garbeam@5 79 }
garbeam@9 80
garbeam@10 81 static int
garbeam@10 82 dummy_error_handler(Display *dpy, XErrorEvent *error)
garbeam@10 83 {
garbeam@10 84 return 0;
garbeam@10 85 }
garbeam@10 86
garbeam@10 87 void
garbeam@10 88 unmanage(Client *c)
garbeam@10 89 {
garbeam@10 90 Client **l;
garbeam@10 91
garbeam@10 92 XGrabServer(dpy);
garbeam@10 93 XSetErrorHandler(dummy_error_handler);
garbeam@10 94
garbeam@10 95 XUnmapWindow(dpy, c->win);
garbeam@10 96 XDestroyWindow(dpy, c->title);
garbeam@10 97
garbeam@10 98 for(l=&clients; *l && *l != c; l=&(*l)->next);
garbeam@10 99 eassert(*l == c);
garbeam@10 100 *l = c->next;
garbeam@10 101 free(c);
garbeam@10 102
garbeam@10 103 XFlush(dpy);
garbeam@10 104 XSetErrorHandler(error_handler);
garbeam@10 105 XUngrabServer(dpy);
garbeam@10 106 /*flush_masked_events(EnterWindowMask); ? */
garbeam@10 107 }
garbeam@10 108
garbeam@10 109
garbeam@9 110 Client *
garbeam@9 111 getclient(Window w)
garbeam@9 112 {
garbeam@9 113 Client *c;
garbeam@9 114 for(c = clients; c; c = c->next)
garbeam@9 115 if(c->win == w)
garbeam@9 116 return c;
garbeam@9 117 return NULL;
garbeam@9 118 }