Proposed changes to ensure that systray icons are sized according to font size rather than bar height, ref. #62

This commit is contained in:
bakkeby 2020-10-24 10:01:19 +02:00
parent c6c2f0109f
commit 5edf4bab17
2 changed files with 16 additions and 14 deletions

View File

@ -31,15 +31,16 @@ draw_systray(Bar *bar, BarArg *a)
wa.override_redirect = True; wa.override_redirect = True;
wa.event_mask = ButtonPressMask|ExposureMask; wa.event_mask = ButtonPressMask|ExposureMask;
wa.border_pixel = 0; wa.border_pixel = 0;
systray->h = MIN(a->h, drw->fonts->h);
#if BAR_ALPHA_PATCH #if BAR_ALPHA_PATCH
wa.background_pixel = 0; wa.background_pixel = 0;
wa.colormap = cmap; wa.colormap = cmap;
systray->win = XCreateWindow(dpy, root, bar->bx + a->x + lrpad / 2, bar->by + a->y, MAX(a->w + 40, 1), a->h, 0, depth, systray->win = XCreateWindow(dpy, root, bar->bx + a->x + lrpad / 2, bar->by + a->y + (a->h - systray->h) / 2, MAX(a->w + 40, 1), systray->h, 0, depth,
InputOutput, visual, InputOutput, visual,
CWOverrideRedirect|CWBorderPixel|CWBackPixel|CWColormap|CWEventMask, &wa); // CWBackPixmap CWOverrideRedirect|CWBorderPixel|CWBackPixel|CWColormap|CWEventMask, &wa); // CWBackPixmap
#else #else
wa.background_pixel = scheme[SchemeNorm][ColBg].pixel; wa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
systray->win = XCreateSimpleWindow(dpy, root, bar->bx + a->x + lrpad / 2, bar->by + a->y, MIN(a->w, 1), a->h, 0, 0, scheme[SchemeNorm][ColBg].pixel); systray->win = XCreateSimpleWindow(dpy, root, bar->bx + a->x + lrpad / 2, bar->by + a->y + (a->h - systray->h) / 2, MIN(a->w, 1), systray->h, 0, 0, scheme[SchemeNorm][ColBg].pixel);
XChangeWindowAttributes(dpy, systray->win, CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWEventMask, &wa); XChangeWindowAttributes(dpy, systray->win, CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWEventMask, &wa);
#endif // BAR_ALPHA_PATCH #endif // BAR_ALPHA_PATCH
@ -85,7 +86,7 @@ draw_systray(Bar *bar, BarArg *a)
i->mon = bar->mon; i->mon = bar->mon;
} }
XMoveResizeWindow(dpy, systray->win, bar->bx + a->x + lrpad / 2, (w ? bar->by + a->y : -bar->by - a->y), MAX(w, 1), a->h); XMoveResizeWindow(dpy, systray->win, bar->bx + a->x + lrpad / 2, (w ? bar->by + a->y + (a->h - systray->h) / 2: -bar->by - a->y), MAX(w, 1), systray->h);
return w; return w;
} }
@ -127,26 +128,26 @@ updatesystrayicongeom(Client *i, int w, int h)
if (!systray) if (!systray)
return; return;
int bar_height = systray->bar->bh - 2 * systray->bar->borderpx; int icon_height = systray->h;
if (i) { if (i) {
i->h = bar_height; i->h = icon_height;
if (w == h) if (w == h)
i->w = bar_height; i->w = icon_height;
else if (h == bar_height) else if (h == icon_height)
i->w = w; i->w = w;
else else
i->w = (int) ((float)bar_height * ((float)w / (float)h)); i->w = (int) ((float)icon_height * ((float)w / (float)h));
applysizehints(i, &(i->x), &(i->y), &(i->w), &(i->h), False); applysizehints(i, &(i->x), &(i->y), &(i->w), &(i->h), False);
/* force icons into the systray dimensions if they don't want to */ /* force icons into the systray dimensions if they don't want to */
if (i->h > bar_height) { if (i->h > icon_height) {
if (i->w == i->h) if (i->w == i->h)
i->w = bar_height; i->w = icon_height;
else else
i->w = (int) ((float)bar_height * ((float)i->w / (float)i->h)); i->w = (int) ((float)icon_height * ((float)i->w / (float)i->h));
i->h = bar_height; i->h = icon_height;
} }
if (i->w > 2 * bar_height) if (i->w > 2 * icon_height)
i->w = bar_height; i->w = icon_height;
} }
} }

View File

@ -23,6 +23,7 @@ struct Systray {
Window win; Window win;
Client *icons; Client *icons;
Bar *bar; Bar *bar;
int h;
}; };
/* bar integration */ /* bar integration */