>From 993c1ab4dd80cafe4d48030e459a961ef191caf4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?"Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20(kix)"?= <[email protected]>
Date: Sun, 15 Jul 2012 15:43:57 +0200
Subject: [PATCH 5/5] scaleDownIfNeeded removed

The icons had problems with their size in some places (appicons, docks and
switchpanel). This patch solves these problems.

1. This patch removes the argument WScreen in wIconValidateIconSize,
   because is not used.

2. The function scaleDownIfNeeded's code is duplicated with the code of
   wIconValidateIconSize(), then this function can be removed. The icon
   size in the switchpanel should be ~48 pixels, to allow the frame around
   the icon. Then, we always shoul resize the icon to this size. The standard
   icon size is specified in WPreferences.icon_size (usually 64 pixels).

3. The icon size should be set when the icon is created, then, the icon size
   for net_icon_image should be set at get_wwindow_image_from_x11(), when the
   icon is created.
---
 src/icon.c        |   10 +++++-----
 src/icon.h        |    2 +-
 src/switchpanel.c |   16 +++-------------
 src/wdefaults.c   |    2 +-
 src/wmspec.c      |    4 ++++
 5 files changed, 14 insertions(+), 20 deletions(-)

diff --git a/src/icon.c b/src/icon.c
index 8772f2c..22df232 100644
--- a/src/icon.c
+++ b/src/icon.c
@@ -149,7 +149,7 @@ WIcon *wIconCreate(WWindow * wwin)
        return icon;
 }
 
-WIcon *wIconCreateWithIconFile(WScreen * scr, char *iconfile, int tile)
+WIcon *wIconCreateWithIconFile(WScreen *scr, char *iconfile, int tile)
 {
        WIcon *icon;
 
@@ -160,7 +160,7 @@ WIcon *wIconCreateWithIconFile(WScreen * scr, char 
*iconfile, int tile)
                if (!icon->file_image)
                        wwarning(_("error loading image file \"%s\": %s"), 
iconfile, RMessageForError(RErrorCode));
 
-               icon->file_image = wIconValidateIconSize(scr, icon->file_image, 
wPreferences.icon_size);
+               icon->file_image = wIconValidateIconSize(icon->file_image, 
wPreferences.icon_size);
 
                icon->file = wstrdup(iconfile);
        }
@@ -338,7 +338,7 @@ void wIconChangeTitle(WIcon * icon, char *new_title)
        wIconPaint(icon);
 }
 
-RImage *wIconValidateIconSize(WScreen *scr, RImage *icon, int max_size)
+RImage *wIconValidateIconSize(RImage *icon, int max_size)
 {
        RImage *nimage;
 
@@ -376,7 +376,7 @@ Bool wIconChangeImageFile(WIcon * icon, char *file)
        path = FindImage(wPreferences.icon_path, file);
 
        if (path && (image = RLoadImage(scr->rcontext, path, 0))) {
-               icon->file_image = 
wIconValidateIconSize(icon->core->screen_ptr, image, wPreferences.icon_size);
+               icon->file_image = wIconValidateIconSize(image, 
wPreferences.icon_size);
                wIconUpdate(icon);
        } else {
                error = 1;
@@ -630,7 +630,7 @@ void get_pixmap_icon_from_user_icon(WScreen *scr, WIcon * 
icon)
                                }
                        }
 
-                       image = wIconValidateIconSize(scr, image, 
wPreferences.icon_size);
+                       image = wIconValidateIconSize(image, 
wPreferences.icon_size);
                        scr->def_icon_pixmap = makeIcon(scr, image, False, 
False, icon->tile_type, icon->highlighted);
                        scr->def_ticon_pixmap = makeIcon(scr, image, True, 
False, icon->tile_type, icon->highlighted);
                        if (image)
diff --git a/src/icon.h b/src/icon.h
index 62a1844..96bb7d0 100644
--- a/src/icon.h
+++ b/src/icon.h
@@ -65,7 +65,7 @@ void wIconChangeTitle(WIcon *icon, char *new_title);
 
 Bool wIconChangeImageFile(WIcon *icon, char *file);
 
-RImage * wIconValidateIconSize(WScreen *scr, RImage *icon, int max_size);
+RImage *wIconValidateIconSize(RImage *icon, int max_size);
 
 char *wIconStore(WIcon *icon);
 char *get_name_for_instance_class(char *wm_instance, char *wm_class);
diff --git a/src/switchpanel.c b/src/switchpanel.c
index 2b8930f..320ae63 100644
--- a/src/switchpanel.c
+++ b/src/switchpanel.c
@@ -27,6 +27,7 @@
 #include "WindowMaker.h"
 #include "screen.h"
 #include "framewin.h"
+#include "icon.h"
 #include "window.h"
 #include "defaults.h"
 #include "switchpanel.h"
@@ -148,18 +149,6 @@ static void changeImage(WSwitchPanel *panel, int idecks, 
int selected)
                WMSetFrameRelief(icon, WRSimple);
 }
 
