X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=blobdiff_plain;f=dwm.c;h=f873a42ffbc45722f1fdf6dada558781c9f2946c;hp=74a28a3c8688b8a09ad1ba2675e78cefc294249a;hb=c0ee24356493538c83045703ce610d7a8c6603ac;hpb=d2f927543686b2145e394c87c1c512066578f3f9 diff --git a/dwm.c b/dwm.c index 74a28a3..f873a42 100644 --- a/dwm.c +++ b/dwm.c @@ -273,11 +273,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,14 +410,24 @@ 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 attachstack(Client *c) { - c->snext = c->mon->stack; - c->mon->stack = c; + if (c->mon->sel) { + c->snext = c->mon->sel->snext; + c->mon->sel->snext = c; + } else { + c->snext = c->mon->stack; + c->mon->stack = c; + } } void @@ -678,14 +688,23 @@ detach(Client *c) { 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(ISVISIBLE(i)) + next_sel = i; + } if(c == c->mon->sel) { - for(t = c->mon->stack; t && !ISVISIBLE(t); t = t->snext); - c->mon->sel = t; + if (!next_sel) { // if no visible window prev, find first visible + for(i = c->mon->stack; i && !ISVISIBLE(i); i = i->snext) + next_sel = i; + } + c->mon->sel = next_sel; + } + if (prev) { + prev->snext = c->snext; + } else { + c->mon->stack = c->snext; } } @@ -798,10 +817,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 +834,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 +1104,7 @@ manage(Window w, XWindowAttributes *wa) { c->mon->sel = c; arrange(c->mon); XMapWindow(dpy, c->win); - focus(NULL); + focus(c); } void @@ -1712,6 +1727,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) { @@ -1740,7 +1757,7 @@ unmanage(Client *c, Bool destroyed) { XUngrabServer(dpy); } free(c); - focus(NULL); + focus(selmon ? selmon->sel : NULL); updateclientlist(); arrange(m); }