X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=blobdiff_plain;f=dwm.c;h=a6e4fc04debc727c811ab3fe20427ffa15a71e6f;hp=f896170c043fcccefe0d11330ca49f379bf29650;hb=749901f7f7bee4b62424701d6088dde4caa64c51;hpb=3d1090ba896319368c4771b88d325fcee368a608 diff --git a/dwm.c b/dwm.c index f896170..a6e4fc0 100644 --- a/dwm.c +++ b/dwm.c @@ -60,7 +60,7 @@ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ enum { SchemeNorm, SchemeSel, SchemeLast }; /* color schemes */ enum { NetSupported, NetWMName, NetWMState, - NetWMFullscreen, NetActiveWindow, NetWMWindowType, + NetWMFullscreen, NetWMWindowOpacity, NetActiveWindow, NetWMWindowType, NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */ enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */ enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, @@ -145,6 +145,7 @@ static void applyrules(Client *c); static Bool applysizehints(Client *c, int *x, int *y, int *w, int *h, Bool interact); static void arrange(Monitor *m); static void arrangemon(Monitor *m); +static void attach_as_master(Client *c); static void attach(Client *c); static void attachstack(Client *c); static void buttonpress(XEvent *e); @@ -184,6 +185,7 @@ static void monocle(Monitor *m); static void motionnotify(XEvent *e); static void movemouse(const Arg *arg); static Client *nexttiled(Client *c); +static Client *nextvisible(Client *c); static void pop(Client *); static void propertynotify(XEvent *e); static void quit(const Arg *arg); @@ -267,6 +269,20 @@ static Fnt *fnt; static Monitor *mons, *selmon; static Window root; +// unfocused windows get transparent (feature) +static const unsigned long unfocused_opacity[] = { 0xbfffffff }; +static void window_set_opaque(Client *c); +static void window_set_translucent(Client *c); +void +window_set_opaque(Client *c) { + XDeleteProperty(dpy, c->win, netatom[NetWMWindowOpacity]); +} +void +window_set_translucent(Client *c) { + XChangeProperty(dpy, c->win, netatom[NetWMWindowOpacity], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)unfocused_opacity, 1); +} + + /* configuration, allows nested code to access above variables */ #include "config.h" @@ -395,10 +411,19 @@ arrangemon(Monitor *m) { } void -attach(Client *c) { +attach_as_master(Client *c) { c->next = c->mon->clients; c->mon->clients = c; } +void +attach(Client *c) { + if (c->mon->sel) { + c->next = c->mon->sel->next; + c->mon->sel->next = c; + } else { + attach_as_master(c); + } +} void attachstack(Client *c) { @@ -527,6 +552,7 @@ clientmessage(XEvent *e) { || (cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c->isfullscreen))); } else if(cme->message_type == netatom[NetActiveWindow]) { + return; if(!ISVISIBLE(c)) { c->mon->seltags ^= 1; c->mon->tagset[c->mon->seltags] = c->tags; @@ -662,16 +688,30 @@ detach(Client *c) { *tc = c->next; } +// NOTE: the stack is for z-order and most-recently-focused +// only mon->clients determines position in visible layout void detachstack(Client *c) { - Client **tc, *t; - - for(tc = &c->mon->stack; *tc && *tc != c; tc = &(*tc)->snext); - *tc = c->snext; - + Client *prev = NULL, *next_sel = NULL, *i; + for(i = c->mon->stack; i && i != c; i = i->snext) { + prev = i; + } if(c == c->mon->sel) { - for(t = c->mon->stack; t && !ISVISIBLE(t); t = t->snext); - c->mon->sel = t; + // find last visible window before c + // WARNING if you detach() before detachstack() this will select last visible window + for(i = nextvisible(c->mon->clients); i && i != c; i = nextvisible(i->next)) + next_sel = i; + // failing that, find first visible window (besides c) + if (!next_sel) + for(i = nextvisible(c->mon->clients); i && i == c; i = nextvisible(i->next)); + if (i != c) + next_sel = i; + c->mon->sel = next_sel; + } + if (prev) { + prev->snext = c->snext; + } else { + c->mon->stack = c->snext; } } @@ -801,6 +841,8 @@ focus(Client *c) { } selmon->sel = c; drawbars(); + if(c && (!root || (c->win!=root)) ) + window_set_opaque(c); } void @@ -831,7 +873,14 @@ focusstack(const Arg *arg) { if(!selmon->sel) return; - if(arg->i > 0) { + if(arg->i == 0) { + for(i = selmon->clients; i != selmon->sel; i = i->next) { + if(ISVISIBLE(i)) { + c = i; + break; + } + } + } else if(arg->i > 0) { for(c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next); if(!c) for(c = selmon->clients; c && !ISVISIBLE(c); c = c->next); @@ -1062,7 +1111,7 @@ manage(Window w, XWindowAttributes *wa) { c->mon->sel = c; arrange(c->mon); XMapWindow(dpy, c->win); - focus(NULL); + focus(c); } void @@ -1185,10 +1234,16 @@ nexttiled(Client *c) { return c; } +Client * +nextvisible(Client *c) { + for(; c && !ISVISIBLE(c); c = c->next); + return c; +} + void pop(Client *c) { detach(c); - attach(c); + attach_as_master(c); focus(c); arrange(c->mon); } @@ -1388,8 +1443,8 @@ sendmon(Client *c, Monitor *m) { if(c->mon == m) return; unfocus(c, True); - detach(c); detachstack(c); + detach(c); c->mon = m; c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */ attach(c); @@ -1523,6 +1578,7 @@ setup(void) { netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False); netatom[NetWMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False); + netatom[NetWMWindowOpacity] = XInternAtom(dpy, "_NET_WM_WINDOW_OPACITY", False); netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False); netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False); netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False); @@ -1579,6 +1635,17 @@ sigchld(int unused) { void spawn(const Arg *arg) { + int tag = 0, i; + if(arg->v == termcmd) { + for(i = 0; i < 32; ++i) { + if(selmon->tagset[selmon->seltags] & (1 << i)) { + tag = i; + break; + } + } + _SWM_WS[8] = swm_tags[tag][0]; + _SWM_WS[9] = swm_tags[tag][1]; + } if(arg->v == dmenucmd) dmenumon[0] = '0' + selmon->num; if(fork() == 0) { @@ -1684,6 +1751,8 @@ void unfocus(Client *c, Bool setfocus) { if(!c) return; + if(!root || c->win!=root) + window_set_translucent(c); grabbuttons(c, False); XSetWindowBorder(dpy, c->win, scheme[SchemeNorm].border->rgb); if(setfocus) { @@ -1698,8 +1767,8 @@ unmanage(Client *c, Bool destroyed) { XWindowChanges wc; /* The server grab construct avoids race conditions. */ - detach(c); detachstack(c); + detach(c); if(!destroyed) { wc.border_width = c->oldbw; XGrabServer(dpy); @@ -1712,7 +1781,7 @@ unmanage(Client *c, Bool destroyed) { XUngrabServer(dpy); } free(c); - focus(NULL); + focus(selmon ? selmon->sel : NULL); updateclientlist(); arrange(m); }