+
+Icon *client_icon(Client *self, int w, int h)
+{
+ int i;
+ /* si is the smallest image >= req */
+ /* li is the largest image < req */
+ unsigned long size, smallest = 0xffffffff, largest = 0, si = 0, li = 0;
+
+ if (!self->nicons) return NULL;
+
+ 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;
+ }
+ }
+ if (largest == 0) /* didnt find one smaller than the requested size */
+ return &self->icons[si];
+ return &self->icons[li];
+}