>From 13c8e570eb07f1db1960884287015ff97a1bbf98 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?"Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20(kix)"?= <[email protected]>
Date: Tue, 1 Jul 2012 23:23:11 +0200
Subject: [PATCH 13/13] switchpanel addIconForWindow icon updated

The function addIconForWindow did some wrong things:

1. The function got the image using wDefaultGetImage, with the option
   noDefault set to False. Then, the defaultIcon was included in the
   returned incon.
2. Because we had any icon, the function never enter in the next "if"
   and then "if (!image && !panel->defIcon)" was alwasy false.
3. Because is false, the "panel->defIcon" variable NEVER took any value
   and therefore, this variable, used for icon caching, could be removed.

Then, I made some changes:

To understand, ... (not in code!) the steps 1 and 2 are really implemented
as wDefaultGetImage().
1. Now calls to get_default_icon_filename() to get the icon file name.
2. Using the filename, calls to get_default_icon_rimage() to get the pixmap.

These functions are replaced by "wDefaultGetImage", because the functions
get_default_icon_filename() and get_default_icon_rimage() do the same that
wDefaultGetImage, therefore, the code can be replaced.

3. Because panel->defIcon is not used, we can remove the whole "if" block.
4. Because get_default_icon_rimage() returns the icon scaled, calls to the
   function scaleDownIfNeeded() is not needed.
5. Because scaleDownIfNeeded() was only used in addIconForWindow(), can be
   removed.
6. We still need support for scaling for net_icon_image, but is better use
   the function wIconValidateIconSize()
---
 src/switchpanel.c |   46 ++++++++--------------------------------------
 1 file changed, 8 insertions(+), 38 deletions(-)

diff --git a/src/switchpanel.c b/src/switchpanel.c
index 80b30a3..1372107 100644
--- a/src/switchpanel.c
+++ b/src/switchpanel.c
@@ -31,6 +31,7 @@
 #include "defaults.h"
 #include "switchpanel.h"
 #include "funcs.h"
+#include "icon.h"
 #include "xinerama.h"
 
 extern Atom _XA_WM_IGNORE_FOCUS_EVENTS;
@@ -56,8 +57,6 @@ struct SwitchPanel {
 
        WMLabel *label;
 
-       RImage *defIcon;
-
        RImage *tileTmp;
        RImage *tile;
 
@@ -152,17 +151,6 @@ static void changeImage(WSwitchPanel * panel, int idecks, 
int selected)
        }
 }
 
