dwm-meillo

annotate client.c @ 16:359b6e563b95

several changes, new stuff
author Anselm R. Garbe <garbeam@wmii.de>
date Tue, 11 Jul 2006 18:53:41 +0200
parents 5c078b66347b
children 1efa34c6e1b6
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@16 38 if(c == stack)
garbeam@16 39 draw_bar();
garbeam@16 40 else
garbeam@16 41 draw_client(c);
garbeam@5 42 }
garbeam@5 43
garbeam@10 44 void
garbeam@13 45 focus(Client *c)
garbeam@13 46 {
garbeam@13 47 Client **l;
garbeam@13 48 for(l=&stack; *l && *l != c; l=&(*l)->snext);
garbeam@13 49 eassert(*l == c);
garbeam@13 50 *l = c->snext;
garbeam@13 51 c->snext = stack;
garbeam@13 52 stack = c;
garbeam@13 53 XRaiseWindow(dpy, c->win);
garbeam@13 54 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
garbeam@13 55 XFlush(dpy);
garbeam@13 56 }
garbeam@13 57
garbeam@13 58 void
garbeam@10 59 manage(Window w, XWindowAttributes *wa)
garbeam@5 60 {
garbeam@10 61 Client *c, **l;
garbeam@5 62 XSetWindowAttributes twa;
garbeam@5 63 long msize;
garbeam@5 64
garbeam@5 65 c = emallocz(sizeof(Client));
garbeam@5 66 c->win = w;
garbeam@5 67 c->r[RFloat].x = wa->x;
garbeam@5 68 c->r[RFloat].y = wa->y;
garbeam@5 69 c->r[RFloat].width = wa->width;
garbeam@5 70 c->r[RFloat].height = wa->height;
garbeam@5 71 c->border = wa->border_width;
garbeam@5 72 XSetWindowBorderWidth(dpy, c->win, 0);
garbeam@16 73 XSelectInput(dpy, c->win, StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
garbeam@5 74 XGetTransientForHint(dpy, c->win, &c->trans);
garbeam@5 75 if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags)
garbeam@5 76 c->size.flags = PSize;
garbeam@5 77 c->fixedsize =
garbeam@5 78 (c->size.flags & PMinSize && c->size.flags & PMaxSize
garbeam@5 79 && c->size.min_width == c->size.max_width
garbeam@5 80 && c->size.min_height == c->size.max_height);
garbeam@13 81 update_name(c);
garbeam@5 82 twa.override_redirect = 1;
garbeam@5 83 twa.background_pixmap = ParentRelative;
garbeam@5 84 twa.event_mask = ExposureMask;
garbeam@5 85
garbeam@5 86 c->title = XCreateWindow(dpy, root, c->r[RFloat].x, c->r[RFloat].y,
garbeam@5 87 c->r[RFloat].width, barrect.height, 0,
garbeam@5 88 DefaultDepth(dpy, screen), CopyFromParent,
garbeam@5 89 DefaultVisual(dpy, screen),
garbeam@5 90 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
garbeam@5 91
garbeam@10 92 for(l=&clients; *l; l=&(*l)->next);
garbeam@10 93 c->next = *l; /* *l == nil */
garbeam@10 94 *l = c;
garbeam@13 95 c->snext = stack;
garbeam@13 96 stack = c;
garbeam@13 97 XMapWindow(dpy, c->win);
garbeam@13 98 focus(c);
garbeam@5 99 }
garbeam@9 100
garbeam@10 101 static int
garbeam@10 102 dummy_error_handler(Display *dpy, XErrorEvent *error)
garbeam@10 103 {
garbeam@10 104 return 0;
garbeam@10 105 }
garbeam@10 106
garbeam@10 107 void
garbeam@10 108 unmanage(Client *c)
garbeam@10 109 {
garbeam@10 110 Client **l;
garbeam@10 111
garbeam@10 112 XGrabServer(dpy);
garbeam@10 113 XSetErrorHandler(dummy_error_handler);
garbeam@10 114
garbeam@10 115 XUnmapWindow(dpy, c->win);
garbeam@10 116 XDestroyWindow(dpy, c->title);
garbeam@10 117
garbeam@10 118 for(l=&clients; *l && *l != c; l=&(*l)->next);
garbeam@10 119 eassert(*l == c);
garbeam@10 120 *l = c->next;
garbeam@13 121 for(l=&stack; *l && *l != c; l=&(*l)->snext);
garbeam@13 122 eassert(*l == c);
garbeam@13 123 *l = c->snext;
garbeam@10 124 free(c);
garbeam@10 125
garbeam@10 126 XFlush(dpy);
garbeam@10 127 XSetErrorHandler(error_handler);
garbeam@10 128 XUngrabServer(dpy);
garbeam@13 129 flush_events(EnterWindowMask);
garbeam@14 130 if(stack)
garbeam@14 131 focus(stack);
garbeam@10 132 }
garbeam@10 133
garbeam@10 134
garbeam@9 135 Client *
garbeam@9 136 getclient(Window w)
garbeam@9 137 {
garbeam@9 138 Client *c;
garbeam@9 139 for(c = clients; c; c = c->next)
garbeam@9 140 if(c->win == w)
garbeam@9 141 return c;
garbeam@9 142 return NULL;
garbeam@9 143 }
garbeam@13 144
garbeam@14 145 void
garbeam@14 146 draw_client(Client *c)
garbeam@14 147 {
garbeam@14 148
garbeam@14 149
garbeam@14 150
garbeam@14 151 }