>From dc9a8d24f3b78c20511f47ad86e2eb85ee62234d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?"Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20(kix)"?= <[email protected]>
Date: Sun, 4 Mar 2012 12:45:34 +0100
Subject: [PATCH 2/8] WindowMaker: New get_wwindow_image_from_x11 function

A new function is created to get the image from the X11 window.

The function updateIconImage is splitted in two blocks, one is moved to 
get_wwindow_image_from_x11 with the X11 code, and other is used to update the 
Application and Window icons (kept in the same function).
---
 src/wmspec.c |   35 +++++++++++++++++++++--------------
 1 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/src/wmspec.c b/src/wmspec.c
index 5bdc43c..bbd96bd 100644
--- a/src/wmspec.c
+++ b/src/wmspec.c
@@ -386,7 +386,7 @@ static unsigned long *findBestIcon(unsigned long *data, 
unsigned long items)
        return icon;
 }
 
-static RImage *makeRImageFromARGBData(unsigned long *data)
+RImage *makeRImageFromARGBData(unsigned long *data)
 {
        int size, width, height, i;
        RImage *image;
@@ -413,40 +413,47 @@ static RImage *makeRImageFromARGBData(unsigned long *data)
        return image;
 }
 
-static void updateIconImage(WWindow * wwin)
+RImage *get_wwindow_image_from_x11(WWindow *wwin)
 {
-       unsigned long *property, *data;
-       unsigned long items, rest;
+       RImage *image;
        Atom type;
        int format;
+       unsigned long items, rest;
+       unsigned long *property, *data;
 
-       /* Refresh icon image from X11 */
-       if (wwin->net_icon_image)
-               RReleaseImage(wwin->net_icon_image);
-
-       wwin->net_icon_image = NULL;
-
+       /* Get the icon from X11 Window */
        if (XGetWindowProperty(dpy, wwin->client_win, net_wm_icon, 0L, LONG_MAX,
                               False, XA_CARDINAL, &type, &format, &items, 
&rest,
                               (unsigned char **)&property) != Success || 
!property)
-               return;
+               return NULL;
 
        if (type != XA_CARDINAL || format != 32 || items < 2) {
                XFree(property);
-               return;
+               return NULL;
        }
 
        /* Find the best icon */
        data = findBestIcon(property, items);
        if (!data) {
                XFree(property);
-               return;
+               return NULL;
        }
 
        /* Save the best icon in the X11 icon */
-       wwin->net_icon_image = makeRImageFromARGBData(data);
+       image = makeRImageFromARGBData(data);
 
        XFree(property);
+       return(image);
+}
+
+static void updateIconImage(WWindow *wwin)
+{
+       /* Remove the icon image from X11 */
+       if (wwin->net_icon_image)
+               RReleaseImage(wwin->net_icon_image);
+
+       /* Save the icon in the X11 icon */
+       wwin->net_icon_image = get_wwindow_image_from_x11(wwin);
 
        /* Refresh the Window Icon */
        if (wwin->icon)
-- 
1.7.7.3

-- 
||// //\\// Rodolfo "kix" Garcia
||\\// //\\ http://www.kix.es/
>From dc9a8d24f3b78c20511f47ad86e2eb85ee62234d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?"Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20(kix)"?= <[email protected]>
Date: Sun, 4 Mar 2012 12:45:34 +0100
Subject: [PATCH 2/8] WindowMaker: New get_wwindow_image_from_x11 function

A new function is created to get the image from the X11 window.

The function updateIconImage is splitted in two blocks, one is moved to get_wwindow_image_from_x11 with the X11 code, and other is used to update the Application and Window icons (kept in the same function).
---
 src/wmspec.c |   35 +++++++++++++++++++++--------------
 1 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/src/wmspec.c b/src/wmspec.c
index 5bdc43c..bbd96bd 100644
--- a/src/wmspec.c
+++ b/src/wmspec.c
@@ -386,7 +386,7 @@ static unsigned long *findBestIcon(unsigned long *data, unsigned long items)
 	return icon;
 }
 
-static RImage *makeRImageFromARGBData(unsigned long *data)
+RImage *makeRImageFromARGBData(unsigned long *data)
 {
 	int size, width, height, i;
 	RImage *image;
@@ -413,40 +413,47 @@ static RImage *makeRImageFromARGBData(unsigned long *data)
 	return image;
 }
 
-static void updateIconImage(WWindow * wwin)
+RImage *get_wwindow_image_from_x11(WWindow *wwin)
 {
-	unsigned long *property, *data;
-	unsigned long items, rest;
+	RImage *image;
 	Atom type;
 	int format;
+	unsigned long items, rest;
+	unsigned long *property, *data;
 
-	/* Refresh icon image from X11 */
-	if (wwin->net_icon_image)
-		RReleaseImage(wwin->net_icon_image);
-
-	wwin->net_icon_image = NULL;
-
+	/* Get the icon from X11 Window */
 	if (XGetWindowProperty(dpy, wwin->client_win, net_wm_icon, 0L, LONG_MAX,
 			       False, XA_CARDINAL, &type, &format, &items, &rest,
 			       (unsigned char **)&property) != Success || !property)
-		return;
+		return NULL;
 
 	if (type != XA_CARDINAL || format != 32 || items < 2) {
 		XFree(property);
-		return;
+		return NULL;
 	}
 
 	/* Find the best icon */
 	data = findBestIcon(property, items);
 	if (!data) {
 		XFree(property);
-		return;
+		return NULL;
 	}
 
 	/* Save the best icon in the X11 icon */
-	wwin->net_icon_image = makeRImageFromARGBData(data);
+	image = makeRImageFromARGBData(data);
 
 	XFree(property);
+	return(image);
+}
+
+static void updateIconImage(WWindow *wwin)
+{
+	/* Remove the icon image from X11 */
+	if (wwin->net_icon_image)
+		RReleaseImage(wwin->net_icon_image);
+
+	/* Save the icon in the X11 icon */
+	wwin->net_icon_image = get_wwindow_image_from_x11(wwin);
 
 	/* Refresh the Window Icon */
 	if (wwin->icon)
-- 
1.7.7.3

Reply via email to