X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=blobdiff_plain;f=dwm.c;h=7b3c0abf8688a2f11ab25720415f5b0323cf9964;hp=d5eec04a21492be28ea174bda2ae62ed642ebfcd;hb=52d205e6ebfddbfea35ef92630cef55d2d8795e0;hpb=7fb0771af631512715ee98315ac2382d1730b3d5 diff --git a/dwm.c b/dwm.c index d5eec04..7b3c0ab 100644 --- a/dwm.c +++ b/dwm.c @@ -61,7 +61,7 @@ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ enum { SchemeNorm, SchemeSel, SchemeLast }; /* color schemes */ enum { NetSupported, NetWMName, NetWMState, NetWMFullscreen, NetWMWindowOpacity, NetActiveWindow, NetWMWindowType, - NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */ + NetWMWindowTypeDialog, NetClientList, NetSupportingWMCheck, NetLast }; /* EWMH atoms */ enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */ enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, ClkRootWin, ClkLast }; /* clicks */ @@ -90,6 +90,7 @@ struct Client { int oldx, oldy, oldw, oldh; int basew, baseh, incw, inch, maxw, maxh, minw, minh; int bw, oldbw; + int opacity; unsigned int tags; Bool isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen, screen_hog; Client *next; @@ -272,22 +273,59 @@ static Monitor *mons, *selmon; static Window root; // unfocused windows get transparent (feature) -static const unsigned long unfocused_opacity[] = { 0xbfffffff }; -static const unsigned long invisible_opacity[] = { 0x00000000 }; +static const unsigned long opacities[] = { 0, 0xbfffffff, 0x00000000 }; // first unused static void window_set_opaque(Client *c); static void window_set_translucent(Client *c); static void window_set_invisible(Client *c); +static void window_set_opacity(Client *c, int opacity_index); +static void update_window_opacities(Monitor *m); +void +window_set_opacity(Client *c, int opacity_index) { + if (c->opacity == opacity_index) { + return; + } + c->opacity = opacity_index; + if (opacity_index == 0) { + XDeleteProperty(dpy, c->win, netatom[NetWMWindowOpacity]); + } else { + XChangeProperty(dpy, c->win, netatom[NetWMWindowOpacity], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)(&opacities[opacity_index]), 1); + } +} void window_set_opaque(Client *c) { - XDeleteProperty(dpy, c->win, netatom[NetWMWindowOpacity]); + window_set_opacity(c, 0); } void window_set_translucent(Client *c) { - XChangeProperty(dpy, c->win, netatom[NetWMWindowOpacity], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)unfocused_opacity, 1); + window_set_opacity(c, 1); } void window_set_invisible(Client *c) { - XChangeProperty(dpy, c->win, netatom[NetWMWindowOpacity], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)invisible_opacity, 1); + window_set_opacity(c, 2); +} +void +update_window_opacities(Monitor *m) { + Client *master, *slave, *c; + Bool selection_floating = False; + slave = master = nexttiled(m->clients); + if (master) slave = nexttiled(master->next); + if (m->sel && m->sel != master) { + if (nexttiled(m->sel) == m->sel) // if selection is tiled + slave = m->sel; + else + selection_floating = True; + } + for (c = m->clients; c; c = c->next) { + if (ISVISIBLE(c)) { + if (c->isfloating || c == m->sel || (c == master && selection_floating)) { + window_set_opaque(c); + } else if (c == master || c == slave) { + window_set_translucent(c); + } else { + window_set_invisible(c); + } + } + } } @@ -849,6 +887,7 @@ focus(Client *c) { XDeleteProperty(dpy, root, netatom[NetActiveWindow]); } selmon->sel = c; + update_window_opacities(selmon); drawbars(); if(c && (!root || (c->win!=root)) ) window_set_opaque(c); @@ -1069,6 +1108,7 @@ manage(Window w, XWindowAttributes *wa) { if(!(c = calloc(1, sizeof(Client)))) die("fatal: could not malloc() %u bytes\n", sizeof(Client)); + c->opacity = -1; // who knows c->win = w; updatetitle(c); if(XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) { @@ -1591,6 +1631,7 @@ setup(void) { 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); + netatom[NetSupportingWMCheck] = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False); /* init cursors */ cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr); cursor[CurResize] = drw_cur_create(drw, XC_sizing); @@ -1652,8 +1693,8 @@ spawn(const Arg *arg) { break; } } - _SWM_WS[8] = swm_tags[tag][0]; - _SWM_WS[9] = swm_tags[tag][1]; + WORKSPACE_NUMBER[17] = workspace_numbers_str[tag][0]; + WORKSPACE_NUMBER[18] = workspace_numbers_str[tag][1]; } if(arg->v == dmenucmd) dmenumon[0] = '0' + selmon->num; @@ -1804,32 +1845,8 @@ toggleview(const Arg *arg) { void unfocus(Client *c, Bool setfocus) { - Client *w; if(!c) return; - if(!root || c->win!=root) { - w = nexttiled(c->mon->clients); - if (!w) { - // no tiled windows - window_set_translucent(c); - } else if (w == c) { - // master - window_set_translucent(c); - } else { - w = nexttiled(w->next); - if (!w) { - // c must not be tiled - window_set_translucent(c); - } else { - if (w == c) { // first slave - window_set_translucent(c); - } else { - window_set_invisible(c); - window_set_translucent(w); - } - } - } - } grabbuttons(c, False); XSetWindowBorder(dpy, c->win, scheme[SchemeNorm].border->rgb); if(setfocus) { @@ -1890,6 +1907,12 @@ updatebars(void) { m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); + XChangeProperty(dpy, root, netatom[NetSupportingWMCheck], XA_WINDOW, 32, + PropModeReplace, (unsigned char *) &(m->barwin), 1); + XChangeProperty(dpy, m->barwin, netatom[NetSupportingWMCheck], XA_WINDOW, 32, + PropModeReplace, (unsigned char *) &(m->barwin), 1); + XChangeProperty(dpy, m->barwin, netatom[NetWMName], XA_STRING, 8, + PropModeReplace, (unsigned char *) "dwm", 3); XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor); XMapRaised(dpy, m->barwin); }