X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=client.c;h=1bdebd2e5b06fa2908bf86ad10637366cb8ecb46;hb=4688ad181da14be36e034918580ec0ce5968ffdb;hp=92b26a262e03cb979f468a41a28207a5e7e9c3b7;hpb=c09bf8da071e05e2c1d714f0d31d41fe944bc11b;p=dwm.git diff --git a/client.c b/client.c index 92b26a2..1bdebd2 100644 --- a/client.c +++ b/client.c @@ -25,7 +25,11 @@ resizetitle(Client *c) c->tw = c->w + 2; c->tx = c->x + c->w - c->tw + 2; c->ty = c->y; - XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th); + if(c->tags[tsel]) + XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th); + else + XMoveResizeWindow(dpy, c->title, c->tx + 2 * sw, c->ty, c->tw, c->th); + } static int @@ -49,13 +53,12 @@ focus(Client *c) Client *old = sel; XEvent ev; - XFlush(dpy); sel = c; if(old && old != c) drawtitle(old); drawtitle(c); XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); - XFlush(dpy); + XSync(dpy, False); while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); } @@ -67,8 +70,11 @@ focusnext(Arg *arg) if(!sel) return; - if(!(c = getnext(sel->next))) - c = getnext(clients); + if(sel->ismax) + togglemax(NULL); + + if(!(c = getnext(sel->next, tsel))) + c = getnext(clients, tsel); if(c) { higher(c); c->revert = sel; @@ -84,6 +90,9 @@ focusprev(Arg *arg) if(!sel) return; + if(sel->ismax) + togglemax(NULL); + if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) { higher(c); focus(c); @@ -94,6 +103,7 @@ Client * getclient(Window w) { Client *c; + for(c = clients; c; c = c->next) if(c->win == w) return c; @@ -104,6 +114,7 @@ Client * getctitle(Window w) { Client *c; + for(c = clients; c; c = c->next) if(c->title == w) return c; @@ -130,7 +141,7 @@ gravitate(Client *c, Bool invert) case SouthEastGravity: case SouthGravity: case SouthWestGravity: - dy = -c->h; + dy = -(c->h); break; default: break; @@ -193,19 +204,22 @@ lower(Client *c) void manage(Window w, XWindowAttributes *wa) { - Client *c, **l; - XSetWindowAttributes twa; + int diff; + Client *c; Window trans; + XSetWindowAttributes twa; c = emallocz(sizeof(Client)); c->win = w; - c->tx = c->x = wa->x; - c->ty = c->y = wa->y; - if(c->y < bh) - c->ty = c->y += bh; - c->tw = c->w = wa->width; + c->x = c->tx = wa->x; + c->y = c->ty = wa->y; + c->w = c->tw = wa->width; c->h = wa->height; c->th = bh; + + if(c->y < bh) + c->y = c->ty = bh; + c->border = 1; c->proto = getproto(c->win); setsize(c); @@ -221,25 +235,26 @@ manage(Window w, XWindowAttributes *wa) DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa); - settitle(c); settags(c); - for(l = &clients; *l; l = &(*l)->next); - c->next = *l; /* *l == nil */ - *l = c; + c->next = clients; + clients = c; - XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask, + XGrabButton(dpy, Button1, MODKEY, c->win, False, ButtonPressMask, GrabModeAsync, GrabModeSync, None, None); - XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask, + XGrabButton(dpy, Button2, MODKEY, c->win, False, ButtonPressMask, GrabModeAsync, GrabModeSync, None, None); - XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask, + XGrabButton(dpy, Button3, MODKEY, c->win, False, ButtonPressMask, GrabModeAsync, GrabModeSync, None, None); - if(!c->dofloat) - c->dofloat = trans - || ((c->maxw == c->minw) && (c->maxh == c->minh)); + if(!c->isfloat) + c->isfloat = trans || (c->maxw && c->minw && + (c->maxw == c->minw) && (c->maxh == c->minh)); + + settitle(c); arrange(NULL); + /* mapping the window now prevents flicker */ if(c->tags[tsel]) { XMapRaised(dpy, c->win); @@ -247,28 +262,29 @@ manage(Window w, XWindowAttributes *wa) focus(c); } else { - ban(c); XMapRaised(dpy, c->win); XMapRaised(dpy, c->title); } } void -maximize(Arg *arg) +pop(Client *c) { - if(!sel) - return; - sel->x = sx; - sel->y = sy + bh; - sel->w = sw - 2 * sel->border; - sel->h = sh - 2 * sel->border - bh; - higher(sel); - resize(sel, False); + Client **l; + + for(l = &clients; *l && *l != c; l = &(*l)->next); + *l = c->next; + + c->next = clients; /* pop */ + clients = c; + arrange(NULL); } void -resize(Client *c, Bool inc) +resize(Client *c, Bool inc, Corner sticky) { + int bottom = c->y + c->h; + int right = c->x + c->w; XConfigureEvent e; if(inc) { @@ -280,7 +296,7 @@ resize(Client *c, Bool inc) if(c->x > sw) /* might happen on restart */ c->x = sw - c->w; if(c->y > sh) - c->ty = c->y = sh - c->h; + c->y = sh - c->h; if(c->minw && c->w < c->minw) c->w = c->minw; if(c->minh && c->h < c->minh) @@ -289,9 +305,15 @@ resize(Client *c, Bool inc) c->w = c->maxw; if(c->maxh && c->h > c->maxh) c->h = c->maxh; + if(sticky == TopRight || sticky == BotRight) + c->x = right - c->w; + if(sticky == BotLeft || sticky == BotRight) + c->y = bottom - c->h; + resizetitle(c); XSetWindowBorderWidth(dpy, c->win, 1); XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); + e.type = ConfigureNotify; e.event = c->win; e.window = c->win; @@ -303,14 +325,15 @@ resize(Client *c, Bool inc) e.above = None; e.override_redirect = False; XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e); - XFlush(dpy); + XSync(dpy, False); } void setsize(Client *c) { - XSizeHints size; long msize; + XSizeHints size; + if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags) size.flags = PSize; c->flags = size.flags; @@ -347,9 +370,9 @@ setsize(Client *c) void settitle(Client *c) { - XTextProperty name; - int n; char **list = NULL; + int n; + XTextProperty name; name.nitems = 0; c->name[0] = 0; @@ -373,6 +396,38 @@ settitle(Client *c) } void +togglemax(Arg *arg) +{ + int ox, oy, ow, oh; + XEvent ev; + + if(!sel) + return; + + if((sel->ismax = !sel->ismax)) { + ox = sel->x; + oy = sel->y; + ow = sel->w; + oh = sel->h; + sel->x = sx; + sel->y = sy + bh; + sel->w = sw - 2 * sel->border; + sel->h = sh - 2 * sel->border - bh; + + higher(sel); + resize(sel, False, TopLeft); + + sel->x = ox; + sel->y = oy; + sel->w = ow; + sel->h = oh; + } + else + resize(sel, False, TopLeft); + while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); +} + +void unmanage(Client *c) { Client **l; @@ -393,7 +448,7 @@ unmanage(Client *c) free(c); - XFlush(dpy); + XSync(dpy, False); XSetErrorHandler(xerror); XUngrabServer(dpy); arrange(NULL); @@ -404,21 +459,16 @@ unmanage(Client *c) void zoom(Arg *arg) { - Client **l, *c; + Client *c; if(!sel) return; - if(sel == getnext(clients) && sel->next) { - if((c = getnext(sel->next))) + if(sel == getnext(clients, tsel) && sel->next) { + if((c = getnext(sel->next, tsel))) sel = c; } - for(l = &clients; *l && *l != sel; l = &(*l)->next); - *l = sel->next; - - sel->next = clients; /* pop */ - clients = sel; - arrange(NULL); + pop(sel); focus(sel); }