X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=client.c;h=c11d5d5b970f08602ef085c2b57648bf64d1d041;hb=48b6e9a3968e54a87f022c8e68b5bec5423cb75f;hp=62f4d98e252af623aa4481e63cf7f72fbd8ae1b1;hpb=16c67f32d62849792c8e6d4fdec22a1896f9c279;p=dwm.git diff --git a/client.c b/client.c index 62f4d98..c11d5d5 100644 --- a/client.c +++ b/client.c @@ -3,14 +3,17 @@ * See LICENSE file for license details. */ +#include #include #include #include "util.h" #include "wm.h" -static void -update_client_name(Client *c) +#define CLIENT_MASK (StructureNotifyMask | PropertyChangeMask | EnterWindowMask) + +void +update_name(Client *c) { XTextProperty name; int n; @@ -34,12 +37,30 @@ update_client_name(Client *c) } } XFree(name.value); + if(c == stack) + draw_bar(); + else + draw_client(c); } -Client * -create_client(Window w, XWindowAttributes *wa) +void +focus(Client *c) { - Client *c; + Client **l; + for(l=&stack; *l && *l != c; l=&(*l)->snext); + eassert(*l == c); + *l = c->snext; + c->snext = stack; + stack = c; + XRaiseWindow(dpy, c->win); + XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); + XFlush(dpy); +} + +void +manage(Window w, XWindowAttributes *wa) +{ + Client *c, **l; XSetWindowAttributes twa; long msize; @@ -49,8 +70,8 @@ create_client(Window w, XWindowAttributes *wa) c->r[RFloat].y = wa->y; c->r[RFloat].width = wa->width; c->r[RFloat].height = wa->height; - c->border = wa->border_width; - XSetWindowBorderWidth(dpy, c->win, 0); + XSetWindowBorderWidth(dpy, c->win, 1); + XSelectInput(dpy, c->win, CLIENT_MASK); XGetTransientForHint(dpy, c->win, &c->trans); if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags) c->size.flags = PSize; @@ -58,7 +79,7 @@ create_client(Window w, XWindowAttributes *wa) (c->size.flags & PMinSize && c->size.flags & PMaxSize && c->size.min_width == c->size.max_width && c->size.min_height == c->size.max_height); - update_client_name(c); + update_name(c); twa.override_redirect = 1; twa.background_pixmap = ParentRelative; twa.event_mask = ExposureMask; @@ -68,24 +89,80 @@ create_client(Window w, XWindowAttributes *wa) DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa); + + for(l=&clients; *l; l=&(*l)->next); + c->next = *l; /* *l == nil */ + *l = c; + c->snext = stack; + stack = c; + XMapWindow(dpy, c->win); + XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask, + GrabModeAsync, GrabModeSync, None, None); + XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask, + GrabModeAsync, GrabModeSync, None, None); + XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask, + GrabModeAsync, GrabModeSync, None, None); + focus(c); +} + +void +resize(Client *c) +{ + XConfigureEvent e; + + XMoveResizeWindow(dpy, c->win, c->r[RFloat].x, c->r[RFloat].y, + c->r[RFloat].width, c->r[RFloat].height); + e.type = ConfigureNotify; + e.event = c->win; + e.window = c->win; + e.x = c->r[RFloat].x; + e.y = c->r[RFloat].y; + e.width = c->r[RFloat].width; + e.height = c->r[RFloat].height; + e.border_width = 0; + e.above = None; + e.override_redirect = False; + XSelectInput(dpy, c->win, CLIENT_MASK & ~StructureNotifyMask); + XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e); + XSelectInput(dpy, c->win, CLIENT_MASK); XFlush(dpy); +} -#if 0 - for(t=&client, i=0; *t; t=&(*t)->next, i++); - c->next = *t; /* *t == nil */ - *t = c; -#endif - return c; +static int +dummy_error_handler(Display *dpy, XErrorEvent *error) +{ + return 0; } void -manage(Client *c) +unmanage(Client *c) { - XMapRaised(dpy, c->win); - XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); + Client **l; + + XGrabServer(dpy); + XSetErrorHandler(dummy_error_handler); + + XUngrabButton(dpy, AnyButton, AnyModifier, c->win); + XUnmapWindow(dpy, c->win); + XDestroyWindow(dpy, c->title); + + for(l=&clients; *l && *l != c; l=&(*l)->next); + eassert(*l == c); + *l = c->next; + for(l=&stack; *l && *l != c; l=&(*l)->snext); + eassert(*l == c); + *l = c->snext; + free(c); + XFlush(dpy); + XSetErrorHandler(error_handler); + XUngrabServer(dpy); + discard_events(EnterWindowMask); + if(stack) + focus(stack); } + Client * getclient(Window w) { @@ -95,3 +172,11 @@ getclient(Window w) return c; return NULL; } + +void +draw_client(Client *c) +{ + + + +}