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

The function wIconChangeTitle() now changes the icon title name
doing the full work (except painting it).

The function receives now the icon to change the name and the
wwindow with the new name. The function checks if icon and the
window exists.

Then, try to get the name using wNETWMGetIconName(), if not found
then try to read it from wGetIconName(). Then the icon has the new
name and the function returns.

This is better because:

1. We don't need a flag to know if the window got the name
   using the wNETWMGetIconName function. Now call this function
   always.

2. We do the same work in all calls to the wIconChangeTitle()
   function.
---
 src/client.c |   14 ++++----------
 src/icon.c   |   22 +++++++++++-----------
 src/icon.h   |    2 +-
 src/window.h |    1 -
 src/wmspec.c |    4 ++--
 5 files changed, 18 insertions(+), 25 deletions(-)

diff --git a/src/client.c b/src/client.c
index 2ae1e48..70791ee 100644
--- a/src/client.c
+++ b/src/client.c
@@ -331,16 +331,10 @@ void wClientCheckProperty(WWindow * wwin, XPropertyEvent 
* event)
                break;
 
        case XA_WM_ICON_NAME:
-               if (!wwin->flags.net_has_icon_title) {
-                       if (!wwin->icon)
-                               break;
-                       else {
-                               char *new_title;
-
-                               /* icon title was changed */
-                               wGetIconName(dpy, wwin->client_win, &new_title);
-                               wIconChangeTitle(wwin->icon, new_title);
-                       }
+               /* icon title was changed */
+               if (wwin->icon) {
+                       wIconChangeTitle(wwin->icon, wwin);
+                       wIconPaint(wwin->icon);
                }
                break;
 
diff --git a/src/icon.c b/src/icon.c
index 0aa29b8..b20ab4f 100644
--- a/src/icon.c
+++ b/src/icon.c
@@ -132,11 +132,7 @@ WIcon *icon_create_for_wwindow(WWindow *wwin)
        icon->show_title = 1;
 #endif
 
-       icon->icon_name = wNETWMGetIconName(wwin->client_win);
-       if (icon->icon_name)
-               wwin->flags.net_has_icon_title = 1;
-       else
-               wGetIconName(dpy, wwin->client_win, &icon->icon_name);
+       wIconChangeTitle(icon, wwin);
 
        icon->tile_type = TILE_NORMAL;
 
@@ -333,17 +329,21 @@ static void icon_update_pixmap(WIcon *icon, RImage *image)
        icon->pixmap = pixmap;
 }
 
-void wIconChangeTitle(WIcon *icon, char *new_title)
+void wIconChangeTitle(WIcon *icon, WWindow *wwin)
 {
+       if (!icon || !wwin)
+               return;
+
+       /* Remove the previous icon name */
        if (icon->icon_name != NULL)
                XFree(icon->icon_name);
 
-       icon->icon_name = new_title;
+       /* Set the new one */
+       icon->icon_name = wNETWMGetIconName(wwin->client_win);
 
-       /* If the title change, then we must re-create the icon with
-        * the new title, but we can still continue with the same icon
-        * therefore, we need only re-paint with the new title. */
-       wIconPaint(icon);
+       /* If not set, then try with wGetIconName */
+       if (!icon->icon_name)
+               wGetIconName(dpy, wwin->client_win, &icon->icon_name);
 }
 
 RImage *wIconValidateIconSize(RImage *icon, int max_size)
diff --git a/src/icon.h b/src/icon.h
index 099f592..d59ca94 100644
--- a/src/icon.h
+++ b/src/icon.h
@@ -60,7 +60,7 @@ void wIconDestroy(WIcon *icon);
 void wIconPaint(WIcon *icon);
 void wIconUpdate(WIcon *icon, RImage *image);
 void wIconSelect(WIcon *icon);
-void wIconChangeTitle(WIcon *icon, char *new_title);
+void wIconChangeTitle(WIcon *icon, WWindow *wwin);
 void update_icon_pixmap(WIcon *icon);
 void set_icon_for_window(WWindow *wwin, WIcon *icon);
 
diff --git a/src/window.h b/src/window.h
index c4148a3..4a3b81c 100644
--- a/src/window.h
+++ b/src/window.h
@@ -282,7 +282,6 @@ typedef struct WWindow {
                unsigned int net_handle_icon:1;
                unsigned int net_show_desktop:1;
                unsigned int net_has_title:1;   /* use netwm version of WM_NAME 
*/
-               unsigned int net_has_icon_title:1;
        } flags;                                /* state of the window */
 
        struct WIcon *icon;                     /* Window icon when miminized
diff --git a/src/wmspec.c b/src/wmspec.c
index c0600c5..4f0d4a8 100644
--- a/src/wmspec.c
+++ b/src/wmspec.c
@@ -1498,8 +1498,8 @@ void wNETWMCheckClientHintChange(WWindow *wwin, 
XPropertyEvent *event)
                        wfree(name);
        } else if (event->atom == net_wm_icon_name) {
                if (wwin->icon) {
-                       char *name = wNETWMGetIconName(wwin->client_win);
-                       wIconChangeTitle(wwin->icon, name);
+                       wIconChangeTitle(wwin->icon, wwin);
+                       wIconPaint(wwin->icon);
                }
        } else if (event->atom == net_wm_icon) {
                updateIconImage(wwin);
-- 
1.7.10.4


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

Reply via email to