Comments (13)
Oh, you might forget to cancel the comment on the memcpy(icbuf, imlib_image_... line. That's where the image data is generated, or the image buffer will remains random
from dwm-winicon.
Also try this new version of the geticonprop function, which can avoid crashing when receiving false data.
#define MAXICONAXIS 0xffffu
XImage *
geticonprop(Window win)
{
int format;
unsigned long n, extra, *p = NULL;
Atom real;
if (XGetWindowProperty(dpy, win, netatom[NetWMIcon], 0L, LONG_MAX, False, AnyPropertyType,
&real, &format, &n, &extra, (unsigned char **)&p) != Success)
return NULL;
if (n == 0 || format != 32) { XFree(p); return NULL; }
unsigned long *bstp = NULL, w, h, sz;
{
const unsigned long *end = p + n;
unsigned long *i;
int bstd = INT_MAX, d, m;
for (i = p; i + 1 < end; ) {
if ((w = *i++) > MAXICONAXIS || (h = *i++) > MAXICONAXIS) break;
m = w > h ? w : h; sz = w * h;
if ((i += sz) <= end && m >= ICONSIZE && (d = m - ICONSIZE) < bstd) { bstd = d; bstp = i - sz; }
}
if (!bstp) {
for (i = p; i + 1 < end; ) {
if ((w = *i++) > MAXICONAXIS || (h = *i++) > MAXICONAXIS) break;
m = w > h ? w : h; sz = w * h;
if ((i += sz) <= end && (d = ICONSIZE - m) < bstd) { bstd = d; bstp = i - sz; }
}
}
if (!bstp) { XFree(p); return NULL; }
}
w = *(bstp - 2); h = *(bstp - 1);
int icw, ich, icsz;
if (w <= h) {
ich = ICONSIZE; icw = w * ICONSIZE / h;
if (icw < 1) icw = 1;
}
else {
icw = ICONSIZE; ich = h * ICONSIZE / w;
if (ich < 1) ich = 1;
}
icsz = icw * ich;
int i;
#if ULONG_MAX > UINT32_MAX
uint32_t *bstp32 = (uint32_t *)bstp;
for (sz = w * h, i = 0; i < sz; ++i) bstp32[i] = bstp[i];
#endif
uint32_t *icbuf = malloc(icsz << 2); if(!icbuf) { XFree(p); return NULL; }
if (w == icw && h == ich) memcpy(icbuf, bstp, icsz << 2);
else {
Imlib_Image origin = imlib_create_image_using_data(w, h, (DATA32 *)bstp);
if (!origin) { XFree(p); free(icbuf); return NULL; }
imlib_context_set_image(origin);
imlib_image_set_has_alpha(1);
Imlib_Image scaled = imlib_create_cropped_scaled_image(0, 0, w, h, icw, ich);
imlib_free_image_and_decache();
if (!scaled) { XFree(p); free(icbuf); return NULL; }
imlib_context_set_image(scaled);
imlib_image_set_has_alpha(1);
memcpy(icbuf, imlib_image_get_data_for_reading_only(), icsz << 2);
imlib_free_image_and_decache();
}
XFree(p);
for (i = 0; i < icsz; ++i) icbuf[i] = prealpha(icbuf[i]);
return XCreateImage(drw->dpy, drw->visual, drw->depth, ZPixmap, 0, (char *)icbuf, icw, ich, 32, 0);
}
from dwm-winicon.
You mean making dwm bar transparent while keeping the icons opaque ?
from dwm-winicon.
Yes, using this patch makes the bar transparent.
pd: the littke i know is that the rectangle that XCreateImage, correctly poiting to visual and depth made by xinitvisual(), seems to be always transparent. On the alpha array i put everything to 255 or 0xffU but still the icon has transparency. I also suspect this could be from imlib_image_set_alpha() which causes a doble layer or something?..
from dwm-winicon.
@explosion-mental
after applying both patches
- change the last return statement in geticonprop function (dwm.c) to
return XCreateImage(drw->dpy, drw->visual, drw->depth, ZPixmap, 0, (char *)icbuf, icw, ich, 32, 0);
- change drw_img and blend function (drw.c) to
inline 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) | ((~a * 255u + a * p1a) / 255u) << 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;
}
from dwm-winicon.
These modifications seem to work :D (at least on my laptop), adding the additional blend on alpha channel. This won't be a big deal if enabling -march=native and -O3, which automatically optimize it to use SIMD
from dwm-winicon.
some further optimizations:
inline static uint8_t div255(uint32_t x) {return (x*0x8081u) >> 23u; }
inline 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;
}
from dwm-winicon.
Okay this is weird. Maybe I should have added images.
Before:
After the patches:
Did I miss something?
Edit: On the first image is where i applied you win-icon repo changes and for some reason the icon remain transparent. The second is after changing the code you send.
from dwm-winicon.
can you show me the DWM code of the second screenshots?
from dwm-winicon.
from dwm-winicon.
yikes I don't know why i did that. Thanks seems to be working fine!
from dwm-winicon.
Yes works fine, thank you very much!
from dwm-winicon.
you're welcome :D
Also feel free to make an issue if you discover any bugs, crashes or memory leaks, since it's hard to cover all the situations by myself.
from dwm-winicon.
Related Issues (8)
- awesomebar, alpha, systray, winicon HOT 3
- same icon for multiple windows while using the awesome bar patch HOT 3
- I'm getting this error "/usr/include/X11/Xft/Xft.h fatal error: ft2build.h: No such file or directory" HOT 3
- Iconspacing & iconsizing undeclared HOT 1
- Show icon of occupied tab HOT 1
- fullgaps + alpha + winicon on dwm 6.4 HOT 6
- Can you mention whether the recommended flags should be added to CFLAGS or CPPFLAGS? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dwm-winicon.