summaryrefslogtreecommitdiff
path: root/openbox
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2007-05-11 05:54:57 +0000
committerDana Jansens <danakj@orodu.net>2007-05-11 05:54:57 +0000
commit8432416d4e1acef20638536d0f26449dfc474cd2 (patch)
tree20b87b885ecd1d3243cdb0adad1ee29a7e31318a /openbox
parentd8919a9bf837da29c5ca4726c8ebc429127b955b (diff)
pick the closest icon instead of always a smaller one
Diffstat (limited to 'openbox')
-rw-r--r--openbox/client.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/openbox/client.c b/openbox/client.c
index e06fa291..af44d3b0 100644
--- a/openbox/client.c
+++ b/openbox/client.c
@@ -3478,9 +3478,7 @@ gboolean client_focused(ObClient *self)
static ObClientIcon* client_icon_recursive(ObClient *self, gint w, gint h)
{
guint i;
- /* si is the smallest image >= req */
- /* li is the largest image < req */
- gulong size, smallest = 0xffffffff, largest = 0, si = 0, li = 0;
+ gulong min_diff, min_i;
if (!self->nicons) {
ObClientIcon *parent = NULL;
@@ -3503,20 +3501,27 @@ static ObClientIcon* client_icon_recursive(ObClient *self, gint w, gint h)
return parent;
}
- 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");
}
}
- if (largest == 0) /* didnt find one smaller than the requested size */
- return &self->icons[si];
- return &self->icons[li];
+ return &self->icons[min_i];
}
const ObClientIcon* client_icon(ObClient *self, gint w, gint h)