-static RImage *scaleDownIfNeeded(RImage *image)
-{
-       if (image && ((image->width - ICON_SIZE) > 2 || (image->height - 
ICON_SIZE) > 2)) {
-               RImage *nimage;
-               nimage = RScaleImage(image, ICON_SIZE, (image->height * 
ICON_SIZE / image->width));
-               RReleaseImage(image);
-               image = nimage;
-       }
-
-       return image;
-}
-
 static void addIconForWindow(WSwitchPanel *panel, WMWidget *parent, WWindow 
*wwin, int x, int y)
 {
        WMFrame *icon = WMCreateFrame(parent);
@@ -176,7 +165,8 @@ static void addIconForWindow(WSwitchPanel *panel, WMWidget 
*parent, WWindow *wwi
        if (!image)
                image = wDefaultGetImage(panel->scr, wwin->wm_instance, 
wwin->wm_class, ICON_TILE_SIZE);
 
-       image = scaleDownIfNeeded(image);
+       /* We must resize the icon size (~64) to the switchpanel icon size 
(~48) */
+       image = wIconValidateIconSize(image, ICON_SIZE);
 
        WMAddToArray(panel->images, image);
        WMAddToArray(panel->icons, icon);
diff --git a/src/wdefaults.c b/src/wdefaults.c
index 1f52d7d..497cb48 100644
--- a/src/wdefaults.c
+++ b/src/wdefaults.c
@@ -432,7 +432,7 @@ RImage *get_default_icon_rimage(WScreen *scr, char 
*file_name, int max_size)
                wwarning(_("error loading image file \"%s\": %s"), file_name,
                         RMessageForError(RErrorCode));
 
-       image = wIconValidateIconSize(scr, image, max_size);
+       image = wIconValidateIconSize(image, max_size);
 
        return image;
 }
diff --git a/src/wmspec.c b/src/wmspec.c
index 494f55b..b416fdb 100644
--- a/src/wmspec.c
+++ b/src/wmspec.c
@@ -449,6 +449,10 @@ static RImage *get_wwindow_image_from_x11(WWindow *wwin)
        image = makeRImageFromARGBData(data);
 
        XFree(property);
+
+       /* Resize the image to the correct value */
+       image = wIconValidateIconSize(image, wPreferences.icon_size);
+
        return image;
 }
 
-- 
1.7.10.4

-- 
||// //\\// Rodolfo "kix" Garcia
||\\// //\\ http://www.kix.es/
>From 993c1ab4dd80cafe4d48030e459a961ef191caf4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?"Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20(kix)"?= <[email protected]>
Date: Sun, 15 Jul 2012 15:43:57 +0200
Subject: [PATCH 5/5] scaleDownIfNeeded removed

The icons had problems with their size in some places (appicons, docks and
switchpanel). This patch solves these problems.

1. This patch removes the argument WScreen in wIconValidateIconSize,
   because is not used.

2. The function scaleDownIfNeeded's code is duplicated with the code of
   wIconValidateIconSize(), then this function can be removed. The icon
   size in the switchpanel should be ~48 pixels, to allow the frame around
   the icon. Then, we always shoul resize the icon to this size. The standard
   icon size is specified in WPreferences.icon_size (usually 64 pixels).

3. The icon size should be set when the icon is created, then, the icon size
   for net_icon_image should be set at get_wwindow_image_from_x11(), when the
   icon is created.
---
 src/icon.c        |   10 +++++-----
 src/icon.h        |    2 +-
 src/switchpanel.c |   16 +++-------------
 src/wdefaults.c   |    2 +-
 src/wmspec.c      |    4 ++++
 5 files changed, 14 insertions(+), 20 deletions(-)

diff --git a/src/icon.c b/src/icon.c
index 8772f2c..22df232 100644
--- a/src/icon.c
+++ b/src/icon.c
@@ -149,7 +149,7 @@ WIcon *wIconCreate(WWindow * wwin)
 	return icon;
 }
 
-WIcon *wIconCreateWithIconFile(WScreen * scr, char *iconfile, int tile)
+WIcon *wIconCreateWithIconFile(WScreen *scr, char *iconfile, int tile)
 {
 	WIcon *icon;
 
@@ -160,7 +160,7 @@ WIcon *wIconCreateWithIconFile(WScreen * scr, char *iconfile, int tile)
 		if (!icon->file_image)
 			wwarning(_("error loading image file \"%s\": %s"), iconfile, RMessageForError(RErrorCode));
 
-		icon->file_image = wIconValidateIconSize(scr, icon->file_image, wPreferences.icon_size);
+		icon->file_image = wIconValidateIconSize(icon->file_image, wPreferences.icon_size);
 
 		icon->file = wstrdup(iconfile);
 	}
@@ -338,7 +338,7 @@ void wIconChangeTitle(WIcon * icon, char *new_title)
 	wIconPaint(icon);
 }
 
