aewl

annotate client.c @ 18:1efa34c6e1b6

added mouse-based resizals
author Anselm R. Garbe <garbeam@wmii.de>
date Tue, 11 Jul 2006 21:24:10 +0200
parents 359b6e563b95
children b5510d0c6d43
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@18 13 #define CLIENT_MASK (StructureNotifyMask | PropertyChangeMask | EnterWindowMask)
garbeam@18 14
garbeam@13 15 void
garbeam@13 16 update_name(Client *c)
garbeam@5 17 {
garbeam@5 18 XTextProperty name;
garbeam@5 19 int n;
garbeam@7 20 char **list = NULL;
garbeam@5 21
garbeam@5 22 name.nitems = 0;
garbeam@5 23 c->name[0] = 0;
garbeam@5 24 XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
garbeam@5 25 if(!name.nitems)
garbeam@5 26 XGetWMName(dpy, c->win, &name);
garbeam@5 27 if(!name.nitems)
garbeam@5 28 return;
garbeam@5 29 if(name.encoding == XA_STRING)
garbeam@5 30 strncpy(c->name, (char *)name.value, sizeof(c->name));
garbeam@5 31 else {
garbeam@5 32 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
garbeam@5 33 && n > 0 && *list)
garbeam@5 34 {
garbeam@5 35 strncpy(c->name, *list, sizeof(c->name));
garbeam@5 36 XFreeStringList(list);
garbeam@5 37 }
garbeam@5 38 }
garbeam@5 39 XFree(name.value);
garbeam@16 40 if(c == stack)
garbeam@16 41 draw_bar();
garbeam@16 42 else
garbeam@16 43 draw_client(c);
garbeam@5 44 }
garbeam@5 45
garbeam@10 46 void
garbeam@13 47 focus(Client *c)
garbeam@13 48 {
garbeam@13 49 Client **l;
garbeam@13 50 for(l=&stack; *l && *l != c; l=&(*l)->snext);
garbeam@13 51 eassert(*l == c);
garbeam@13 52 *l = c->snext;
garbeam@13 53 c->snext = stack;
garbeam@13 54 stack = c;
garbeam@13 55 XRaiseWindow(dpy, c->win);
garbeam@13 56 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
garbeam@13 57 XFlush(dpy);
garbeam@13 58 }
garbeam@13 59
garbeam@13 60 void
garbeam@10 61 manage(Window w, XWindowAttributes *wa)
garbeam@5 62 {
garbeam@10 63 Client *c, **l;
garbeam@5 64 XSetWindowAttributes twa;
garbeam@5 65 long msize;
garbeam@5 66
garbeam@5 67 c = emallocz(sizeof(Client));
garbeam@5 68 c->win = w;
garbeam@5 69 c->r[RFloat].x = wa->x;
garbeam@5 70 c->r[RFloat].y = wa->y;
garbeam@5 71 c->r[RFloat].width = wa->width;
garbeam@5 72 c->r[RFloat].height = wa->height;
garbeam@5 73 c->border = wa->border_width;
garbeam@5 74 XSetWindowBorderWidth(dpy, c->win, 0);
garbeam@18 75 XSelectInput(dpy, c->win, CLIENT_MASK);
garbeam@5 76 XGetTransientForHint(dpy, c->win, &c->trans);
garbeam@5 77 if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags)
garbeam@5 78 c->size.flags = PSize;
garbeam@5 79 c->fixedsize =
garbeam@5 80 (c->size.flags & PMinSize && c->size.flags & PMaxSize
garbeam@5 81 && c->size.min_width == c->size.max_width
garbeam@5 82 && c->size.min_height == c->size.max_height);
garbeam@13 83 update_name(c);
garbeam@5 84 twa.override_redirect = 1;
garbeam@5 85 twa.background_pixmap = ParentRelative;
garbeam@5 86 twa.event_mask = ExposureMask;
garbeam@5 87
garbeam@5 88 c->title = XCreateWindow(dpy, root, c->r[RFloat].x, c->r[RFloat].y,
garbeam@5 89 c->r[RFloat].width, barrect.height, 0,
garbeam@5 90 DefaultDepth(dpy, screen), CopyFromParent,
garbeam@5 91 DefaultVisual(dpy, screen),
garbeam@5 92 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
garbeam@5 93
garbeam@10 94 for(l=&clients; *l; l=&(*l)->next);
garbeam@10 95 c->next = *l; /* *l == nil */
garbeam@10 96 *l = c;
garbeam@13 97 c->snext = stack;
garbeam@13 98 stack = c;
garbeam@13 99 XMapWindow(dpy, c->win);
garbeam@18 100 XGrabButton(dpy, AnyButton, Mod1Mask, c->win, False, ButtonPressMask,
garbeam@18 101 GrabModeAsync, GrabModeSync, None, None);
garbeam@13 102 focus(c);
garbeam@5 103 }
garbeam@9 104
garbeam@18 105 void
garbeam@18 106 resize(Client *c)
garbeam@18 107 {
garbeam@18 108 XConfigureEvent e;
garbeam@18 109
garbeam@18 110 XMoveResizeWindow(dpy, c->win, c->r[RFloat].x, c->r[RFloat].y,
garbeam@18 111 c->r[RFloat].width, c->r[RFloat].height);
garbeam@18 112 e.type = ConfigureNotify;
garbeam@18 113 e.event = c->win;
garbeam@18 114 e.window = c->win;
garbeam@18 115 e.x = c->r[RFloat].x;
garbeam@18 116 e.y = c->r[RFloat].y;
garbeam@18 117 e.width = c->r[RFloat].width;
garbeam@18 118 e.height = c->r[RFloat].height;
garbeam@18 119 e.border_width = c->border;
garbeam@18 120 e.above = None;
garbeam@18 121 e.override_redirect = False;
garbeam@18 122 XSelectInput(dpy, c->win, CLIENT_MASK & ~StructureNotifyMask);
garbeam@18 123 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
garbeam@18 124 XSelectInput(dpy, c->win, CLIENT_MASK);
garbeam@18 125 XFlush(dpy);
garbeam@18 126 }
garbeam@18 127
garbeam@10 128 static int
garbeam@10 129 dummy_error_handler(Display *dpy, XErrorEvent *error)
garbeam@10 130 {
garbeam@10 131 return 0;
garbeam@10 132 }
garbeam@10 133
garbeam@10 134 void
garbeam@10 135 unmanage(Client *c)
garbeam@10 136 {
garbeam@10 137 Client **l;
garbeam@10 138
garbeam@10 139 XGrabServer(dpy);
garbeam@10 140 XSetErrorHandler(dummy_error_handler);
garbeam@10 141
garbeam@18 142 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
garbeam@10 143 XUnmapWindow(dpy, c->win);
garbeam@10 144 XDestroyWindow(dpy, c->title);
garbeam@10 145
garbeam@10 146 for(l=&clients; *l && *l != c; l=&(*l)->next);
garbeam@10 147 eassert(*l == c);
garbeam@10 148 *l = c->next;
garbeam@13 149 for(l=&stack; *l && *l != c; l=&(*l)->snext);
garbeam@13 150 eassert(*l == c);
garbeam@13 151 *l = c->snext;
garbeam@10 152 free(c);
garbeam@10 153
garbeam@10 154 XFlush(dpy);
garbeam@10 155 XSetErrorHandler(error_handler);
garbeam@10 156 XUngrabServer(dpy);
garbeam@18 157 discard_events(EnterWindowMask);
garbeam@14 158 if(stack)
garbeam@14 159 focus(stack);
garbeam@10 160 }
garbeam@10 161
garbeam@10 162
garbeam@9 163 Client *
garbeam@9 164 getclient(Window w)
garbeam@9 165 {
garbeam@9 166 Client *c;
garbeam@9 167 for(c = clients; c; c = c->next)
garbeam@9 168 if(c->win == w)
garbeam@9 169 return c;
garbeam@9 170 return NULL;
garbeam@9 171 }
garbeam@13 172
garbeam@14 173 void
garbeam@14 174 draw_client(Client *c)
garbeam@14 175 {
garbeam@14 176
garbeam@14 177
garbeam@14 178
garbeam@14 179 }