From 99065c63f819a8274c7189f51c0e4a4f1ab5fb9d Mon Sep 17 00:00:00 2001
From: David Maciejak <david.maciejak@gmail.com>
Date: Fri, 7 Mar 2014 19:45:50 +0800
Subject: [PATCH] Fixed unknown image format detection in Icon Chooser preview
 mode

When pressing the Preview button from Icon chooser, a list of preview
icons is displayed. When a unknown image format is encountered the
list is showing duplicated entries. That patch is correcting that issue
and adding rescale feature to that preview show.
---
 src/dialog.c |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/dialog.c b/src/dialog.c
index 5218866..221f6ac 100644
--- a/src/dialog.c
+++ b/src/dialog.c
@@ -741,11 +741,12 @@ static void drawIconProc(WMList * lPtr, int index, Drawable d, char *text, int s
 	color.blue = WMBlueComponentOfColor(back) >> 8;
 	color.alpha = WMGetColorAlpha(back) >> 8;
 
-	pixmap = WMCreateBlendedPixmapFromFile(wmscr, file, &color, 0, 0);
+	pixmap = WMCreateBlendedPixmapFromFile(wmscr, file, &color, 64, 100);
 	wfree(file);
 
 	if (!pixmap) {
-		/*WMRemoveListItem(lPtr, index); */
+		/* if unknow image format, just remove the entry from the preview list */
+		WMRemoveListItem(lPtr, index);
 		return;
 	}
 
@@ -758,10 +759,9 @@ static void drawIconProc(WMList * lPtr, int index, Drawable d, char *text, int s
 	size = WMGetPixmapSize(pixmap);
 
 	XSetClipMask(dpy, copygc, WMGetPixmapMaskXID(pixmap));
-	XSetClipOrigin(dpy, copygc, x + (width - size.width) / 2, y + 2);
-	XCopyArea(dpy, WMGetPixmapXID(pixmap), d, copygc, 0, 0,
-		  size.width > 100 ? 100 : size.width, size.height > 64 ? 64 : size.height,
-		  x + (width - size.width) / 2, y + 2);
+	/* the icon is centered */
+	XSetClipOrigin(dpy, copygc, x + (width - size.width) / 2, y + (height - size.height) / 2);
+	XCopyArea(dpy, WMGetPixmapXID(pixmap), d, copygc, 0, 0, size.width, size.height, x + (width - size.width) / 2, y + (height - size.height) / 2);
 
 	{
 		int i, j;
-- 
1.7.10.4

