>From 8b6f47395b86c78d4c494353f14bc74f58aea49e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?"Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20(kix)"?= <[email protected]>
Date: Sat, 14 Jul 2012 12:07:45 +0200
Subject: [PATCH 2/5] New function create_default_icon

The function create_default_icon sets the panel's default icon. This
is interesting to have a "cache" icon and don't search the default
icon more than one time if the icons don't have icon associated.

The code of create_default_icon was included in the addIconForWindow()
function, this patch only moves it to get a better (clear) code.
---
 src/switchpanel.c |   44 ++++++++++++++++++++++++++------------------
 1 file changed, 26 insertions(+), 18 deletions(-)

diff --git a/src/switchpanel.c b/src/switchpanel.c
index 2c52e63..5966d9a 100644
--- a/src/switchpanel.c
+++ b/src/switchpanel.c
@@ -162,6 +162,27 @@ static RImage *scaleDownIfNeeded(RImage *image)
        return image;
 }
 
+/* This function sets the default icon (defIcon) in the switchpanel */
+static void create_default_icon(WSwitchPanel *panel)
+{
+       RImage *image = NULL;
+       char *path = NULL;
+       char *file = wDefaultGetIconFile(NULL, NULL, False);
+
+       if (file) {
+               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;
+}
+
 static void addIconForWindow(WSwitchPanel *panel, WMWidget *parent, WWindow 
*wwin, int x, int y)
 {
        WMFrame *icon = WMCreateFrame(parent);
@@ -174,27 +195,14 @@ static void addIconForWindow(WSwitchPanel *panel, 
WMWidget *parent, WWindow *wwi
        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;
-       }
+       // 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 && !panel->defIcon)
+               create_default_icon(panel);
 
        if (!image && panel->defIcon)
                image = RRetainImage(panel->defIcon);
-- 
1.7.10.4

-- 
||// //\\// Rodolfo "kix" Garcia
||\\// //\\ http://www.kix.es/
>From 8b6f47395b86c78d4c494353f14bc74f58aea49e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?"Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20(kix)"?= <[email protected]>
Date: Sat, 14 Jul 2012 12:07:45 +0200
Subject: [PATCH 2/5] New function create_default_icon

The function create_default_icon sets the panel's default icon. This
is interesting to have a "cache" icon and don't search the default
icon more than one time if the icons don't have icon associated.

The code of create_default_icon was included in the addIconForWindow()
function, this patch only moves it to get a better (clear) code.
---
 src/switchpanel.c |   44 ++++++++++++++++++++++++++------------------
 1 file changed, 26 insertions(+), 18 deletions(-)

diff --git a/src/switchpanel.c b/src/switchpanel.c
index 2c52e63..5966d9a 100644
--- a/src/switchpanel.c
+++ b/src/switchpanel.c
@@ -162,6 +162,27 @@ static RImage *scaleDownIfNeeded(RImage *image)
 	return image;
 }
 
+/* This function sets the default icon (defIcon) in the switchpanel */
+static void create_default_icon(WSwitchPanel *panel)
+{
+	RImage *image = NULL;
+	char *path = NULL;
+	char *file = wDefaultGetIconFile(NULL, NULL, False);
+
+	if (file) {
+		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;
+}
+
 static void addIconForWindow(WSwitchPanel *panel, WMWidget *parent, WWindow *wwin, int x, int y)
 {
 	WMFrame *icon = WMCreateFrame(parent);
@@ -174,27 +195,14 @@ static void addIconForWindow(WSwitchPanel *panel, WMWidget *parent, WWindow *wwi
 	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;
-	}
+	// 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 && !panel->defIcon)
+		create_default_icon(panel);
 
 	if (!image && panel->defIcon)
 		image = RRetainImage(panel->defIcon);
-- 
1.7.10.4

Reply via email to