2019-09-05 20:10:00 +00:00
|
|
|
static Systray *systray = NULL;
|
|
|
|
static unsigned long systrayorientation = _NET_SYSTEM_TRAY_ORIENTATION_HORZ;
|
|
|
|
|
2020-07-15 06:57:30 +00:00
|
|
|
int
|
2020-09-09 15:24:02 +00:00
|
|
|
width_systray(Bar *bar, BarArg *a)
|
2019-09-05 20:10:00 +00:00
|
|
|
{
|
|
|
|
unsigned int w = 0;
|
|
|
|
Client *i;
|
2020-07-15 06:57:30 +00:00
|
|
|
if (!systray)
|
|
|
|
return 1;
|
2022-06-27 09:07:26 +00:00
|
|
|
if (showsystray) {
|
2019-09-05 20:10:00 +00:00
|
|
|
for (i = systray->icons; i; w += i->w + systrayspacing, i = i->next);
|
2022-06-27 09:07:26 +00:00
|
|
|
if (!w)
|
|
|
|
XMoveWindow(dpy, systray->win, -systray->h, bar->by);
|
|
|
|
}
|
2020-07-18 11:03:30 +00:00
|
|
|
return w ? w + lrpad - systrayspacing : 0;
|
2019-09-05 20:10:00 +00:00
|
|
|
}
|
|
|
|
|
2020-07-15 06:57:30 +00:00
|
|
|
int
|
2020-09-09 15:24:02 +00:00
|
|
|
draw_systray(Bar *bar, BarArg *a)
|
2019-09-05 20:10:00 +00:00
|
|
|
{
|
2020-07-15 06:57:30 +00:00
|
|
|
if (!showsystray)
|
2020-08-22 06:43:07 +00:00
|
|
|
return 0;
|
2020-07-18 11:03:30 +00:00
|
|
|
|
2019-09-05 20:10:00 +00:00
|
|
|
XSetWindowAttributes wa;
|
2020-11-28 09:58:00 +00:00
|
|
|
XWindowChanges wc;
|
2019-09-05 20:10:00 +00:00
|
|
|
Client *i;
|
2020-07-18 11:03:30 +00:00
|
|
|
unsigned int w;
|
2019-09-05 20:10:00 +00:00
|
|
|
|
|
|
|
if (!systray) {
|
|
|
|
/* init systray */
|
|
|
|
if (!(systray = (Systray *)calloc(1, sizeof(Systray))))
|
|
|
|
die("fatal: could not malloc() %u bytes\n", sizeof(Systray));
|
|
|
|
|
2020-07-18 11:03:30 +00:00
|
|
|
wa.override_redirect = True;
|
|
|
|
wa.event_mask = ButtonPressMask|ExposureMask;
|
|
|
|
wa.border_pixel = 0;
|
2020-10-24 08:01:19 +00:00
|
|
|
systray->h = MIN(a->h, drw->fonts->h);
|
2020-07-18 11:03:30 +00:00
|
|
|
#if BAR_ALPHA_PATCH
|
|
|
|
wa.background_pixel = 0;
|
|
|
|
wa.colormap = cmap;
|
2022-06-27 09:07:26 +00:00
|
|
|
systray->win = XCreateWindow(dpy, root, bar->bx + a->x + lrpad / 2, -systray->h, MAX(a->w + 40, 1), systray->h, 0, depth,
|
2020-07-18 11:03:30 +00:00
|
|
|
InputOutput, visual,
|
|
|
|
CWOverrideRedirect|CWBorderPixel|CWBackPixel|CWColormap|CWEventMask, &wa); // CWBackPixmap
|
|
|
|
#else
|
|
|
|
wa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
|
2022-06-27 09:07:26 +00:00
|
|
|
systray->win = XCreateSimpleWindow(dpy, root, bar->bx + a->x + lrpad / 2, -systray->h, MIN(a->w, 1), systray->h, 0, 0, scheme[SchemeNorm][ColBg].pixel);
|
2020-07-18 11:03:30 +00:00
|
|
|
XChangeWindowAttributes(dpy, systray->win, CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWEventMask, &wa);
|
|
|
|
#endif // BAR_ALPHA_PATCH
|
2020-07-15 06:57:30 +00:00
|
|
|
|
2020-07-18 11:03:30 +00:00
|
|
|
XSelectInput(dpy, systray->win, SubstructureNotifyMask);
|
2019-09-05 20:10:00 +00:00
|
|
|
XChangeProperty(dpy, systray->win, netatom[NetSystemTrayOrientation], XA_CARDINAL, 32,
|
|
|
|
PropModeReplace, (unsigned char *)&systrayorientation, 1);
|
2020-07-15 06:57:30 +00:00
|
|
|
#if BAR_ALPHA_PATCH
|
2019-09-05 20:10:00 +00:00
|
|
|
XChangeProperty(dpy, systray->win, netatom[NetSystemTrayVisual], XA_VISUALID, 32,
|
|
|
|
PropModeReplace, (unsigned char *)&visual->visualid, 1);
|
2020-07-15 06:57:30 +00:00
|
|
|
#endif // BAR_ALPHA_PATCH
|
2019-09-05 20:10:00 +00:00
|
|
|
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) {
|
|
|
|
sendevent(root, xatom[Manager], StructureNotifyMask, CurrentTime, netatom[NetSystemTray], systray->win, 0, 0);
|
|
|
|
XSync(dpy, False);
|
2020-07-15 06:57:30 +00:00
|
|
|
} else {
|
2019-09-05 20:10:00 +00:00
|
|
|
fprintf(stderr, "dwm: unable to obtain system tray.\n");
|
|
|
|
free(systray);
|
|
|
|
systray = NULL;
|
2020-08-22 06:43:07 +00:00
|
|
|
return 0;
|
2019-09-05 20:10:00 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-22 18:39:08 +00:00
|
|
|
|
2020-07-18 11:03:30 +00:00
|
|
|
systray->bar = bar;
|
|
|
|
|
2020-11-28 09:58:00 +00:00
|
|
|
wc.stack_mode = Above;
|
|
|
|
wc.sibling = bar->win;
|
|
|
|
XConfigureWindow(dpy, systray->win, CWSibling|CWStackMode, &wc);
|
|
|
|
|
2020-07-18 11:03:30 +00:00
|
|
|
drw_setscheme(drw, scheme[SchemeNorm]);
|
2019-09-05 20:10:00 +00:00
|
|
|
for (w = 0, i = systray->icons; i; i = i->next) {
|
2020-07-18 11:03:30 +00:00
|
|
|
#if BAR_ALPHA_PATCH
|
|
|
|
wa.background_pixel = 0;
|
|
|
|
#else
|
2019-09-05 20:10:00 +00:00
|
|
|
wa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
|
2020-07-18 11:03:30 +00:00
|
|
|
#endif // BAR_ALPHA_PATCH
|
2019-09-05 20:10:00 +00:00
|
|
|
XChangeWindowAttributes(dpy, i->win, CWBackPixel, &wa);
|
|
|
|
XMapRaised(dpy, i->win);
|
2020-07-18 11:03:30 +00:00
|
|
|
i->x = w;
|
2019-09-05 20:10:00 +00:00
|
|
|
XMoveResizeWindow(dpy, i->win, i->x, 0, i->w, i->h);
|
|
|
|
w += i->w;
|
2020-07-18 11:03:30 +00:00
|
|
|
if (i->next)
|
|
|
|
w += systrayspacing;
|
|
|
|
if (i->mon != bar->mon)
|
|
|
|
i->mon = bar->mon;
|
|
|
|
}
|
|
|
|
|
2024-07-01 07:53:43 +00:00
|
|
|
#if !BAR_ALPHA_PATCH
|
|
|
|
wa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
|
|
|
|
XChangeWindowAttributes(dpy, systray->win, CWBackPixel, &wa);
|
|
|
|
XClearWindow(dpy, systray->win);
|
|
|
|
#endif // BAR_ALPHA_PATCH
|
|
|
|
|
2022-06-27 09:07:26 +00:00
|
|
|
XMoveResizeWindow(dpy, systray->win, bar->bx + a->x + lrpad / 2, (w ? bar->by + a->y + (a->h - systray->h) / 2: -systray->h), MAX(w, 1), systray->h);
|
2020-08-22 06:43:07 +00:00
|
|
|
return w;
|
2020-07-18 11:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-09-09 15:24:02 +00:00
|
|
|
click_systray(Bar *bar, Arg *arg, BarArg *a)
|
2020-07-18 11:03:30 +00:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
removesystrayicon(Client *i)
|
|
|
|
{
|
|
|
|
Client **ii;
|
|
|
|
|
|
|
|
if (!showsystray || !i)
|
|
|
|
return;
|
|
|
|
for (ii = &systray->icons; *ii && *ii != i; ii = &(*ii)->next);
|
|
|
|
if (ii)
|
|
|
|
*ii = i->next;
|
2022-06-17 14:58:47 +00:00
|
|
|
XReparentWindow(dpy, i->win, root, 0, 0);
|
2020-07-18 11:03:30 +00:00
|
|
|
free(i);
|
|
|
|
drawbarwin(systray->bar);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
resizerequest(XEvent *e)
|
|
|
|
{
|
|
|
|
XResizeRequestEvent *ev = &e->xresizerequest;
|
|
|
|
Client *i;
|
|
|
|
|
|
|
|
if ((i = wintosystrayicon(ev->window))) {
|
|
|
|
updatesystrayicongeom(i, ev->width, ev->height);
|
|
|
|
drawbarwin(systray->bar);
|
2019-09-05 20:10:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
updatesystrayicongeom(Client *i, int w, int h)
|
|
|
|
{
|
2020-09-09 15:24:02 +00:00
|
|
|
if (!systray)
|
|
|
|
return;
|
|
|
|
|
2020-10-24 08:01:19 +00:00
|
|
|
int icon_height = systray->h;
|
2019-09-05 20:10:00 +00:00
|
|
|
if (i) {
|
2020-10-24 08:01:19 +00:00
|
|
|
i->h = icon_height;
|
2019-09-05 20:10:00 +00:00
|
|
|
if (w == h)
|
2020-10-24 08:01:19 +00:00
|
|
|
i->w = icon_height;
|
|
|
|
else if (h == icon_height)
|
2019-09-05 20:10:00 +00:00
|
|
|
i->w = w;
|
|
|
|
else
|
2020-10-24 08:01:19 +00:00
|
|
|
i->w = (int) ((float)icon_height * ((float)w / (float)h));
|
2019-09-05 20:10:00 +00:00
|
|
|
applysizehints(i, &(i->x), &(i->y), &(i->w), &(i->h), False);
|
|
|
|
/* force icons into the systray dimensions if they don't want to */
|
2020-10-24 08:01:19 +00:00
|
|
|
if (i->h > icon_height) {
|
2019-09-05 20:10:00 +00:00
|
|
|
if (i->w == i->h)
|
2020-10-24 08:01:19 +00:00
|
|
|
i->w = icon_height;
|
2019-09-05 20:10:00 +00:00
|
|
|
else
|
2020-10-24 08:01:19 +00:00
|
|
|
i->w = (int) ((float)icon_height * ((float)i->w / (float)i->h));
|
|
|
|
i->h = icon_height;
|
2019-09-05 20:10:00 +00:00
|
|
|
}
|
2020-10-24 08:01:19 +00:00
|
|
|
if (i->w > 2 * icon_height)
|
|
|
|
i->w = icon_height;
|
2019-09-05 20:10:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
updatesystrayiconstate(Client *i, XPropertyEvent *ev)
|
|
|
|
{
|
|
|
|
long flags;
|
|
|
|
int code = 0;
|
|
|
|
|
2020-09-07 10:43:37 +00:00
|
|
|
if (!showsystray || !systray || !i || ev->atom != xatom[XembedInfo] ||
|
2022-06-17 12:36:20 +00:00
|
|
|
!(flags = getatomprop(i, xatom[XembedInfo], xatom[XembedInfo])))
|
2019-09-05 20:10:00 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (flags & XEMBED_MAPPED && !i->tags) {
|
|
|
|
i->tags = 1;
|
|
|
|
code = XEMBED_WINDOW_ACTIVATE;
|
|
|
|
XMapRaised(dpy, i->win);
|
|
|
|
setclientstate(i, NormalState);
|
|
|
|
}
|
|
|
|
else if (!(flags & XEMBED_MAPPED) && i->tags) {
|
|
|
|
i->tags = 0;
|
|
|
|
code = XEMBED_WINDOW_DEACTIVATE;
|
|
|
|
XUnmapWindow(dpy, i->win);
|
|
|
|
setclientstate(i, WithdrawnState);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
sendevent(i->win, xatom[Xembed], StructureNotifyMask, CurrentTime, code, 0,
|
|
|
|
systray->win, XEMBED_EMBEDDED_VERSION);
|
|
|
|
}
|
|
|
|
|
|
|
|
Client *
|
2019-09-10 22:51:37 +00:00
|
|
|
wintosystrayicon(Window w)
|
|
|
|
{
|
2020-07-18 11:03:30 +00:00
|
|
|
if (!systray)
|
|
|
|
return NULL;
|
2019-09-05 20:10:00 +00:00
|
|
|
Client *i = NULL;
|
|
|
|
if (!showsystray || !w)
|
|
|
|
return i;
|
|
|
|
for (i = systray->icons; i && i->win != w; i = i->next);
|
|
|
|
return i;
|
2021-06-14 05:16:17 +00:00
|
|
|
}
|
|
|
|
|