From: "Rodolfo García Peñas (kix)" <k...@kix.es>

This patch create two new functions:

static RImage *get_window_image(WWindow *wwin);
static RImage *get_window_image_def(WWindow *wwin);

The function get_window_image() creates an image using these methods:
 a) Get the window image from the client, using the "net_wm_icon" image
 b) If not found, use the wm_hints image

This aim of this function is set the window image (wwin->net_icon_image)
but don't set the default image, so net_icon_image could be NULL. The
reason is because we don't want to save the default icon in the disk,
only "real" icons.

The function get_window_image_def() returns the icon stored at
wwin->net_icon_image, but if the image is NULL, then returns the default
icon.

The aim of get_window_image_def() is show an icon always to the user.

This patch also needs to set as public these functions:

+RImage *get_wwindow_image_from_wm_hints(WWindow *wwin);
+RImage *get_rimage_from_default(WScreen *scr);

And the function get_rimage_icon_from_default_icon() is renamed to
get_rimage_from_default() because this function returns the default image,
and don't have (needs/provides) an icon, only the an image (yes, can be used
in a WIcon, but is a image).
---
 src/icon.c   |    9 ++++-----
 src/icon.h   |    2 ++
 src/wmspec.c |   34 ++++++++++++++++++++++++++++++++++
 3 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/src/icon.c b/src/icon.c
index ce97b26..8ee69ca 100644
--- a/src/icon.c
+++ b/src/icon.c
@@ -63,7 +63,6 @@ static WIcon *icon_create_core(WScreen *scr, int coord_x, int 
coord_y);
 static void set_dockapp_in_icon(WIcon *icon);
 static RImage *get_rimage_icon_from_icon_win(WIcon *icon);
 static void get_rimage_icon_from_user_icon(WIcon *icon);
-static RImage *get_rimage_icon_from_default_icon(WScreen *scr);
 
 static void icon_update_pixmap(WIcon *icon, RImage *image);
 static void unset_icon_image(WIcon *icon);
@@ -463,7 +462,7 @@ static char *get_icon_cache_path(void)
        return NULL;
 }
 
-static RImage *get_wwindow_image_from_wm_hints(WWindow *wwin)
+RImage *get_wwindow_image_from_wm_hints(WWindow *wwin)
 {
        RImage *image = NULL;
        XWMHints *hints = wwin->wm_hints;
@@ -670,10 +669,10 @@ static void get_rimage_icon_from_user_icon(WIcon *icon)
        /* Remove the icon image */
        unset_icon_image(icon);
 
-       icon->file_image = 
get_rimage_icon_from_default_icon(icon->core->screen_ptr);
+       icon->file_image = get_rimage_from_default(icon->core->screen_ptr);
 }
 
-static RImage *get_rimage_icon_from_default_icon(WScreen *scr)
+RImage *get_rimage_from_default(WScreen *scr)
 {
        /* If the icon don't have image, we should use the default image. */
        if (!scr->def_icon_rimage)
@@ -692,7 +691,7 @@ static RImage *get_rimage_icon_from_icon_win(WIcon *icon)
        image = get_window_image_from_x11(icon->icon_win);
 
        if (!image)
-               image = 
get_rimage_icon_from_default_icon(icon->core->screen_ptr);
+               image = get_rimage_from_default(icon->core->screen_ptr);
 
        return image;
 }
diff --git a/src/icon.h b/src/icon.h
index 696a20d..5d2c7d1 100644
--- a/src/icon.h
+++ b/src/icon.h
@@ -67,6 +67,8 @@ Bool wIconChangeImageFile(WIcon *icon, char *file);
 
 RImage *wIconValidateIconSize(RImage *icon, int max_size);
 RImage *get_rimage_icon_from_wm_hints(WWindow *wwin);
+RImage *get_wwindow_image_from_wm_hints(WWindow *wwin);
+RImage *get_rimage_from_default(WScreen *scr);
 
 char *wIconStore(WIcon *icon);
 char *get_name_for_instance_class(char *wm_instance, char *wm_class);
diff --git a/src/wmspec.c b/src/wmspec.c
index c758f0a..3ad4f6e 100644
--- a/src/wmspec.c
+++ b/src/wmspec.c
@@ -231,6 +231,9 @@ static void updateCurrentWorkspace(WScreen *scr);
 static void updateWorkspaceCount(WScreen *scr);
 static void wNETWMShowingDesktop(WScreen *scr, Bool show);
 
+static RImage *get_window_image(WWindow *wwin);
+static RImage *get_window_image_def(WWindow *wwin);
+
 typedef struct NetData {
        WScreen *scr;
        WReservedArea *strut;
@@ -420,6 +423,37 @@ static RImage *makeRImageFromARGBData(unsigned long *data)
        return image;
 }
 
+static RImage *get_window_image(WWindow *wwin)
+{
+       RImage *image = NULL;
+
+       /* First, get the image from the client (net_wm_icon) */
+       image = get_window_image_from_x11(wwin->client_win);
+
+       /* If no image, get the image from the window hints */
+       if (!image)
+               image = get_wwindow_image_from_wm_hints(wwin);
+
+       if (image)
+               image = wIconValidateIconSize(image, wPreferences.icon_size);
+
+       /* If no image, don't return the default image
+        * is better to control if we found the image and
+        * for example, don't save the default icon as cache */
+       return image;
+}
+
+static RImage *get_window_image_def(WWindow *wwin)
+{
+       /* The window image is stored at window->net_icon_image
+        * because get_window_image() sets it there, return it */
+       if (wwin->net_icon_image)
+               return RRetainImage(wwin->net_icon_image);
+
+       /* Else, return the default icon */
+       return get_rimage_from_default(wwin->screen_ptr);
+}
+
 RImage *get_window_image_from_x11(Window window)
 {
        RImage *image;
-- 
1.7.10.4


-- 
To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.

Reply via email to