X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=blobdiff_plain;f=dwm.c;h=a04e2b60727990d9a2d35de06c157cd5610e90b6;hp=74a28a3c8688b8a09ad1ba2675e78cefc294249a;hb=63f792db45b8422aef1be9127c3b5a53ce2e926d;hpb=d2f927543686b2145e394c87c1c512066578f3f9 diff --git a/dwm.c b/dwm.c index 74a28a3..a04e2b6 100644 --- a/dwm.c +++ b/dwm.c @@ -184,6 +184,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); @@ -273,11 +274,11 @@ static void window_set_opaque(Client *c); static void window_set_translucent(Client *c); void window_set_opaque(Client *c) { - XChangeProperty(dpy, c->win, netatom[NetWMWindowOpacity], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)unfocused_opacity, 1); + XDeleteProperty(dpy, c->win, netatom[NetWMWindowOpacity]); } void window_set_translucent(Client *c) { - XDeleteProperty(dpy, c->win, netatom[NetWMWindowOpacity]); + XChangeProperty(dpy, c->win, netatom[NetWMWindowOpacity], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)unfocused_opacity, 1); } @@ -410,8 +411,13 @@ arrangemon(Monitor *m) { void attach(Client *c) { - c->next = c->mon->clients; - c->mon->clients = c; + if (c->mon->sel) { + c->next = c->mon->sel->next; + c->mon->sel->next = c; + } else { + c->next = c->mon->clients; + c->mon->clients = c; + } } void @@ -541,6 +547,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; @@ -676,16 +683,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; } } @@ -798,10 +819,6 @@ focus(Client *c) { /* was if(selmon->sel) */ if(selmon->sel && selmon->sel != c) unfocus(selmon->sel, False); - if(selmon->sel && c!=selmon->sel && c && (!root || (selmon->sel->win!=root && c->win!=root)) ) - window_set_opaque(selmon->sel); - if(c && c!=selmon->sel && (!root || (c->win!=root)) ) - window_set_translucent(c); if(c) { if(c->mon != selmon) selmon = c->mon; @@ -819,8 +836,8 @@ focus(Client *c) { } selmon->sel = c; drawbars(); - if(c) - window_set_translucent(c); + if(c && (!root || (c->win!=root)) ) + window_set_opaque(c); } void @@ -1089,7 +1106,7 @@ manage(Window w, XWindowAttributes *wa) { c->mon->sel = c; arrange(c->mon); XMapWindow(dpy, c->win); - focus(NULL); + focus(c); } void @@ -1212,6 +1229,12 @@ nexttiled(Client *c) { return c; } +Client * +nextvisible(Client *c) { + for(; c && !ISVISIBLE(c); c = c->next); + return c; +} + void pop(Client *c) { detach(c); @@ -1415,8 +1438,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); @@ -1712,6 +1735,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) { @@ -1726,8 +1751,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); @@ -1740,7 +1765,7 @@ unmanage(Client *c, Bool destroyed) { XUngrabServer(dpy); } free(c); - focus(NULL); + focus(selmon ? selmon->sel : NULL); updateclientlist(); arrange(m); }