Move layout systray functions to "dwm/systray.c"
This commit is contained in:
parent
b281865198
commit
6d253f4365
167
dwm.c
167
dwm.c
|
@ -323,6 +323,7 @@ struct Pertag {
|
||||||
/* function implementations */
|
/* function implementations */
|
||||||
|
|
||||||
#include "dwm/layouts.c"
|
#include "dwm/layouts.c"
|
||||||
|
#include "dwm/systray.c"
|
||||||
|
|
||||||
void
|
void
|
||||||
applyrules(Client *c)
|
applyrules(Client *c)
|
||||||
|
@ -1093,16 +1094,6 @@ getstate(Window w)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
|
||||||
getsystraywidth()
|
|
||||||
{
|
|
||||||
unsigned int w = 0;
|
|
||||||
Client *i;
|
|
||||||
if(showsystray)
|
|
||||||
for(i = systray->icons; i; w += i->w + systrayspacing, i = i->next) ;
|
|
||||||
return w ? w + systrayspacing : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
gettextprop(Window w, Atom atom, char *text, unsigned int size)
|
gettextprop(Window w, Atom atom, char *text, unsigned int size)
|
||||||
{
|
{
|
||||||
|
@ -1617,19 +1608,6 @@ recttomon(int x, int y, int w, int h)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
free(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
resetnmaster(const Arg *arg)
|
resetnmaster(const Arg *arg)
|
||||||
{
|
{
|
||||||
|
@ -2490,123 +2468,6 @@ updatestatus(void)
|
||||||
updatesystray();
|
updatesystray();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
updatesystrayicongeom(Client *i, int w, int h)
|
|
||||||
{
|
|
||||||
if (i) {
|
|
||||||
i->h = bh;
|
|
||||||
if (w == h)
|
|
||||||
i->w = bh;
|
|
||||||
else if (h == bh)
|
|
||||||
i->w = w;
|
|
||||||
else
|
|
||||||
i->w = (int) ((float)bh * ((float)w / (float)h));
|
|
||||||
applysizehints(i, &(i->x), &(i->y), &(i->w), &(i->h), 0, False);
|
|
||||||
/* force icons into the systray dimensions if they don't want to */
|
|
||||||
if (i->h > bh) {
|
|
||||||
if (i->w == i->h)
|
|
||||||
i->w = bh;
|
|
||||||
else
|
|
||||||
i->w = (int) ((float)bh * ((float)i->w / (float)i->h));
|
|
||||||
i->h = bh;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
updatesystrayiconstate(Client *i, XPropertyEvent *ev)
|
|
||||||
{
|
|
||||||
long flags;
|
|
||||||
int code = 0;
|
|
||||||
|
|
||||||
if (!showsystray || !i || ev->atom != atoms->xatom[XembedInfo] ||
|
|
||||||
!(flags = getatomprop(i, atoms->xatom[XembedInfo])))
|
|
||||||
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, atoms->xatom[Xembed], StructureNotifyMask, CurrentTime, code, 0,
|
|
||||||
systray->win, XEMBED_EMBEDDED_VERSION);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
updatesystray(void)
|
|
||||||
{
|
|
||||||
XSetWindowAttributes wa;
|
|
||||||
XWindowChanges wc;
|
|
||||||
Client *i;
|
|
||||||
Monitor *m = systraytomon(NULL);
|
|
||||||
unsigned int x = m->mx + m->mw;
|
|
||||||
unsigned int sw = TEXTW(stext) - lrpad + systrayspacing;
|
|
||||||
unsigned int w = 1;
|
|
||||||
|
|
||||||
if (!showsystray)
|
|
||||||
return;
|
|
||||||
if (systrayonleft)
|
|
||||||
x -= sw + lrpad / 2;
|
|
||||||
if (!systray) {
|
|
||||||
/* 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, m->by, w, bh, 0, 0, scheme[SchemeSel][ColBg].pixel);
|
|
||||||
wa.event_mask = ButtonPressMask | ExposureMask;
|
|
||||||
wa.override_redirect = True;
|
|
||||||
wa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
|
|
||||||
XSelectInput(dpy, systray->win, SubstructureNotifyMask);
|
|
||||||
XChangeProperty(dpy, systray->win, atoms->netatom[NetSystemTrayOrientation], XA_CARDINAL, 32,
|
|
||||||
PropModeReplace, (unsigned char *)&atoms->netatom[NetSystemTrayOrientationHorz], 1);
|
|
||||||
XChangeWindowAttributes(dpy, systray->win, CWEventMask|CWOverrideRedirect|CWBackPixel, &wa);
|
|
||||||
XMapRaised(dpy, systray->win);
|
|
||||||
XSetSelectionOwner(dpy, atoms->netatom[NetSystemTray], systray->win, CurrentTime);
|
|
||||||
if (XGetSelectionOwner(dpy, atoms->netatom[NetSystemTray]) == systray->win) {
|
|
||||||
sendevent(root, atoms->xatom[Manager], StructureNotifyMask, CurrentTime, atoms->netatom[NetSystemTray], systray->win, 0, 0);
|
|
||||||
XSync(dpy, False);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fprintf(stderr, "polytreewm: unable to obtain system tray.\n");
|
|
||||||
free(systray);
|
|
||||||
systray = NULL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
XChangeWindowAttributes(dpy, i->win, CWBackPixel, &wa);
|
|
||||||
XMapRaised(dpy, i->win);
|
|
||||||
w += systrayspacing;
|
|
||||||
i->x = w;
|
|
||||||
XMoveResizeWindow(dpy, i->win, i->x, 0, i->w, i->h);
|
|
||||||
w += i->w;
|
|
||||||
if (i->mon != m)
|
|
||||||
i->mon = m;
|
|
||||||
}
|
|
||||||
w = w ? w + systrayspacing : 1;
|
|
||||||
x -= w;
|
|
||||||
XMoveResizeWindow(dpy, systray->win, x, m->by, w, bh);
|
|
||||||
wc.x = x; wc.y = m->by; 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);
|
|
||||||
XFillRectangle(dpy, systray->win, drw->gc, 0, 0, w, bh);
|
|
||||||
XSync(dpy, False);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
updatetitle(Client *c)
|
updatetitle(Client *c)
|
||||||
{
|
{
|
||||||
|
@ -2744,16 +2605,6 @@ wintoclient(Window w)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Client *
|
|
||||||
wintosystrayicon(Window w) {
|
|
||||||
Client *i = NULL;
|
|
||||||
|
|
||||||
if (!showsystray || !w)
|
|
||||||
return i;
|
|
||||||
for (i = systray->icons; i && i->win != w; i = i->next) ;
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
Monitor *
|
Monitor *
|
||||||
wintomon(Window w)
|
wintomon(Window w)
|
||||||
{
|
{
|
||||||
|
@ -2807,22 +2658,6 @@ xerrorstart(Display *dpy, XErrorEvent *ee)
|
||||||
return -1;
|
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
|
void
|
||||||
zoom(const Arg *arg)
|
zoom(const Arg *arg)
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,165 @@
|
||||||
|
unsigned int
|
||||||
|
getsystraywidth()
|
||||||
|
{
|
||||||
|
unsigned int w = 0;
|
||||||
|
Client *i;
|
||||||
|
if(showsystray)
|
||||||
|
for(i = systray->icons; i; w += i->w + systrayspacing, i = i->next) ;
|
||||||
|
return w ? w + systrayspacing : 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;
|
||||||
|
free(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
updatesystray(void)
|
||||||
|
{
|
||||||
|
XSetWindowAttributes wa;
|
||||||
|
XWindowChanges wc;
|
||||||
|
Client *i;
|
||||||
|
Monitor *m = systraytomon(NULL);
|
||||||
|
unsigned int x = m->mx + m->mw;
|
||||||
|
unsigned int sw = TEXTW(stext) - lrpad + systrayspacing;
|
||||||
|
unsigned int w = 1;
|
||||||
|
|
||||||
|
if (!showsystray)
|
||||||
|
return;
|
||||||
|
if (systrayonleft)
|
||||||
|
x -= sw + lrpad / 2;
|
||||||
|
if (!systray) {
|
||||||
|
/* 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, m->by, w, bh, 0, 0, scheme[SchemeSel][ColBg].pixel);
|
||||||
|
wa.event_mask = ButtonPressMask | ExposureMask;
|
||||||
|
wa.override_redirect = True;
|
||||||
|
wa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
|
||||||
|
XSelectInput(dpy, systray->win, SubstructureNotifyMask);
|
||||||
|
XChangeProperty(dpy, systray->win, atoms->netatom[NetSystemTrayOrientation], XA_CARDINAL, 32,
|
||||||
|
PropModeReplace, (unsigned char *)&atoms->netatom[NetSystemTrayOrientationHorz], 1);
|
||||||
|
XChangeWindowAttributes(dpy, systray->win, CWEventMask|CWOverrideRedirect|CWBackPixel, &wa);
|
||||||
|
XMapRaised(dpy, systray->win);
|
||||||
|
XSetSelectionOwner(dpy, atoms->netatom[NetSystemTray], systray->win, CurrentTime);
|
||||||
|
if (XGetSelectionOwner(dpy, atoms->netatom[NetSystemTray]) == systray->win) {
|
||||||
|
sendevent(root, atoms->xatom[Manager], StructureNotifyMask, CurrentTime, atoms->netatom[NetSystemTray], systray->win, 0, 0);
|
||||||
|
XSync(dpy, False);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fprintf(stderr, "polytreewm: unable to obtain system tray.\n");
|
||||||
|
free(systray);
|
||||||
|
systray = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
XChangeWindowAttributes(dpy, i->win, CWBackPixel, &wa);
|
||||||
|
XMapRaised(dpy, i->win);
|
||||||
|
w += systrayspacing;
|
||||||
|
i->x = w;
|
||||||
|
XMoveResizeWindow(dpy, i->win, i->x, 0, i->w, i->h);
|
||||||
|
w += i->w;
|
||||||
|
if (i->mon != m)
|
||||||
|
i->mon = m;
|
||||||
|
}
|
||||||
|
w = w ? w + systrayspacing : 1;
|
||||||
|
x -= w;
|
||||||
|
XMoveResizeWindow(dpy, systray->win, x, m->by, w, bh);
|
||||||
|
wc.x = x; wc.y = m->by; 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);
|
||||||
|
XFillRectangle(dpy, systray->win, drw->gc, 0, 0, w, bh);
|
||||||
|
XSync(dpy, False);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
updatesystrayicongeom(Client *i, int w, int h)
|
||||||
|
{
|
||||||
|
if (i) {
|
||||||
|
i->h = bh;
|
||||||
|
if (w == h)
|
||||||
|
i->w = bh;
|
||||||
|
else if (h == bh)
|
||||||
|
i->w = w;
|
||||||
|
else
|
||||||
|
i->w = (int) ((float)bh * ((float)w / (float)h));
|
||||||
|
applysizehints(i, &(i->x), &(i->y), &(i->w), &(i->h), 0, False);
|
||||||
|
/* force icons into the systray dimensions if they don't want to */
|
||||||
|
if (i->h > bh) {
|
||||||
|
if (i->w == i->h)
|
||||||
|
i->w = bh;
|
||||||
|
else
|
||||||
|
i->w = (int) ((float)bh * ((float)i->w / (float)i->h));
|
||||||
|
i->h = bh;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
updatesystrayiconstate(Client *i, XPropertyEvent *ev)
|
||||||
|
{
|
||||||
|
long flags;
|
||||||
|
int code = 0;
|
||||||
|
|
||||||
|
if (!showsystray || !i || ev->atom != atoms->xatom[XembedInfo] ||
|
||||||
|
!(flags = getatomprop(i, atoms->xatom[XembedInfo])))
|
||||||
|
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, atoms->xatom[Xembed], StructureNotifyMask, CurrentTime, code, 0,
|
||||||
|
systray->win, XEMBED_EMBEDDED_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
Client *
|
||||||
|
wintosystrayicon(Window w) {
|
||||||
|
Client *i = NULL;
|
||||||
|
|
||||||
|
if (!showsystray || !w)
|
||||||
|
return i;
|
||||||
|
for (i = systray->icons; i && i->win != w; i = i->next) ;
|
||||||
|
return i;
|
||||||
|
}
|
Loading…
Reference in New Issue