From daff5cd58b33f074ba94d1e288546e5cce3628c8 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Wed, 23 Dec 2015 14:16:24 +0100 Subject: [PATCH] Refactor _NET_WM_ICON parsing This shouldn't change the logic here, but hopefully makes it easier to understand. Signed-off-by: Uli Schlachter --- ewmh.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ewmh.c b/ewmh.c index 94142b8a7..3604f3011 100755 --- a/ewmh.c +++ b/ewmh.c @@ -686,10 +686,15 @@ ewmh_window_icon_from_reply(xcb_get_property_reply_t *r, uint32_t preferred_size /* use the greater of the two dimensions to match against the preferred size */ uint32_t size = MAX(data[0], data[1]); + /* pick the icon if it's a better match than the one we already have */ - if (data[0] && data[1] && ( - (found_size < preferred_size && size > found_size) || - (found_size > preferred_size && size >= preferred_size && size < found_size))) + bool found_icon_too_small = found_size < preferred_size; + bool found_icon_too_large = found_size > preferred_size; + bool icon_empty = data[0] == 0 || data[1] == 0; + bool better_because_bigger = found_icon_too_small && size > found_size; + bool better_because_smaller = found_icon_too_large && + size >= preferred_size && size < found_size; + if (!icon_empty && (better_because_bigger || better_because_smaller)) { found_data = data; found_size = size;