From 5edf4bab172157288985c483009f846cc8b15478 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Sat, 24 Oct 2020 10:01:19 +0200 Subject: [PATCH] Proposed changes to ensure that systray icons are sized according to font size rather than bar height, ref. #62 --- patch/bar_systray.c | 29 +++++++++++++++-------------- patch/bar_systray.h | 1 + 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/patch/bar_systray.c b/patch/bar_systray.c index d3df37c..4ff7fd9 100644 --- a/patch/bar_systray.c +++ b/patch/bar_systray.c @@ -31,15 +31,16 @@ draw_systray(Bar *bar, BarArg *a) wa.override_redirect = True; wa.event_mask = ButtonPressMask|ExposureMask; wa.border_pixel = 0; + systray->h = MIN(a->h, drw->fonts->h); #if BAR_ALPHA_PATCH wa.background_pixel = 0; 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, CWOverrideRedirect|CWBorderPixel|CWBackPixel|CWColormap|CWEventMask, &wa); // CWBackPixmap #else 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); #endif // BAR_ALPHA_PATCH @@ -85,7 +86,7 @@ draw_systray(Bar *bar, BarArg *a) 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; } @@ -127,26 +128,26 @@ updatesystrayicongeom(Client *i, int w, int h) if (!systray) return; - int bar_height = systray->bar->bh - 2 * systray->bar->borderpx; + int icon_height = systray->h; if (i) { - i->h = bar_height; + i->h = icon_height; if (w == h) - i->w = bar_height; - else if (h == bar_height) + i->w = icon_height; + else if (h == icon_height) i->w = w; 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); /* 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) - i->w = bar_height; + i->w = icon_height; else - i->w = (int) ((float)bar_height * ((float)i->w / (float)i->h)); - i->h = bar_height; + i->w = (int) ((float)icon_height * ((float)i->w / (float)i->h)); + i->h = icon_height; } - if (i->w > 2 * bar_height) - i->w = bar_height; + if (i->w > 2 * icon_height) + i->w = icon_height; } } diff --git a/patch/bar_systray.h b/patch/bar_systray.h index 5a107f2..851b3ec 100644 --- a/patch/bar_systray.h +++ b/patch/bar_systray.h @@ -23,6 +23,7 @@ struct Systray { Window win; Client *icons; Bar *bar; + int h; }; /* bar integration */