X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=dwm.c;h=99920d034e20752699aae2e3ad034a58c0dd75f4;hb=cd7ebaad25fa5f10a4442f9d80a05f344ca271d3;hp=9e9e7483b7eea36e1fda3958d53ebf719342ee64;hpb=eeea4ef583a2ca3746e987bd2ecd570fd1869c2d;p=dwm.git diff --git a/dwm.c b/dwm.c index 9e9e748..99920d0 100644 --- a/dwm.c +++ b/dwm.c @@ -57,6 +57,21 @@ enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */ /* typedefs */ typedef struct Client Client; +struct Client { + char name[256]; + int x, y, w, h; + int rx, ry, rw, rh; /* revert geometry */ + int basew, baseh, incw, inch, maxw, maxh, minw, minh; + int minax, maxax, minay, maxay; + long flags; + unsigned int border, oldborder; + Bool isbanned, isfixed, ismax, isfloating, wasfloating; + Bool *tags; + Client *next; + Client *prev; + Client *snext; + Window win; +}; typedef struct { int x, y, w, h; @@ -96,7 +111,7 @@ typedef struct { regex_t *tagregex; } Regs; -/* forward declarations */ +/* functions */ void applyrules(Client *c); void arrange(void); void attach(Client *c); @@ -170,6 +185,7 @@ void updatebarpos(void); void updatesizehints(Client *c); void updatetitle(Client *c); void view(const char *arg); +void viewprevtag(const char *arg); /* views previous selected tags */ int xerror(Display *dpy, XErrorEvent *ee); int xerrordummy(Display *dsply, XErrorEvent *ee); int xerrorstart(Display *dsply, XErrorEvent *ee); @@ -216,27 +232,10 @@ Regs *regs = NULL; /* configuration, allows nested code to access above variables */ #include "config.h" -/* Statically define the number of tags. */ +/* statically define the number of tags. */ unsigned int ntags = sizeof tags / sizeof tags[0]; Bool seltags[sizeof tags / sizeof tags[0]] = {[0] = True}; - -struct Client { - char name[256]; - int x, y, w, h; - int rx, ry, rw, rh; /* revert geometry */ - int basew, baseh, incw, inch, maxw, maxh, minw, minh; - int minax, maxax, minay, maxay; - long flags; - unsigned int border, oldborder; - Bool isbanned, isfixed, ismax, isfloating, wasfloating; - Bool tags[sizeof tags / sizeof tags[0]]; - Client *next; - Client *prev; - Client *snext; - Window win; -}; - -/* functions*/ +Bool prevtags[sizeof tags / sizeof tags[0]] = {[0] = True}; void applyrules(Client *c) { static char buf[512]; @@ -265,8 +264,7 @@ applyrules(Client *c) { if(ch.res_name) XFree(ch.res_name); if(!matched) - for(i = 0; i < ntags; i++) - c->tags[i] = seltags[i]; + memcpy(c->tags, seltags, sizeof seltags); } void @@ -1002,13 +1000,13 @@ leavenotify(XEvent *e) { void manage(Window w, XWindowAttributes *wa) { - unsigned int i; Client *c, *t = NULL; Window trans; Status rettrans; XWindowChanges wc; c = emallocz(sizeof(Client)); + c->tags = emallocz(sizeof seltags); c->win = w; c->x = wa->x; c->y = wa->y; @@ -1043,8 +1041,7 @@ manage(Window w, XWindowAttributes *wa) { if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success)) for(t = clients; t && t->win != trans; t = t->next); if(t) - for(i = 0; i < ntags; i++) - c->tags[i] = t->tags[i]; + memcpy(c->tags, t->tags, sizeof seltags); applyrules(c); if(!c->isfloating) c->isfloating = (rettrans == Success) || c->isfixed; @@ -1163,43 +1160,45 @@ quit(const char *arg) { void resize(Client *c, int x, int y, int w, int h, Bool sizehints) { - double dx, dy, max, min, ratio; XWindowChanges wc; if(sizehints) { - if(c->minay > 0 && c->maxay > 0 && (h - c->baseh) > 0 && (w - c->basew) > 0) { - dx = (double)(w - c->basew); - dy = (double)(h - c->baseh); - min = (double)(c->minax) / (double)(c->minay); - max = (double)(c->maxax) / (double)(c->maxay); - ratio = dx / dy; - if(max > 0 && min > 0 && ratio > 0) { - if(ratio < min) { - dy = (dx * min + dy) / (min * min + 1); - dx = dy * min; - w = (int)dx + c->basew; - h = (int)dy + c->baseh; - } - else if(ratio > max) { - dy = (dx * min + dy) / (max * max + 1); - dx = dy * min; - w = (int)dx + c->basew; - h = (int)dy + c->baseh; - } - } + /* set minimum possible */ + if (w < 1) + w = 1; + if (h < 1) + h = 1; + + /* temporarily remove base dimensions */ + w -= c->basew; + h -= c->baseh; + + /* adjust for aspect limits */ + if (c->minay > 0 && c->maxay > 0 && c->minax > 0 && c->maxax > 0) { + if (w * c->maxay > h * c->maxax) + w = h * c->maxax / c->maxay; + else if (w * c->minay < h * c->minax) + h = w * c->minay / c->minax; } - if(c->minw && w < c->minw) + + /* adjust for increment value */ + if(c->incw) + w -= w % c->incw; + if(c->inch) + h -= h % c->inch; + + /* restore base dimensions */ + w += c->basew; + h += c->baseh; + + if(c->minw > 0 && w < c->minw) w = c->minw; - if(c->minh && h < c->minh) + if(c->minh > 0 && h < c->minh) h = c->minh; - if(c->maxw && w > c->maxw) + if(c->maxw > 0 && w > c->maxw) w = c->maxw; - if(c->maxh && h > c->maxh) + if(c->maxh > 0 && h > c->maxh) h = c->maxh; - if(c->incw) - w -= (w - c->basew) % c->incw; - if(c->inch) - h -= (h - c->baseh) % c->inch; } if(w <= 0 || h <= 0) return; @@ -1702,6 +1701,7 @@ unmanage(Client *c) { focus(NULL); XUngrabButton(dpy, AnyButton, AnyModifier, c->win); setclientstate(c, WithdrawnState); + free(c->tags); free(c); XSync(dpy, False); XSetErrorHandler(xerror); @@ -1838,6 +1838,7 @@ void view(const char *arg) { unsigned int i; + memcpy(prevtags, seltags, sizeof seltags); for(i = 0; i < ntags; i++) seltags[i] = arg == NULL; i = idxoftag(arg); @@ -1847,6 +1848,16 @@ view(const char *arg) { } void +viewprevtag(const char *arg) { + static Bool tmptags[sizeof tags / sizeof tags[0]]; + + memcpy(tmptags, seltags, sizeof seltags); + memcpy(seltags, prevtags, sizeof seltags); + memcpy(prevtags, tmptags, sizeof seltags); + arrange(); +} + +void zoom(const char *arg) { Client *c;