-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);
@@ -172,32 +160,16 @@ static void addIconForWindow(WSwitchPanel * panel, 
WMWidget * parent, WWindow *
        WMResizeWidget(icon, ICON_TILE_SIZE, ICON_TILE_SIZE);
        WMMoveWidget(icon, x, y);
 
-       if (!WFLAGP(wwin, always_user_icon) && wwin->net_icon_image)
+       /* Get the icon from wwindow net_icon_image) */
+       if (!WFLAGP(wwin, always_user_icon) && wwin->net_icon_image) {
                image = RRetainImage(wwin->net_icon_image);
-
-       // Make this use a caching thing. When there are many windows,
-       // it's very likely that most of them are instances of the same thing,
-       // so caching them should get performance acceptable in these cases.
-       if (!image)
-               image = wDefaultGetImage(panel->scr, wwin->wm_instance, 
wwin->wm_class, ICON_TILE_SIZE);
-
-       if (!image && !panel->defIcon) {
-               char *file = wDefaultGetIconFile(NULL, NULL, False);
-               if (file) {
-                       char *path = FindImage(wPreferences.icon_path, file);
-                       if (path) {
-                               image = RLoadImage(panel->scr->rcontext, path, 
0);
-                               wfree(path);
-                       }
-               }
-               if (image)
-                       panel->defIcon = scaleDownIfNeeded(image);
-               image = NULL;
+               image = wIconValidateIconSize(panel->scr, image, 
ICON_TILE_SIZE);
        }
-       if (!image && panel->defIcon)
-               image = RRetainImage(panel->defIcon);
 
-       image = scaleDownIfNeeded(image);
+       /* If not found, then get the image, including default */
+       if (!image)
+               image = wDefaultGetImage(panel->scr, wwin->wm_instance,
+                                        wwin->wm_class, ICON_TILE_SIZE);
 
        WMAddToArray(panel->images, image);
        WMAddToArray(panel->icons, icon);
@@ -592,8 +564,6 @@ void wSwitchPanelDestroy(WSwitchPanel * panel)
        if (panel->icons)
                WMFreeArray(panel->icons);
        WMFreeArray(panel->windows);
-       if (panel->defIcon)
-               RReleaseImage(panel->defIcon);
        if (panel->tile)
                RReleaseImage(panel->tile);
        if (panel->tileTmp)
-- 
1.7.10

-- 
||// //\\// Rodolfo "kix" Garcia
||\\// //\\ http://www.kix.es/
>From 13c8e570eb07f1db1960884287015ff97a1bbf98 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?"Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20(kix)"?= <[email protected]>
Date: Tue, 1 Jul 2012 23:23:11 +0200
Subject: [PATCH 13/13] switchpanel addIconForWindow icon updated

The function addIconForWindow did some wrong things:

1. The function got the image using wDefaultGetImage, with the option
   noDefault set to False. Then, the defaultIcon was included in the
   returned incon.
2. Because we had any icon, the function never enter in the next "if"
   and then "if (!image && !panel->defIcon)" was alwasy false.
3. Because is false, the "panel->defIcon" variable NEVER took any value
   and therefore, this variable, used for icon caching, could be removed.

Then, I made some changes:

To understand, ... (not in code!) the steps 1 and 2 are really implemented
as wDefaultGetImage().
1. Now calls to get_default_icon_filename() to get the icon file name.
2. Using the filename, calls to get_default_icon_rimage() to get the pixmap.

These functions are replaced by "wDefaultGetImage", because the functions
get_default_icon_filename() and get_default_icon_rimage() do the same that
wDefaultGetImage, therefore, the code can be replaced.

3. Because panel->defIcon is not used, we can remove the whole "if" block.
4. Because get_default_icon_rimage() returns the icon scaled, calls to the
   function scaleDownIfNeeded() is not needed.
5. Because scaleDownIfNeeded() was only used in addIconForWindow(), can be
   removed.
6. We still need support for scaling for net_icon_image, but is better use
   the function wIconValidateIconSize()
---
 src/switchpanel.c |   46 ++++++++--------------------------------------
 1 file changed, 8 insertions(+), 38 deletions(-)

diff --git a/src/switchpanel.c b/src/switchpanel.c
index 80b30a3..1372107 100644
--- a/src/switchpanel.c
+++ b/src/switchpanel.c
@@ -31,6 +31,7 @@
 #include "defaults.h"
 #include "switchpanel.h"
 #include "funcs.h"
+#include "icon.h"
 #include "xinerama.h"
 
 extern Atom _XA_WM_IGNORE_FOCUS_EVENTS;
@@ -56,8 +57,6 @@ struct SwitchPanel {
 
 	WMLabel *label;
 
-	RImage *defIcon;
-
 	RImage *tileTmp;
 	RImage *tile;
 
@@ -152,17 +151,6 @@ static void changeImage(WSwitchPanel * panel, int idecks, int selected)
 	}
 }
 
-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);
@@ -172,32 +160,16 @@ static void addIconForWindow(WSwitchPanel * panel, WMWidget * parent, WWindow *
 	WMResizeWidget(icon, ICON_TILE_SIZE, ICON_TILE_SIZE);
 	WMMoveWidget(icon, x, y);
 
-	if (!WFLAGP(wwin, always_user_icon) && wwin->net_icon_image)
+	/* Get the icon from wwindow net_icon_image) */
+	if (!WFLAGP(wwin, always_user_icon) && wwin->net_icon_image) {
 		image = RRetainImage(wwin->net_icon_image);
-
-	// Make this use a caching thing. When there are many windows,
-	// it's very likely that most of them are instances of the same thing,
-	// so caching them should get performance acceptable in these cases.
-	if (!image)
-		image = wDefaultGetImage(panel->scr, wwin->wm_instance, wwin->wm_class, ICON_TILE_SIZE);
-
-	if (!image && !panel->defIcon) {
-		char *file = wDefaultGetIconFile(NULL, NULL, False);
-		if (file) {
-			char *path = FindImage(wPreferences.icon_path, file);
-			if (path) {
-				image = RLoadImage(panel->scr->rcontext, path, 0);
-				wfree(path);
-			}
-		}
-		if (image)
-			panel->defIcon = scaleDownIfNeeded(image);
-		image = NULL;
+		image = wIconValidateIconSize(panel->scr, image, ICON_TILE_SIZE);
 	}
-	if (!image && panel->defIcon)
-		image = RRetainImage(panel->defIcon);
 
-	image = scaleDownIfNeeded(image);
+	/* If not found, then get the image, including default */
+	if (!image)
+		image = wDefaultGetImage(panel->scr, wwin->wm_instance,
+					 wwin->wm_class, ICON_TILE_SIZE);
 
 	WMAddToArray(panel->images, image);
 	WMAddToArray(panel->icons, icon);
@@ -592,8 +564,6 @@ void wSwitchPanelDestroy(WSwitchPanel * panel)
 	if (panel->icons)
 		WMFreeArray(panel->icons);
 	WMFreeArray(panel->windows);
-	if (panel->defIcon)
-		RReleaseImage(panel->defIcon);
 	if (panel->tile)
 		RReleaseImage(panel->tile);
 	if (panel->tileTmp)
-- 
1.7.10

Reply via email to