5 icon* icon_update(screen *sc, Window win, gint *nicons)
7 /* these bits are borrowed from openbox' client.c::client_update_icons */
10 unsigned int w, h, i, j;
15 data = xprop_get_data(sc, win, _NET_WM_ICON, XA_CARDINAL, &num);
17 /* figure out how many valid icons are in here */
23 if (i > num || w*h == 0) break;
27 ret = calloc(*nicons, sizeof(icon));
31 for (j = 0; j < *nicons; ++j) {
34 w = ret[j].width = data[i++];
35 h = ret[j].height = data[i++];
37 if (w*h == 0) continue;
39 ret[j].data = g_new(RrPixel32, w * h);
40 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
46 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
47 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
48 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
49 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
58 if ((hints = XGetWMHints(sc->dd, win))) {
59 if (hints->flags & IconPixmapHint) {
61 ret = calloc(*nicons, sizeof(icon));
62 // xerror_set_ignore(TRUE);
63 if (!RrPixmapToRGBA(sc->rr,
65 (hints->flags & IconMaskHint ?
66 hints->icon_mask : None),
75 // xerror_set_ignore(FALSE);
83 const icon* icon_get_best(icon list[], int num, int w, int h)
87 gulong min_diff, min_i;
89 if (num < 1) return NULL;
91 min_diff = ABS(list[0].width - w) + ABS(list[0].height - h);
94 for (i = 1; i < num; ++i) {
97 diff = ABS(list[i].width - w) + ABS(list[i].height - h);
98 if (diff < min_diff) {