1 diff -urN WindowMaker-0.91.0/src/wmspec.c WindowMaker-0.91.0.patch/src/wmspec.c
2 --- WindowMaker-0.91.0/src/wmspec.c 2004-10-24 21:36:15.000000000 +0200
3 +++ WindowMaker-0.91.0.patch/src/wmspec.c 2005-01-12 23:31:41.833101648 +0100
9 + * Find the best icon to be used by Window Maker for appicon/miniwindows.
10 + * Currently the algorithm is to take the image with the size closest
11 + * to icon_size x icon_size, but never bigger than that.
13 + * This algorithm is very poorly implemented and needs to be redone (it can
14 + * easily select images with very large widths and very small heights over
15 + * square images, if the area of the former is closer to the desired one).
17 + * The logic can also be changed to accept bigger images and scale them down.
20 +findBestIcon(CARD32 *data, unsigned long items)
22 + long size, wanted, d, distance;
26 + /* better use only 75% of icon_size. For 64x64 this means 48x48
27 + * This leaves room around the icon for the miniwindow title and
28 + * results in better overall aesthetics -Dan */
29 + wanted = wPreferences.icon_size * wPreferences.icon_size;
31 + for (icon=NULL, distance=LONG_MAX, i=0L; i<items-1; ) {
32 + size = data[i] * data[i+1];
36 + if (d>=0 && d<=distance && (i+size+2)<=items) {
48 +makeRImageFromARGBData(CARD32 *data)
50 + int size, width, height, i;
52 + unsigned char *imgdata;
57 + size = width * height;
62 + image = RCreateImage(width, height, True);
64 + for (imgdata=image->data, i=2; i<size+2; i++, imgdata+=4) {
66 + imgdata[3] = (pixel >> 24) & 0xff; /* A */
67 + imgdata[0] = (pixel >> 16) & 0xff; /* R */
68 + imgdata[1] = (pixel >> 8) & 0xff; /* G */
69 + imgdata[2] = (pixel >> 0) & 0xff; /* B */
77 updateIconImage(WScreen *scr, WWindow *wwin)
79 - Atom actual_type_return;
80 - int actual_format_return;
81 - unsigned long nitems_return, bytes_after_return;
82 - unsigned char *prop_return;
83 - int rc = XGetWindowProperty(dpy, wwin->client_win, net_wm_icon, 0, ~0, False,
84 - XA_CARDINAL, &actual_type_return, &actual_format_return,
85 - &nitems_return, &bytes_after_return, &prop_return);
87 - if (rc==Success && prop_return) {
88 - unsigned int *data = (unsigned int *)prop_return;
89 - unsigned int pos = 0, len = 0;
90 - unsigned int best_pos = 0, best_tmp = ~0;
91 - extern WPreferences wPreferences;
92 - unsigned int pref_size = wPreferences.icon_size;
93 - unsigned int pref_sq = pref_size*pref_size;
98 - len = data[pos+0]*data[pos+1];
99 - unsigned int tmp = pref_sq-len;
100 - if (tmp < best_tmp && tmp > 0) {
105 - } while (pos < nitems_return && len != 0);
106 + CARD32 *property, *data;
107 + unsigned long items, rest;
112 + if (XGetWindowProperty(dpy, wwin->client_win, net_wm_icon, 0L, LONG_MAX,
113 + False, XA_CARDINAL, &type, &format, &items, &rest,
114 + (unsigned char**)&property)!=Success || !property) {
118 - new_rimage = RCreateImage(data[best_pos+0], data[best_pos+1], True);
119 - len = data[best_pos+0] * data[best_pos+1];
120 - src = (char*)&data[best_pos+2];
121 - dst = new_rimage->data;
122 - for (pos=0; pos<len; ++pos, src+=4, dst+=4) {
123 - dst[0] = src[2]; /* R */
124 - dst[1] = src[1]; /* G */
125 - dst[2] = src[0]; /* B */
126 - dst[3] = src[3]; /* A */
127 + if (type!=XA_CARDINAL || format!=32 || items<2) {
133 + data = findBestIcon(property, items);
139 + image = makeRImageFromARGBData(data);
142 if (wwin->net_icon_image)
143 RReleaseImage(wwin->net_icon_image);
144 - wwin->net_icon_image = new_rimage;
145 + wwin->net_icon_image = image;
148 - XFree(prop_return);