-RImage *wIconValidateIconSize(WScreen *scr, RImage *icon, int max_size)
+RImage *wIconValidateIconSize(RImage *icon, int max_size)
 {
 	RImage *nimage;
 
@@ -376,7 +376,7 @@ Bool wIconChangeImageFile(WIcon * icon, char *file)
 	path = FindImage(wPreferences.icon_path, file);
 
 	if (path && (image = RLoadImage(scr->rcontext, path, 0))) {
-		icon->file_image = wIconValidateIconSize(icon->core->screen_ptr, image, wPreferences.icon_size);
+		icon->file_image = wIconValidateIconSize(image, wPreferences.icon_size);
 		wIconUpdate(icon);
 	} else {
 		error = 1;
@@ -630,7 +630,7 @@ void get_pixmap_icon_from_user_icon(WScreen *scr, WIcon * icon)
 				}
 			}
 
-			image = wIconValidateIconSize(scr, image, wPreferences.icon_size);
+			image = wIconValidateIconSize(image, wPreferences.icon_size);
 			scr->def_icon_pixmap = makeIcon(scr, image, False, False, icon->tile_type, icon->highlighted);
 			scr->def_ticon_pixmap = makeIcon(scr, image, True, False, icon->tile_type, icon->highlighted);
 			if (image)
diff --git a/src/icon.h b/src/icon.h
index 62a1844..96bb7d0 100644
--- a/src/icon.h
+++ b/src/icon.h
@@ -65,7 +65,7 @@ void wIconChangeTitle(WIcon *icon, char *new_title);
 
 Bool wIconChangeImageFile(WIcon *icon, char *file);
 
-RImage * wIconValidateIconSize(WScreen *scr, RImage *icon, int max_size);
+RImage *wIconValidateIconSize(RImage *icon, int max_size);
 
 char *wIconStore(WIcon *icon);
 char *get_name_for_instance_class(char *wm_instance, char *wm_class);
diff --git a/src/switchpanel.c b/src/switchpanel.c
index 2b8930f..320ae63 100644
--- a/src/switchpanel.c
+++ b/src/switchpanel.c
@@ -27,6 +27,7 @@
 #include "WindowMaker.h"
 #include "screen.h"
 #include "framewin.h"
+#include "icon.h"
 #include "window.h"
 #include "defaults.h"
 #include "switchpanel.h"
@@ -148,18 +149,6 @@ static void changeImage(WSwitchPanel *panel, int idecks, int selected)
 		WMSetFrameRelief(icon, WRSimple);
 }
 
-static RImage *scaleDownIfNeeded(RImage *image)
-{
-	if (image && ((image->width - ICON_SIZE) > 2 || (image->height - ICON_SIZE) > 2)) {
-		RImage *nimage;
-		nimage = RScaleImage(image, ICON_SIZE, (image->height * ICON_SIZE / image->width));
-		RReleaseImage(image);
-		image = nimage;
-	}
-
-	return image;
-}
-
 static void addIconForWindow(WSwitchPanel *panel, WMWidget *parent, WWindow *wwin, int x, int y)
 {
 	WMFrame *icon = WMCreateFrame(parent);
@@ -176,7 +165,8 @@ static void addIconForWindow(WSwitchPanel *panel, WMWidget *parent, WWindow *wwi
 	if (!image)
 		image = wDefaultGetImage(panel->scr, wwin->wm_instance, wwin->wm_class, ICON_TILE_SIZE);
 
-	image = scaleDownIfNeeded(image);
+	/* We must resize the icon size (~64) to the switchpanel icon size (~48) */
+	image = wIconValidateIconSize(image, ICON_SIZE);
 
 	WMAddToArray(panel->images, image);
 	WMAddToArray(panel->icons, icon);
diff --git a/src/wdefaults.c b/src/wdefaults.c
index 1f52d7d..497cb48 100644
--- a/src/wdefaults.c
+++ b/src/wdefaults.c
@@ -432,7 +432,7 @@ RImage *get_default_icon_rimage(WScreen *scr, char *file_name, int max_size)
 		wwarning(_("error loading image file \"%s\": %s"), file_name,
 			 RMessageForError(RErrorCode));
 
-	image = wIconValidateIconSize(scr, image, max_size);
+	image = wIconValidateIconSize(image, max_size);
 
 	return image;
 }
diff --git a/src/wmspec.c b/src/wmspec.c
index 494f55b..b416fdb 100644
--- a/src/wmspec.c
+++ b/src/wmspec.c
@@ -449,6 +449,10 @@ static RImage *get_wwindow_image_from_x11(WWindow *wwin)
 	image = makeRImageFromARGBData(data);
 
 	XFree(property);
+
+	/* Resize the image to the correct value */
+	image = wIconValidateIconSize(image, wPreferences.icon_size);
+
 	return image;
 }
 
-- 
1.7.10.4

Reply via email to