mirror of
https://github.com/mintycube/dwm.git
synced 2024-10-22 14:05:45 +02:00
Upgrading winicon patch to v2.1 ref. #238
This commit is contained in:
parent
5c321794f1
commit
adc05c2332
@ -28,7 +28,7 @@ FREETYPEINC = /usr/include/freetype2
|
|||||||
# OpenBSD - Uncomment this for the swallow patch / SWALLOW_PATCH
|
# OpenBSD - Uncomment this for the swallow patch / SWALLOW_PATCH
|
||||||
#KVMLIB = -lkvm
|
#KVMLIB = -lkvm
|
||||||
|
|
||||||
# Uncomment this for the alpha patch / BAR_ALPHA_PATCH
|
# Uncomment this for the alpha patch and the winicon patch (BAR_ALPHA_PATCH, BAR_WINICON_PATCH)
|
||||||
#XRENDER = -lXrender
|
#XRENDER = -lXrender
|
||||||
|
|
||||||
# Uncomment this for the mdpcontrol patch / MDPCONTROL_PATCH
|
# Uncomment this for the mdpcontrol patch / MDPCONTROL_PATCH
|
||||||
|
21
drw.c
21
drw.c
@ -89,9 +89,15 @@ drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h
|
|||||||
drw->depth = depth;
|
drw->depth = depth;
|
||||||
drw->cmap = cmap;
|
drw->cmap = cmap;
|
||||||
drw->drawable = XCreatePixmap(dpy, root, w, h, depth);
|
drw->drawable = XCreatePixmap(dpy, root, w, h, depth);
|
||||||
|
#if BAR_WINICON_PATCH
|
||||||
|
drw->picture = XRenderCreatePicture(dpy, drw->drawable, XRenderFindVisualFormat(dpy, visual), 0, NULL);
|
||||||
|
#endif // BAR_WINICON_PATCH
|
||||||
drw->gc = XCreateGC(dpy, drw->drawable, 0, NULL);
|
drw->gc = XCreateGC(dpy, drw->drawable, 0, NULL);
|
||||||
#else
|
#else
|
||||||
drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen));
|
drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen));
|
||||||
|
#if BAR_WINICON_PATCH
|
||||||
|
drw->picture = XRenderCreatePicture(dpy, drw->drawable, XRenderFindVisualFormat(dpy, DefaultVisual(dpy, screen)), 0, NULL);
|
||||||
|
#endif // BAR_WINICON_PATCH
|
||||||
drw->gc = XCreateGC(dpy, root, 0, NULL);
|
drw->gc = XCreateGC(dpy, root, 0, NULL);
|
||||||
#endif // BAR_ALPHA_PATCH
|
#endif // BAR_ALPHA_PATCH
|
||||||
XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter);
|
XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter);
|
||||||
@ -107,18 +113,31 @@ drw_resize(Drw *drw, unsigned int w, unsigned int h)
|
|||||||
|
|
||||||
drw->w = w;
|
drw->w = w;
|
||||||
drw->h = h;
|
drw->h = h;
|
||||||
|
#if BAR_WINICON_PATCH
|
||||||
|
if (drw->picture)
|
||||||
|
XRenderFreePicture(drw->dpy, drw->picture);
|
||||||
|
#endif // BAR_WINICON_PATCH
|
||||||
if (drw->drawable)
|
if (drw->drawable)
|
||||||
XFreePixmap(drw->dpy, drw->drawable);
|
XFreePixmap(drw->dpy, drw->drawable);
|
||||||
#if BAR_ALPHA_PATCH
|
#if BAR_ALPHA_PATCH
|
||||||
drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, drw->depth);
|
drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, drw->depth);
|
||||||
#else
|
#if BAR_WINICON_PATCH
|
||||||
|
drw->picture = XRenderCreatePicture(drw->dpy, drw->drawable, XRenderFindVisualFormat(drw->dpy, drw->visual), 0, NULL);
|
||||||
|
#endif // BAR_WINICON_PATCH
|
||||||
|
#else // !BAR_ALPHA_PATCH
|
||||||
drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen));
|
drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen));
|
||||||
|
#if BAR_WINICON_PATCH
|
||||||
|
drw->picture = XRenderCreatePicture(drw->dpy, drw->drawable, XRenderFindVisualFormat(drw->dpy, DefaultVisual(drw->dpy, drw->screen)), 0, NULL);
|
||||||
|
#endif // BAR_WINICON_PATCH
|
||||||
#endif // BAR_ALPHA_PATCH
|
#endif // BAR_ALPHA_PATCH
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
drw_free(Drw *drw)
|
drw_free(Drw *drw)
|
||||||
{
|
{
|
||||||
|
#if BAR_WINICON_PATCH
|
||||||
|
XRenderFreePicture(drw->dpy, drw->picture);
|
||||||
|
#endif // BAR_WINICON_PATCH
|
||||||
XFreePixmap(drw->dpy, drw->drawable);
|
XFreePixmap(drw->dpy, drw->drawable);
|
||||||
XFreeGC(drw->dpy, drw->gc);
|
XFreeGC(drw->dpy, drw->gc);
|
||||||
drw_fontset_free(drw->fonts);
|
drw_fontset_free(drw->fonts);
|
||||||
|
3
drw.h
3
drw.h
@ -35,6 +35,9 @@ typedef struct {
|
|||||||
Colormap cmap;
|
Colormap cmap;
|
||||||
#endif // BAR_ALPHA_PATCH
|
#endif // BAR_ALPHA_PATCH
|
||||||
Drawable drawable;
|
Drawable drawable;
|
||||||
|
#if BAR_WINICON_PATCH
|
||||||
|
Picture picture;
|
||||||
|
#endif // BAR_WINICON_PATCH
|
||||||
GC gc;
|
GC gc;
|
||||||
Clr *scheme;
|
Clr *scheme;
|
||||||
Fnt *fonts;
|
Fnt *fonts;
|
||||||
|
4
dwm.c
4
dwm.c
@ -395,7 +395,8 @@ struct Client {
|
|||||||
XkbInfo *xkb;
|
XkbInfo *xkb;
|
||||||
#endif // XKB_PATCH
|
#endif // XKB_PATCH
|
||||||
#if BAR_WINICON_PATCH
|
#if BAR_WINICON_PATCH
|
||||||
XImage *icon;
|
unsigned int icw, ich;
|
||||||
|
Picture icon;
|
||||||
#endif // BAR_WINICON_PATCH
|
#endif // BAR_WINICON_PATCH
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2324,7 +2325,6 @@ manage(Window w, XWindowAttributes *wa)
|
|||||||
c->cfact = 1.0;
|
c->cfact = 1.0;
|
||||||
#endif // CFACTS_PATCH
|
#endif // CFACTS_PATCH
|
||||||
#if BAR_WINICON_PATCH
|
#if BAR_WINICON_PATCH
|
||||||
c->icon = NULL;
|
|
||||||
updateicon(c);
|
updateicon(c);
|
||||||
#endif // BAR_WINICON_PATCH
|
#endif // BAR_WINICON_PATCH
|
||||||
updatetitle(c);
|
updatetitle(c);
|
||||||
|
@ -50,7 +50,7 @@ draw_awesomebar(Bar *bar, BarArg *a)
|
|||||||
cpad = 0;
|
cpad = 0;
|
||||||
#endif // BAR_CENTEREDWINDOWNAME_PATCH
|
#endif // BAR_CENTEREDWINDOWNAME_PATCH
|
||||||
#if BAR_WINICON_PATCH
|
#if BAR_WINICON_PATCH
|
||||||
ipad = c->icon ? c->icon->width + ICONSPACING : 0;
|
ipad = c->icon ? c->icw + ICONSPACING : 0;
|
||||||
#endif // BAR_WINICON_PATCH
|
#endif // BAR_WINICON_PATCH
|
||||||
|
|
||||||
tx = x;
|
tx = x;
|
||||||
@ -80,7 +80,7 @@ draw_awesomebar(Bar *bar, BarArg *a)
|
|||||||
|
|
||||||
#if BAR_WINICON_PATCH
|
#if BAR_WINICON_PATCH
|
||||||
if (ipad) {
|
if (ipad) {
|
||||||
drw_img(drw, tx, a->y + (a->h - c->icon->height) / 2, c->icon, tmpicon);
|
drw_pic(drw, tx, a->y + (a->h - c->ich) / 2, c->icw, c->ich, c->icon);
|
||||||
tx += ipad;
|
tx += ipad;
|
||||||
tw -= ipad;
|
tw -= ipad;
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ draw_fancybar(Bar *bar, BarArg *a)
|
|||||||
tabw = TEXTW(m->sel->name);
|
tabw = TEXTW(m->sel->name);
|
||||||
#if BAR_WINICON_PATCH
|
#if BAR_WINICON_PATCH
|
||||||
if (m->sel->icon)
|
if (m->sel->icon)
|
||||||
tabw += m->sel->icon->width + ICONSPACING;
|
tabw += m->sel->icw + ICONSPACING;
|
||||||
#endif // BAR_WINICON_PATCH
|
#endif // BAR_WINICON_PATCH
|
||||||
mw = (tabw >= w || n == 1) ? 0 : (w - tabw) / (n - 1);
|
mw = (tabw >= w || n == 1) ? 0 : (w - tabw) / (n - 1);
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ draw_fancybar(Bar *bar, BarArg *a)
|
|||||||
tabw = TEXTW(c->name);
|
tabw = TEXTW(c->name);
|
||||||
#if BAR_WINICON_PATCH
|
#if BAR_WINICON_PATCH
|
||||||
if (c->icon)
|
if (c->icon)
|
||||||
tabw += c->icon->width + ICONSPACING;
|
tabw += c->icw + ICONSPACING;
|
||||||
#endif // BAR_WINICON_PATCH
|
#endif // BAR_WINICON_PATCH
|
||||||
if (tabw < mw)
|
if (tabw < mw)
|
||||||
ew += (mw - tabw);
|
ew += (mw - tabw);
|
||||||
@ -62,7 +62,7 @@ draw_fancybar(Bar *bar, BarArg *a)
|
|||||||
continue;
|
continue;
|
||||||
tabw = MIN(m->sel == c ? w : mw, TEXTW(c->name));
|
tabw = MIN(m->sel == c ? w : mw, TEXTW(c->name));
|
||||||
#if BAR_WINICON_PATCH
|
#if BAR_WINICON_PATCH
|
||||||
ipad = c->icon ? c->icon->width + ICONSPACING : 0;
|
ipad = c->icon ? c->icw + ICONSPACING : 0;
|
||||||
tabw += ipad;
|
tabw += ipad;
|
||||||
#endif // BAR_WINICON_PATCH
|
#endif // BAR_WINICON_PATCH
|
||||||
tx = x;
|
tx = x;
|
||||||
@ -80,7 +80,7 @@ draw_fancybar(Bar *bar, BarArg *a)
|
|||||||
|
|
||||||
#if BAR_WINICON_PATCH
|
#if BAR_WINICON_PATCH
|
||||||
if (ipad) {
|
if (ipad) {
|
||||||
drw_img(drw, tx, a->y + (a->h - c->icon->height) / 2, c->icon, tmpicon);
|
drw_pic(drw, tx, a->y + (a->h - c->ich) / 2, c->icw, c->ich, c->icon);
|
||||||
tx += ipad;
|
tx += ipad;
|
||||||
tw -= ipad;
|
tw -= ipad;
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ flextitledraw(Monitor *m, Client *c, int unused, int x, int w, int tabscheme, Ar
|
|||||||
int i, nclienttags = 0, nviewtags = 0;
|
int i, nclienttags = 0, nviewtags = 0;
|
||||||
int tpad = lrpad / 2;
|
int tpad = lrpad / 2;
|
||||||
#if BAR_WINICON_PATCH
|
#if BAR_WINICON_PATCH
|
||||||
int ipad = c->icon ? c->icon->width + ICONSPACING : 0;
|
int ipad = c->icon ? c->icw + ICONSPACING : 0;
|
||||||
#endif // BAR_WINICON_PATCH
|
#endif // BAR_WINICON_PATCH
|
||||||
#if BAR_CENTEREDWINDOWNAME_PATCH
|
#if BAR_CENTEREDWINDOWNAME_PATCH
|
||||||
int cpad = 0;
|
int cpad = 0;
|
||||||
@ -220,7 +220,7 @@ flextitledraw(Monitor *m, Client *c, int unused, int x, int w, int tabscheme, Ar
|
|||||||
|
|
||||||
#if BAR_WINICON_PATCH
|
#if BAR_WINICON_PATCH
|
||||||
if (ipad) {
|
if (ipad) {
|
||||||
drw_img(drw, tx, a->y + (a->h - c->icon->height) / 2, c->icon, tmpicon);
|
drw_pic(drw, tx, a->y + (a->h - c->ich) / 2, c->icw, c->ich, c->icon);
|
||||||
tx += ipad;
|
tx += ipad;
|
||||||
tw -= ipad;
|
tw -= ipad;
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ bartabdraw(Monitor *m, Client *c, int unused, int x, int w, int groupactive, Arg
|
|||||||
int i, nclienttags = 0, nviewtags = 0;
|
int i, nclienttags = 0, nviewtags = 0;
|
||||||
int tpad = lrpad / 2;
|
int tpad = lrpad / 2;
|
||||||
#if BAR_WINICON_PATCH
|
#if BAR_WINICON_PATCH
|
||||||
int ipad = c->icon ? c->icon->width + ICONSPACING : 0;
|
int ipad = c->icon ? c->icw + ICONSPACING : 0;
|
||||||
#endif // BAR_WINICON_PATCH
|
#endif // BAR_WINICON_PATCH
|
||||||
#if BAR_CENTEREDWINDOWNAME_PATCH
|
#if BAR_CENTEREDWINDOWNAME_PATCH
|
||||||
int cpad = 0;
|
int cpad = 0;
|
||||||
@ -89,7 +89,7 @@ bartabdraw(Monitor *m, Client *c, int unused, int x, int w, int groupactive, Arg
|
|||||||
|
|
||||||
#if BAR_WINICON_PATCH
|
#if BAR_WINICON_PATCH
|
||||||
if (ipad) {
|
if (ipad) {
|
||||||
drw_img(drw, tx, a->y + (a->h - c->icon->height) / 2, c->icon, tmpicon);
|
drw_pic(drw, tx, a->y + (a->h - c->ich) / 2, c->icw, c->ich, c->icon);
|
||||||
tx += ipad;
|
tx += ipad;
|
||||||
tw -= ipad;
|
tw -= ipad;
|
||||||
}
|
}
|
||||||
|
@ -1,60 +1,12 @@
|
|||||||
static uint32_t tmpicon[ICONSIZE * ICONSIZE];
|
|
||||||
|
|
||||||
static uint32_t prealpha(uint32_t p) {
|
static uint32_t prealpha(uint32_t p) {
|
||||||
uint8_t a = p >> 24u;
|
uint8_t a = p >> 24u;
|
||||||
uint32_t rb = (a * (p & 0xFF00FFu)) >> 8u;
|
uint32_t rb = (a * (p & 0xFF00FFu)) >> 8u;
|
||||||
uint32_t g = (a * (p & 0x00FF00u)) >> 8u;
|
uint32_t g = (a * (p & 0x00FF00u)) >> 8u;
|
||||||
return (rb & 0xFF00FFu) | (g & 0x00FF00u) | ((~a) << 24u);
|
return (rb & 0xFF00FFu) | (g & 0x00FF00u) | (a << 24u);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if BAR_ALPHA_PATCH
|
Picture
|
||||||
static uint8_t div255(uint16_t x) { return (x*0x8081u) >> 23u; }
|
geticonprop(Window win, unsigned int *picw, unsigned int *pich)
|
||||||
static uint32_t blend(uint32_t p1rb, uint32_t p1g, uint8_t p1a, uint32_t p2) {
|
|
||||||
uint8_t a = p2 >> 24u;
|
|
||||||
uint32_t rb = (p2 & 0xFF00FFu) + ( (a * p1rb) >> 8u );
|
|
||||||
uint32_t g = (p2 & 0x00FF00u) + ( (a * p1g) >> 8u );
|
|
||||||
return (rb & 0xFF00FFu) | (g & 0x00FF00u) | div255(~a * 255u + a * p1a) << 24u;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
drw_img(Drw *drw, int x, int y, XImage *img, uint32_t *tmp)
|
|
||||||
{
|
|
||||||
if (!drw || !drw->scheme)
|
|
||||||
return;
|
|
||||||
uint32_t *data = (uint32_t *)img->data, p = drw->scheme[ColBg].pixel,
|
|
||||||
prb = p & 0xFF00FFu, pg = p & 0x00FF00u;
|
|
||||||
uint8_t pa = p >> 24u;
|
|
||||||
int icsz = img->width * img->height, i;
|
|
||||||
for (i = 0; i < icsz; ++i) tmp[i] = blend(prb, pg, pa, data[i]);
|
|
||||||
|
|
||||||
img->data = (char *) tmp;
|
|
||||||
XPutImage(drw->dpy, drw->drawable, drw->gc, img, 0, 0, x, y, img->width, img->height);
|
|
||||||
img->data = (char *) data;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
static uint32_t blend(uint32_t p1rb, uint32_t p1g, uint32_t p2) {
|
|
||||||
uint8_t a = p2 >> 24u;
|
|
||||||
uint32_t rb = (p2 & 0xFF00FFu) + ( (a * p1rb) >> 8u );
|
|
||||||
uint32_t g = (p2 & 0x00FF00u) + ( (a * p1g) >> 8u );
|
|
||||||
return (rb & 0xFF00FFu) | (g & 0x00FF00u) | ((~a) << 24u);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
drw_img(Drw *drw, int x, int y, XImage *img, uint32_t *tmp)
|
|
||||||
{
|
|
||||||
if (!drw || !drw->scheme)
|
|
||||||
return;
|
|
||||||
uint32_t *data = (uint32_t *)img->data, p = drw->scheme[ColBg].pixel, prb = p & 0xFF00FFu, pg = p & 0x00FF00u;
|
|
||||||
int icsz = img->width * img->height, i;
|
|
||||||
for (i = 0; i < icsz; ++i) tmp[i] = blend(prb, pg, data[i]);
|
|
||||||
img->data = (char *) tmp;
|
|
||||||
XPutImage(drw->dpy, drw->drawable, drw->gc, img, 0, 0, x, y, img->width, img->height);
|
|
||||||
img->data = (char *) data;
|
|
||||||
}
|
|
||||||
#endif // BAR_ALPHA_PATCH
|
|
||||||
|
|
||||||
XImage *
|
|
||||||
geticonprop(Window win)
|
|
||||||
{
|
{
|
||||||
int format;
|
int format;
|
||||||
unsigned long n, extra, *p = NULL;
|
unsigned long n, extra, *p = NULL;
|
||||||
@ -62,34 +14,32 @@ geticonprop(Window win)
|
|||||||
|
|
||||||
if (XGetWindowProperty(dpy, win, netatom[NetWMIcon], 0L, LONG_MAX, False, AnyPropertyType,
|
if (XGetWindowProperty(dpy, win, netatom[NetWMIcon], 0L, LONG_MAX, False, AnyPropertyType,
|
||||||
&real, &format, &n, &extra, (unsigned char **)&p) != Success)
|
&real, &format, &n, &extra, (unsigned char **)&p) != Success)
|
||||||
return NULL;
|
return None;
|
||||||
if (n == 0 || format != 32) { XFree(p); return NULL; }
|
if (n == 0 || format != 32) { XFree(p); return None; }
|
||||||
|
|
||||||
unsigned long *bstp = NULL;
|
unsigned long *bstp = NULL;
|
||||||
uint32_t w, h, sz;
|
uint32_t w, h, sz;
|
||||||
|
|
||||||
{
|
{
|
||||||
const unsigned long *end = p + n;
|
unsigned long *i; const unsigned long *end = p + n;
|
||||||
unsigned long *i;
|
|
||||||
uint32_t bstd = UINT32_MAX, d, m;
|
uint32_t bstd = UINT32_MAX, d, m;
|
||||||
for (i = p; i < end - 1; i += sz) {
|
for (i = p; i < end - 1; i += sz) {
|
||||||
if ((w = *i++) >= 16384 || (h = *i++) >= 16384) { XFree(p); return NULL; }
|
if ((w = *i++) >= 16384 || (h = *i++) >= 16384) { XFree(p); return None; }
|
||||||
if ((sz = w * h) > end - i) break;
|
if ((sz = w * h) > end - i) break;
|
||||||
if ((m = w > h ? w : h) >= ICONSIZE && (d = m - ICONSIZE) < bstd) { bstd = d; bstp = i; }
|
if ((m = w > h ? w : h) >= ICONSIZE && (d = m - ICONSIZE) < bstd) { bstd = d; bstp = i; }
|
||||||
}
|
}
|
||||||
if (!bstp) {
|
if (!bstp) {
|
||||||
for (i = p; i < end - 1; i += sz) {
|
for (i = p; i < end - 1; i += sz) {
|
||||||
if ((w = *i++) >= 16384 || (h = *i++) >= 16384) { XFree(p); return NULL; }
|
if ((w = *i++) >= 16384 || (h = *i++) >= 16384) { XFree(p); return None; }
|
||||||
if ((sz = w * h) > end - i) break;
|
if ((sz = w * h) > end - i) break;
|
||||||
if ((d = ICONSIZE - (w > h ? w : h)) < bstd) { bstd = d; bstp = i; }
|
if ((d = ICONSIZE - (w > h ? w : h)) < bstd) { bstd = d; bstp = i; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!bstp) { XFree(p); return NULL; }
|
if (!bstp) { XFree(p); return None; }
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((w = *(bstp - 2)) == 0 || (h = *(bstp - 1)) == 0) { XFree(p); return NULL; }
|
if ((w = *(bstp - 2)) == 0 || (h = *(bstp - 1)) == 0) { XFree(p); return None; }
|
||||||
|
|
||||||
uint32_t icw, ich, icsz;
|
uint32_t icw, ich;
|
||||||
if (w <= h) {
|
if (w <= h) {
|
||||||
ich = ICONSIZE; icw = w * ICONSIZE / h;
|
ich = ICONSIZE; icw = w * ICONSIZE / h;
|
||||||
if (icw == 0) icw = 1;
|
if (icw == 0) icw = 1;
|
||||||
@ -98,43 +48,92 @@ geticonprop(Window win)
|
|||||||
icw = ICONSIZE; ich = h * ICONSIZE / w;
|
icw = ICONSIZE; ich = h * ICONSIZE / w;
|
||||||
if (ich == 0) ich = 1;
|
if (ich == 0) ich = 1;
|
||||||
}
|
}
|
||||||
icsz = icw * ich;
|
*picw = icw; *pich = ich;
|
||||||
|
|
||||||
uint32_t i;
|
uint32_t i, *bstp32 = (uint32_t *)bstp;
|
||||||
#if ULONG_MAX > UINT32_MAX
|
for (sz = w * h, i = 0; i < sz; ++i) bstp32[i] = prealpha(bstp[i]);
|
||||||
uint32_t *bstp32 = (uint32_t *)bstp;
|
|
||||||
for (sz = w * h, i = 0; i < sz; ++i) bstp32[i] = bstp[i];
|
Picture ret = drw_picture_create_resized(drw, (char *)bstp, w, h, icw, ich);
|
||||||
#endif
|
XFree(p);
|
||||||
uint32_t *icbuf = malloc(icsz << 2); if(!icbuf) { XFree(p); return NULL; }
|
|
||||||
if (w == icw && h == ich) memcpy(icbuf, bstp, icsz << 2);
|
return ret;
|
||||||
else {
|
}
|
||||||
Imlib_Image origin = imlib_create_image_using_data(w, h, (DATA32 *)bstp);
|
|
||||||
if (!origin) { XFree(p); free(icbuf); return NULL; }
|
Picture
|
||||||
|
drw_picture_create_resized(Drw *drw, char *src, unsigned int srcw, unsigned int srch, unsigned int dstw, unsigned int dsth) {
|
||||||
|
Pixmap pm;
|
||||||
|
Picture pic;
|
||||||
|
GC gc;
|
||||||
|
|
||||||
|
if (srcw <= (dstw << 1u) && srch <= (dsth << 1u)) {
|
||||||
|
XImage img = {
|
||||||
|
srcw, srch, 0, ZPixmap, src,
|
||||||
|
ImageByteOrder(drw->dpy), BitmapUnit(drw->dpy), BitmapBitOrder(drw->dpy), 32,
|
||||||
|
32, 0, 32,
|
||||||
|
0, 0, 0
|
||||||
|
};
|
||||||
|
XInitImage(&img);
|
||||||
|
|
||||||
|
pm = XCreatePixmap(drw->dpy, drw->root, srcw, srch, 32);
|
||||||
|
gc = XCreateGC(drw->dpy, pm, 0, NULL);
|
||||||
|
XPutImage(drw->dpy, pm, gc, &img, 0, 0, 0, 0, srcw, srch);
|
||||||
|
XFreeGC(drw->dpy, gc);
|
||||||
|
|
||||||
|
pic = XRenderCreatePicture(drw->dpy, pm, XRenderFindStandardFormat(drw->dpy, PictStandardARGB32), 0, NULL);
|
||||||
|
XFreePixmap(drw->dpy, pm);
|
||||||
|
|
||||||
|
XRenderSetPictureFilter(drw->dpy, pic, FilterBilinear, NULL, 0);
|
||||||
|
XTransform xf;
|
||||||
|
xf.matrix[0][0] = (srcw << 16u) / dstw; xf.matrix[0][1] = 0; xf.matrix[0][2] = 0;
|
||||||
|
xf.matrix[1][0] = 0; xf.matrix[1][1] = (srch << 16u) / dsth; xf.matrix[1][2] = 0;
|
||||||
|
xf.matrix[2][0] = 0; xf.matrix[2][1] = 0; xf.matrix[2][2] = 65536;
|
||||||
|
XRenderSetPictureTransform(drw->dpy, pic, &xf);
|
||||||
|
} else {
|
||||||
|
Imlib_Image origin = imlib_create_image_using_data(srcw, srch, (DATA32 *)src);
|
||||||
|
if (!origin) return None;
|
||||||
imlib_context_set_image(origin);
|
imlib_context_set_image(origin);
|
||||||
imlib_image_set_has_alpha(1);
|
imlib_image_set_has_alpha(1);
|
||||||
Imlib_Image scaled = imlib_create_cropped_scaled_image(0, 0, w, h, icw, ich);
|
Imlib_Image scaled = imlib_create_cropped_scaled_image(0, 0, srcw, srch, dstw, dsth);
|
||||||
imlib_free_image_and_decache();
|
imlib_free_image_and_decache();
|
||||||
if (!scaled) { XFree(p); free(icbuf); return NULL; }
|
if (!scaled) return None;
|
||||||
imlib_context_set_image(scaled);
|
imlib_context_set_image(scaled);
|
||||||
imlib_image_set_has_alpha(1);
|
imlib_image_set_has_alpha(1);
|
||||||
memcpy(icbuf, imlib_image_get_data_for_reading_only(), icsz << 2);
|
|
||||||
|
XImage img = {
|
||||||
|
dstw, dsth, 0, ZPixmap, (char *)imlib_image_get_data_for_reading_only(),
|
||||||
|
ImageByteOrder(drw->dpy), BitmapUnit(drw->dpy), BitmapBitOrder(drw->dpy), 32,
|
||||||
|
32, 0, 32,
|
||||||
|
0, 0, 0
|
||||||
|
};
|
||||||
|
XInitImage(&img);
|
||||||
|
|
||||||
|
pm = XCreatePixmap(drw->dpy, drw->root, dstw, dsth, 32);
|
||||||
|
gc = XCreateGC(drw->dpy, pm, 0, NULL);
|
||||||
|
XPutImage(drw->dpy, pm, gc, &img, 0, 0, 0, 0, dstw, dsth);
|
||||||
imlib_free_image_and_decache();
|
imlib_free_image_and_decache();
|
||||||
|
XFreeGC(drw->dpy, gc);
|
||||||
|
|
||||||
|
pic = XRenderCreatePicture(drw->dpy, pm, XRenderFindStandardFormat(drw->dpy, PictStandardARGB32), 0, NULL);
|
||||||
|
XFreePixmap(drw->dpy, pm);
|
||||||
}
|
}
|
||||||
XFree(p);
|
|
||||||
for (i = 0; i < icsz; ++i) icbuf[i] = prealpha(icbuf[i]);
|
return pic;
|
||||||
#if BAR_ALPHA_PATCH
|
}
|
||||||
return XCreateImage(dpy, drw->visual, drw->depth, ZPixmap, 0, (char *)icbuf, icw, ich, 32, 0);
|
|
||||||
#else
|
void
|
||||||
return XCreateImage(dpy, DefaultVisual(dpy, screen), DefaultDepth(dpy, screen), ZPixmap, 0, (char *)icbuf, icw, ich, 32, 0);
|
drw_pic(Drw *drw, int x, int y, unsigned int w, unsigned int h, Picture pic)
|
||||||
#endif // BAR_ALPHA_PATCH
|
{
|
||||||
|
if (!drw)
|
||||||
|
return;
|
||||||
|
XRenderComposite(drw->dpy, PictOpOver, pic, None, drw->picture, 0, 0, 0, 0, x, y, w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
freeicon(Client *c)
|
freeicon(Client *c)
|
||||||
{
|
{
|
||||||
if (c->icon) {
|
if (c->icon) {
|
||||||
XDestroyImage(c->icon);
|
XRenderFreePicture(dpy, c->icon);
|
||||||
c->icon = NULL;
|
c->icon = None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,5 +141,5 @@ void
|
|||||||
updateicon(Client *c)
|
updateicon(Client *c)
|
||||||
{
|
{
|
||||||
freeicon(c);
|
freeicon(c);
|
||||||
c->icon = geticonprop(c->win);
|
c->icon = geticonprop(c->win, &c->icw, &c->ich);
|
||||||
}
|
}
|
@ -2,7 +2,8 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
void drw_img(Drw *drw, int x, int y, XImage *img, uint32_t *tmp);
|
static Picture drw_picture_create_resized(Drw *drw, char *src, unsigned int src_w, unsigned int src_h, unsigned int dst_w, unsigned int dst_h);
|
||||||
static XImage *geticonprop(Window win);
|
static void drw_pic(Drw *drw, int x, int y, unsigned int w, unsigned int h, Picture pic);
|
||||||
|
static Picture geticonprop(Window w, unsigned int *icw, unsigned int *ich);
|
||||||
static void freeicon(Client *c);
|
static void freeicon(Client *c);
|
||||||
static void updateicon(Client *c);
|
static void updateicon(Client *c);
|
@ -27,7 +27,7 @@ draw_wintitle(Bar *bar, BarArg *a)
|
|||||||
|
|
||||||
int tpad = lrpad / 2;
|
int tpad = lrpad / 2;
|
||||||
#if BAR_WINICON_PATCH
|
#if BAR_WINICON_PATCH
|
||||||
int ipad = c->icon ? c->icon->width + ICONSPACING : 0;
|
int ipad = c->icon ? c->icw + ICONSPACING : 0;
|
||||||
#endif // BAR_WINICON_PATCH
|
#endif // BAR_WINICON_PATCH
|
||||||
#if BAR_CENTEREDWINDOWNAME_PATCH
|
#if BAR_CENTEREDWINDOWNAME_PATCH
|
||||||
int cpad = 0;
|
int cpad = 0;
|
||||||
@ -64,7 +64,7 @@ draw_wintitle(Bar *bar, BarArg *a)
|
|||||||
|
|
||||||
#if BAR_WINICON_PATCH
|
#if BAR_WINICON_PATCH
|
||||||
if (ipad) {
|
if (ipad) {
|
||||||
drw_img(drw, tx, a->y + (a->h - c->icon->height) / 2, c->icon, tmpicon);
|
drw_pic(drw, tx, a->y + (a->h - c->ich) / 2, c->icw, c->ich, c->icon);
|
||||||
tx += ipad;
|
tx += ipad;
|
||||||
tw -= ipad;
|
tw -= ipad;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user