X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=blobdiff_plain;f=dwm.c;h=5c25c2426c6d18ec3ddffbd135d903afafa17e8b;hp=7ca1ace17bda76c0260ec0b85e3d29ff9125174d;hb=99144036af9457eb08c709d3fba7f6ffb42039dc;hpb=5364697914fd4272fc1a6494b4fc522d2935427a diff --git a/dwm.c b/dwm.c index 7ca1ace..5c25c24 100644 --- a/dwm.c +++ b/dwm.c @@ -57,14 +57,14 @@ #define TEXTW(X) (drw_font_getexts_width(drw->font, X, strlen(X)) + drw->font->h) /* enums */ -enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ -enum { ColBorder, ColFG, ColBG, ColLast }; /* color */ +enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ +enum { SchemeNorm, SchemeSel, SchemeLast }; /* color schemes */ enum { NetSupported, NetWMName, NetWMState, - NetWMFullscreen, NetActiveWindow, NetWMWindowType, - NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */ + NetWMFullscreen, NetWMWindowOpacity, NetActiveWindow, NetWMWindowType, + NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */ enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */ enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, - ClkClientWin, ClkRootWin, ClkLast }; /* clicks */ + ClkClientWin, ClkRootWin, ClkLast }; /* clicks */ typedef union { int i; @@ -260,14 +260,27 @@ static void (*handler[LASTEvent]) (XEvent *) = { static Atom wmatom[WMLast], netatom[NetLast]; static Bool running = True; static Cur *cursor[CurLast]; -static Theme thmnorm[ColLast]; -static Theme thmsel[ColLast]; +static ClrScheme scheme[SchemeLast]; static Display *dpy; static Drw *drw; 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" @@ -476,12 +489,12 @@ cleanup(void) { drw_cur_free(drw, cursor[CurResize]); drw_cur_free(drw, cursor[CurMove]); drw_font_free(dpy, fnt); - drw_clr_free(thmnorm->border); - drw_clr_free(thmnorm->bg); - drw_clr_free(thmnorm->fg); - drw_clr_free(thmsel->border); - drw_clr_free(thmsel->bg); - drw_clr_free(thmsel->fg); + drw_clr_free(scheme[SchemeNorm].border); + drw_clr_free(scheme[SchemeNorm].bg); + drw_clr_free(scheme[SchemeNorm].fg); + drw_clr_free(scheme[SchemeSel].border); + drw_clr_free(scheme[SchemeSel].bg); + drw_clr_free(scheme[SchemeSel].fg); drw_free(drw); XSync(dpy, False); XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); @@ -705,14 +718,14 @@ drawbar(Monitor *m) { x = 0; for(i = 0; i < LENGTH(tags); i++) { w = TEXTW(tags[i]); - drw_settheme(drw, m->tagset[m->seltags] & 1 << i ? thmsel : thmnorm); + drw_setscheme(drw, m->tagset[m->seltags] & 1 << i ? &scheme[SchemeSel] : &scheme[SchemeNorm]); drw_text(drw, x, 0, w, bh, tags[i], urg & 1 << i); drw_rect(drw, x, 0, w, bh, m == selmon && selmon->sel && selmon->sel->tags & 1 << i, occ & 1 << i, urg & 1 << i); x += w; } w = blw = TEXTW(m->ltsymbol); - drw_settheme(drw, thmnorm); + drw_setscheme(drw, &scheme[SchemeNorm]); drw_text(drw, x, 0, w, bh, m->ltsymbol, 0); x += w; xx = x; @@ -730,12 +743,12 @@ drawbar(Monitor *m) { if((w = x - xx) > bh) { x = xx; if(m->sel) { - drw_settheme(drw, m == selmon ? thmsel : thmnorm); + drw_setscheme(drw, m == selmon ? &scheme[SchemeSel] : &scheme[SchemeNorm]); drw_text(drw, x, 0, w, bh, m->sel->name, 0); drw_rect(drw, x, 0, w, bh, m->sel->isfixed, m->sel->isfloating, 0); } else { - drw_settheme(drw, thmnorm); + drw_setscheme(drw, &scheme[SchemeNorm]); drw_text(drw, x, 0, w, bh, NULL, 0); } } @@ -793,7 +806,7 @@ focus(Client *c) { detachstack(c); attachstack(c); grabbuttons(c, True); - XSetWindowBorder(dpy, c->win, thmsel->border->rgb); + XSetWindowBorder(dpy, c->win, scheme[SchemeSel].border->rgb); setfocus(c); } else { @@ -802,6 +815,8 @@ focus(Client *c) { } selmon->sel = c; drawbars(); + if(c && (!root || (c->win!=root)) ) + window_set_opaque(c); } void @@ -832,7 +847,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); @@ -1041,7 +1063,7 @@ manage(Window w, XWindowAttributes *wa) { wc.border_width = c->bw; XConfigureWindow(dpy, w, CWBorderWidth, &wc); - XSetWindowBorder(dpy, w, thmnorm->border->rgb); + XSetWindowBorder(dpy, w, scheme[SchemeNorm].border->rgb); configure(c); /* propagates border_width, if size doesn't change */ updatewindowtype(c); updatesizehints(c); @@ -1124,6 +1146,7 @@ movemouse(const Arg *arg) { Client *c; Monitor *m; XEvent ev; + Time lasttime = 0; if(!(c = selmon->sel)) return; @@ -1146,6 +1169,10 @@ movemouse(const Arg *arg) { handler[ev.type](&ev); break; case MotionNotify: + if ((ev.xmotion.time - lasttime) <= (1000 / 60)) + continue; + lasttime = ev.xmotion.time; + nx = ocx + (ev.xmotion.x - x); ny = ocy + (ev.xmotion.y - y); if(nx >= selmon->wx && nx <= selmon->wx + selmon->ww @@ -1265,11 +1292,11 @@ resizeclient(Client *c, int x, int y, int w, int h) { void resizemouse(const Arg *arg) { - int ocx, ocy; - int nw, nh; + int ocx, ocy, nw, nh; Client *c; Monitor *m; XEvent ev; + Time lasttime = 0; if(!(c = selmon->sel)) return; @@ -1291,6 +1318,10 @@ resizemouse(const Arg *arg) { handler[ev.type](&ev); break; case MotionNotify: + if ((ev.xmotion.time - lasttime) <= (1000 / 60)) + continue; + lasttime = ev.xmotion.time; + nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1); nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1); if(c->mon->wx + nw >= selmon->wx && c->mon->wx + nw <= selmon->wx + selmon->ww @@ -1515,6 +1546,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); @@ -1523,12 +1555,12 @@ setup(void) { cursor[CurResize] = drw_cur_create(drw, XC_sizing); cursor[CurMove] = drw_cur_create(drw, XC_fleur); /* init appearance */ - thmnorm->border = drw_clr_create(drw, normbordercolor); - thmnorm->bg = drw_clr_create(drw, normbgcolor); - thmnorm->fg = drw_clr_create(drw, normfgcolor); - thmsel->border = drw_clr_create(drw, selbordercolor); - thmsel->bg = drw_clr_create(drw, selbgcolor); - thmsel->fg = drw_clr_create(drw, selfgcolor); + scheme[SchemeNorm].border = drw_clr_create(drw, normbordercolor); + scheme[SchemeNorm].bg = drw_clr_create(drw, normbgcolor); + scheme[SchemeNorm].fg = drw_clr_create(drw, normfgcolor); + scheme[SchemeSel].border = drw_clr_create(drw, selbordercolor); + scheme[SchemeSel].bg = drw_clr_create(drw, selbgcolor); + scheme[SchemeSel].fg = drw_clr_create(drw, selfgcolor); /* init bars */ updatebars(); updatestatus(); @@ -1543,6 +1575,7 @@ setup(void) { XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa); XSelectInput(dpy, root, wa.event_mask); grabkeys(); + focus(NULL); } void @@ -1570,6 +1603,8 @@ sigchld(int unused) { void spawn(const Arg *arg) { + if(arg->v == dmenucmd) + dmenumon[0] = '0' + selmon->num; if(fork() == 0) { if(dpy) close(ConnectionNumber(dpy)); @@ -1673,8 +1708,10 @@ 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, thmnorm->border->rgb); + XSetWindowBorder(dpy, c->win, scheme[SchemeNorm].border->rgb); if(setfocus) { XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); XDeleteProperty(dpy, root, netatom[NetActiveWindow]); @@ -2044,7 +2081,7 @@ zoom(const Arg *arg) { int main(int argc, char *argv[]) { if(argc == 2 && !strcmp("-v", argv[1])) - die("dwm-"VERSION", © 2006-2012 dwm engineers, see LICENSE for details\n"); + die("dwm-"VERSION", © 2006-2014 dwm engineers, see LICENSE for details\n"); else if(argc != 1) die("usage: dwm [-v]\n"); if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())