- for (i = 0; i < self->nicons; ++i) {
- size = self->icons[i].width * self->icons[i].height;
- if (size < smallest && size >= (unsigned)(w * h)) {
- smallest = size;
- si = i;
- }
- if (size > largest && size <= (unsigned)(w * h)) {
- largest = size;
- li = i;
+ /* some kind of crappy approximation to find the icon closest in size to
+ what we requested, but icons are generally all the same ratio as
+ eachother so it's good enough. */
+
+ min_diff = ABS(self->icons[0].width - w) + ABS(self->icons[0].height - h);
+ min_i = 0;
+
+ for (i = 1; i < self->nicons; ++i) {
+ gulong diff;
+
+ ob_debug("icon %d %d wanted %d %d\n",
+ self->icons[i].width, self->icons[i].height, w, h);
+ diff = ABS(self->icons[0].width - w) + ABS(self->icons[0].height - h);
+ ob_debug("dsize %u\n", diff);
+ if (diff < min_diff) {
+ min_diff = diff;
+ min_i = i;
+ ob_debug("chose it\n");