From 96c57c3c4be6ace946225e92035ecc34a013b223 Mon Sep 17 00:00:00 2001 From: _N0x Date: Thu, 14 Oct 2021 15:13:35 +0200 Subject: [PATCH] Removed regular systray patch and applied alpha-systray patch instead --- dwm-6.2/dwm.c | 181 ++++++++++++++++++++++++-------------------------- 1 file changed, 86 insertions(+), 95 deletions(-) diff --git a/dwm-6.2/dwm.c b/dwm-6.2/dwm.c index a9737d1..6109fbc 100644 --- a/dwm-6.2/dwm.c +++ b/dwm-6.2/dwm.c @@ -59,6 +59,7 @@ #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) #define SYSTEM_TRAY_REQUEST_DOCK 0 +#define _NET_SYSTEM_TRAY_ORIENTATION_HORZ 0 /* XEMBED messages */ #define XEMBED_EMBEDDED_NOTIFY 0 @@ -79,10 +80,9 @@ /* enums */ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ enum { SchemeNorm, SchemeSel}; /* color schemes */ -enum { NetSupported, NetWMName, NetWMState, NetWMCheck, - NetSystemTray, NetSystemTrayOP, NetSystemTrayOrientation, NetSystemTrayOrientationHorz, - NetWMFullscreen, NetActiveWindow, NetWMWindowType, - NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */ +enum { NetSupported, NetSystemTray, NetSystemTrayOP, NetSystemTrayOrientation, NetSystemTrayVisual, + NetWMName, NetWMState, NetWMFullscreen, NetActiveWindow, NetWMWindowType, NetWMWindowTypeDock, + NetSystemTrayOrientationHorz, NetWMWindowTypeDialog, NetClientList, NetWMCheck, NetLast }; /* EWMH atoms */ enum { Manager, Xembed, XembedInfo, XLast }; /* Xembed atoms */ enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */ enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, @@ -198,6 +198,7 @@ static void focus(Client *c); static void focusin(XEvent *e); static void focusmon(const Arg *arg); static void focusstack(const Arg *arg); +static Atom getatomprop(Client *c, Atom prop); static int getrootptr(int *x, int *y); static long getstate(Window w); static unsigned int getsystraywidth(); @@ -220,7 +221,6 @@ static void quit(const Arg *arg); static Monitor *recttomon(int x, int y, int w, int h); static void removesystrayicon(Client *i); static void resize(Client *c, int x, int y, int w, int h, int interact); -static void resizebarwin(Monitor *m); static void resizeclient(Client *c, int x, int y, int w, int h); static void resizemouse(const Arg *arg); static void resizerequest(XEvent *e); @@ -259,7 +259,7 @@ static int updategeom(void); static void updatenumlockmask(void); static void updatesizehints(Client *c); static void updatestatus(void); -static void updatesystray(void); +static void updatesystray(int updatebar); static void updatesystrayicongeom(Client *i, int w, int h); static void updatesystrayiconstate(Client *i, XPropertyEvent *ev); static void updatetitle(Client *c); @@ -277,6 +277,7 @@ static void zoom(const Arg *arg); /* variables */ static Systray *systray = NULL; +static unsigned long systrayorientation = _NET_SYSTEM_TRAY_ORIENTATION_HORZ; static const char autostartblocksh[] = "autostart_blocking.sh"; static const char autostartsh[] = "autostart.sh"; static const char broken[] = "broken"; @@ -537,6 +538,8 @@ cleanup(void) while (mons) cleanupmon(mons); if (showsystray) { + while (systray->icons) + removesystrayicon(systray->icons); XUnmapWindow(dpy, systray->win); XDestroyWindow(dpy, systray->win); free(systray); @@ -588,12 +591,7 @@ clientmessage(XEvent *e) c->mon = selmon; c->next = systray->icons; systray->icons = c; - if (!XGetWindowAttributes(dpy, c->win, &wa)) { - /* use sane defaults */ - wa.width = bh; - wa.height = bh; - wa.border_width = 0; - } + XGetWindowAttributes(dpy, c->win, &wa); c->x = c->oldx = c->y = c->oldy = 0; c->w = c->oldw = wa.width; c->h = c->oldh = wa.height; @@ -611,14 +609,9 @@ clientmessage(XEvent *e) swa.background_pixel = scheme[SchemeNorm][ColBg].pixel; XChangeWindowAttributes(dpy, c->win, CWBackPixel, &swa); sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_EMBEDDED_NOTIFY, 0 , systray->win, XEMBED_EMBEDDED_VERSION); - /* FIXME not sure if I have to send these events, too */ - sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_FOCUS_IN, 0 , systray->win, XEMBED_EMBEDDED_VERSION); - sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_WINDOW_ACTIVATE, 0 , systray->win, XEMBED_EMBEDDED_VERSION); - sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_MODALITY_ON, 0 , systray->win, XEMBED_EMBEDDED_VERSION); XSync(dpy, False); - resizebarwin(selmon); - updatesystray(); setclientstate(c, NormalState); + updatesystray(1); } return; } @@ -674,7 +667,7 @@ configurenotify(XEvent *e) for (c = m->clients; c; c = c->next) if (c->isfullscreen) resizeclient(c, m->mx, m->my, m->mw, m->mh); - resizebarwin(m); + XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh); } focus(NULL); arrange(NULL); @@ -760,10 +753,9 @@ destroynotify(XEvent *e) if ((c = wintoclient(ev->window))) unmanage(c, 1); - else if ((c = wintosystrayicon(ev->window))) { + else if (showsystray && (c = wintosystrayicon(ev->window))) { removesystrayicon(c); - resizebarwin(selmon); - updatesystray(); + updatesystray(1); } } @@ -921,8 +913,11 @@ drawbar(Monitor *m) unsigned int i, occ = 0, urg = 0; Client *c; - if(showsystray && m == systraytomon(m)) + if (showsystray && m == systraytomon(m)) { stw = getsystraywidth(); + drw_setscheme(drw, scheme[SchemeNorm]); + drw_rect(drw, m->ww - stw - 2 * sp, 0, stw, bh, 1, 1); + } /* draw status first so it can be overdrawn by tags later */ if (m == selmon) { /* status is only drawn on selected monitor */ @@ -932,7 +927,6 @@ drawbar(Monitor *m) sw = m->ww - drawstatusbar(m, bh, stext, stw); } - resizebarwin(m); for (c = m->clients; c; c = c->next) { occ |= c->tags; if (c->isurgent) @@ -966,7 +960,7 @@ drawbar(Monitor *m) drw_rect(drw, x, 0, w - 2 * sp, bh, 1, 1); } } - drw_map(drw, m->barwin, 0, 0, m->ww - stw, bh); + drw_map(drw, m->barwin, 0, 0, m->ww, bh); } void @@ -976,6 +970,9 @@ drawbars(void) for (m = mons; m; m = m->next) drawbar(m); + + if (showsystray && !systraypinning) + updatesystray(0); } void @@ -1005,8 +1002,8 @@ expose(XEvent *e) if (ev->count == 0 && (m = wintomon(ev->window))) { drawbar(m); - if (m == selmon) - updatesystray(); + if (showsystray && m == systraytomon(m)) + updatesystray(0); } } @@ -1143,7 +1140,7 @@ getsystraywidth() Client *i; if(showsystray) for(i = systray->icons; i; w += i->w + systrayspacing, i = i->next) ; - return w ? w + systrayspacing : 1; + return w ? w + systrayspacing : 0; } int @@ -1339,10 +1336,9 @@ maprequest(XEvent *e) static XWindowAttributes wa; XMapRequestEvent *ev = &e->xmaprequest; Client *i; - if ((i = wintosystrayicon(ev->window))) { + if (showsystray && (i = wintosystrayicon(ev->window))) { sendevent(i->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_WINDOW_ACTIVATE, 0, systray->win, XEMBED_EMBEDDED_VERSION); - resizebarwin(selmon); - updatesystray(); + updatesystray(1); } if (!XGetWindowAttributes(dpy, ev->window, &wa)) @@ -1468,15 +1464,14 @@ propertynotify(XEvent *e) Window trans; XPropertyEvent *ev = &e->xproperty; - if ((c = wintosystrayicon(ev->window))) { + if (showsystray && (c = wintosystrayicon(ev->window))) { if (ev->atom == XA_WM_NORMAL_HINTS) { updatesizehints(c); updatesystrayicongeom(c, c->w, c->h); } else updatesystrayiconstate(c, ev); - resizebarwin(selmon); - updatesystray(); + updatesystray(1); } if ((ev->window == root) && (ev->atom == XA_WM_NAME)) updatestatus(); @@ -1549,14 +1544,6 @@ resize(Client *c, int x, int y, int w, int h, int interact) resizeclient(c, x, y, w, h); } -void -resizebarwin(Monitor *m) { - unsigned int w = m->ww; - if (showsystray && m == systraytomon(m)) - w -= getsystraywidth(); - XMoveResizeWindow(dpy, m->barwin, m->wx + sp, m->by + vp, w - 2 * sp, bh); -} - void resizeclient(Client *c, int x, int y, int w, int h) { @@ -1637,8 +1624,7 @@ resizerequest(XEvent *e) if ((i = wintosystrayicon(ev->window))) { updatesystrayicongeom(i, ev->width, ev->height); - resizebarwin(selmon); - updatesystray(); + updatesystray(1); } } @@ -1958,11 +1944,13 @@ setup(void) netatom[NetSystemTrayOP] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_OPCODE", False); netatom[NetSystemTrayOrientation] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_ORIENTATION", False); netatom[NetSystemTrayOrientationHorz] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_ORIENTATION_HORZ", False); + netatom[NetSystemTrayVisual] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_VISUAL", False); netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False); netatom[NetWMCheck] = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False); netatom[NetWMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False); netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False); + netatom[NetWMWindowTypeDock] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DOCK", False); netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False); netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False); xatom[Manager] = XInternAtom(dpy, "MANAGER", False); @@ -1978,7 +1966,8 @@ setup(void) for (i = 0; i < LENGTH(colors); i++) scheme[i] = drw_scm_create(drw, colors[i], alphas[i], 3); /* init system tray */ - updatesystray(); + if (showsystray) + updatesystray(0); /* init bars */ updatebars(); updatestatus(); @@ -2062,6 +2051,23 @@ spawn(const Arg *arg) } } +Monitor * +systraytomon(Monitor *m) +{ + Monitor *t; + int i, n; + if (!systraypinning) { + if (!m) + return selmon; + return m == selmon ? m : NULL; + } + for (n = 1, t = mons; t && t->next; n++, t = t->next); + for (i = 1, t = mons; t && t->next && i < systraypinning; i++, t = t->next); + if (systraypinningfailfirst && n < systraypinning) + return mons; + return t; +} + void tag(const Arg *arg) { @@ -2111,15 +2117,15 @@ togglebar(const Arg *arg) { selmon->showbar = !selmon->showbar; updatebarpos(selmon); - resizebarwin(selmon); + XMoveResizeWindow(dpy, selmon->barwin, selmon->wx + sp, selmon->by + vp, selmon->ww - 2 * sp, bh); if (showsystray) { XWindowChanges wc; if (!selmon->showbar) wc.y = -bh; else if (selmon->showbar) { - wc.y = 0; + wc.y = vp; if (!selmon->topbar) - wc.y = selmon->mh - bh; + wc.y = selmon->mh - bh + vp; } XConfigureWindow(dpy, systray->win, CWY, &wc); } @@ -2217,18 +2223,17 @@ unmapnotify(XEvent *e) else unmanage(c, 0); } - else if ((c = wintosystrayicon(ev->window))) { + else if (showsystray && (c = wintosystrayicon(ev->window))) { /* KLUDGE! sometimes icons occasionally unmap their windows, but do * _not_ destroy them. We map those windows back */ XMapRaised(dpy, c->win); - updatesystray(); + updatesystray(1); } } void updatebars(void) { - unsigned int w; Monitor *m; XSetWindowAttributes wa = { .override_redirect = True, @@ -2241,13 +2246,10 @@ updatebars(void) for (m = mons; m; m = m->next) { if (m->barwin) continue; - w = m->ww; - if (showsystray && m == systraytomon(m)) - w -= getsystraywidth(); //m->barwin = XCreateWindow(dpy, root, m->wx + sp, m->by + vp, w -2 * sp, bh, 0, DefaultDepth(dpy, screen), // CopyFromParent, DefaultVisual(dpy, screen), // CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); - m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, depth, + m->barwin = XCreateWindow(dpy, root, m->wx + sp, m->by + vp, m->ww - 2 * sp, bh, 0, depth, InputOutput, visual, CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &wa); XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor); @@ -2428,7 +2430,6 @@ updatestatus(void) if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) strcpy(stext, "dwm-"VERSION); drawbar(selmon); - updatesystray(); } void @@ -2451,6 +2452,8 @@ updatesystrayicongeom(Client *i, int w, int h) i->w = (int) ((float)bh * ((float)i->w / (float)i->h)); i->h = bh; } + if (i->w > 2*bh) + i->w = bh; } } @@ -2483,15 +2486,16 @@ updatesystrayiconstate(Client *i, XPropertyEvent *ev) } void -updatesystray(void) +updatesystray(int updatebar) { XSetWindowAttributes wa; XWindowChanges wc; Client *i; Monitor *m = systraytomon(NULL); - unsigned int x = m->mx + m->mw - sp; - unsigned int y = m->by + vp; - unsigned int w = 1; + unsigned int x = m->mx + m->mw; + unsigned int w = 1, xpad = 0, ypad = 0; + xpad = sp; + ypad = vp; if (!showsystray) return; @@ -2499,14 +2503,22 @@ updatesystray(void) /* init systray */ if (!(systray = (Systray *)calloc(1, sizeof(Systray)))) die("fatal: could not malloc() %u bytes\n", sizeof(Systray)); - systray->win = XCreateSimpleWindow(dpy, root, x, y, w, bh, 0, 0, scheme[SchemeSel][ColBg].pixel); - wa.event_mask = ButtonPressMask | ExposureMask; + wa.override_redirect = True; - wa.background_pixel = scheme[SchemeNorm][ColBg].pixel; + wa.event_mask = ButtonPressMask|ExposureMask; + wa.background_pixel = 0; + wa.border_pixel = 0; + wa.colormap = cmap; + systray->win = XCreateWindow(dpy, root, x - xpad, m->by + ypad, w, bh, 0, depth, + InputOutput, visual, + CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &wa); XSelectInput(dpy, systray->win, SubstructureNotifyMask); XChangeProperty(dpy, systray->win, netatom[NetSystemTrayOrientation], XA_CARDINAL, 32, - PropModeReplace, (unsigned char *)&netatom[NetSystemTrayOrientationHorz], 1); - XChangeWindowAttributes(dpy, systray->win, CWEventMask|CWOverrideRedirect|CWBackPixel, &wa); + PropModeReplace, (unsigned char *)&systrayorientation, 1); + XChangeProperty(dpy, systray->win, netatom[NetSystemTrayVisual], XA_VISUALID, 32, + PropModeReplace, (unsigned char *)&visual->visualid, 1); + XChangeProperty(dpy, systray->win, netatom[NetWMWindowType], XA_ATOM, 32, + PropModeReplace, (unsigned char *)&netatom[NetWMWindowTypeDock], 1); XMapRaised(dpy, systray->win); XSetSelectionOwner(dpy, netatom[NetSystemTray], systray->win, CurrentTime); if (XGetSelectionOwner(dpy, netatom[NetSystemTray]) == systray->win) { @@ -2521,8 +2533,7 @@ updatesystray(void) } } for (w = 0, i = systray->icons; i; i = i->next) { - /* make sure the background color stays the same */ - wa.background_pixel = scheme[SchemeNorm][ColBg].pixel; + wa.background_pixel = 0; XChangeWindowAttributes(dpy, i->win, CWBackPixel, &wa); XMapRaised(dpy, i->win); w += systrayspacing; @@ -2534,23 +2545,19 @@ updatesystray(void) } w = w ? w + systrayspacing : 1; x -= w; - XMoveResizeWindow(dpy, systray->win, x, m->by, w, bh); - wc.x = x; - wc.y = y; - wc.width = w; - wc.height = bh; - wc.stack_mode = Above; - wc.sibling = m->barwin; + XMoveResizeWindow(dpy, systray->win, x - xpad, m->by + ypad, w, bh); + wc.x = x - xpad; + wc.y = m->by + ypad; + wc.width = w; + wc.height = bh; + wc.stack_mode = Above; wc.sibling = m->barwin; XConfigureWindow(dpy, systray->win, CWX|CWY|CWWidth|CWHeight|CWSibling|CWStackMode, &wc); XMapWindow(dpy, systray->win); XMapSubwindows(dpy, systray->win); - /* redraw background */ - XSetForeground(dpy, drw->gc, scheme[SchemeNorm][ColBg].pixel); - // FIXME: - //XFillRectangle(dpy, systray->win, drw->gc, 0, 0, w, bh); XSync(dpy, False); + if (updatebar) + drawbar(m); } - void updatetitle(Client *c) { @@ -2679,22 +2686,6 @@ xerrorstart(Display *dpy, XErrorEvent *ee) return -1; } -Monitor * -systraytomon(Monitor *m) { - Monitor *t; - int i, n; - if(!systraypinning) { - if(!m) - return selmon; - return m == selmon ? m : NULL; - } - for(n = 1, t = mons; t && t->next; n++, t = t->next) ; - for(i = 1, t = mons; t && t->next && i < systraypinning; i++, t = t->next) ; - if(systraypinningfailfirst && n < systraypinning) - return mons; - return t; -} - void xinitvisual() {