From 6aa43d356ca3c7ee44748212d9318f7005d2d140 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20=28kix=29?= Date: Mon, 8 Apr 2013 19:40:58 +0200 Subject: [PATCH] wIconChangeTitle rewritten 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. The functions that uses wIconChangeTitle (at client.c, icon.c and wmspec.c) uses always the value set by wNETWMGetIconName() first, else, the value set by wGetIconName(). This is the reason for the flag net_has_icon_title. Now the flag can be removed. --- src/client.c | 14 ++++---------- src/icon.c | 19 ++++++++++--------- src/icon.h | 2 +- src/window.h | 1 - src/wmspec.c | 4 ++-- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/client.c b/src/client.c index 9e7eb6af..cfe51815 100644 --- a/src/client.c +++ b/src/client.c @@ -322,16 +322,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); - } + /* Title has changed, update the icon title */ + if (wwin->icon) { + wIconChangeTitle(wwin->icon, wwin); + wIconPaint(wwin->icon); } break; diff --git a/src/icon.c b/src/icon.c index 166b8be9..7b71ab7b 100644 --- a/src/icon.c +++ b/src/icon.c @@ -134,12 +134,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; set_icon_image_from_database(icon, wwin->wm_instance, wwin->wm_class, NULL); @@ -305,13 +300,19 @@ 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 title */ if (icon->icon_name != NULL) XFree(icon->icon_name); - icon->icon_name = new_title; - wIconPaint(icon); + /* Set the new one, using two methods */ + icon->icon_name = wNETWMGetIconName(wwin->client_win); + 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 22e81f30..2c81ae70 100644 --- a/src/icon.h +++ b/src/icon.h @@ -61,7 +61,7 @@ void wIconDestroy(WIcon *icon); void wIconPaint(WIcon *icon); void wIconUpdate(WIcon *icon); void wIconSelect(WIcon *icon); -void wIconChangeTitle(WIcon *icon, char *new_title); +void wIconChangeTitle(WIcon *icon, WWindow *wwin); void update_icon_pixmap(WIcon *icon); Bool wIconChangeImageFile(WIcon *icon, char *file); diff --git a/src/window.h b/src/window.h index 2e24f49e..a95b9f79 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 c894fab3..255982e7 100644 --- a/src/wmspec.c +++ b/src/wmspec.c @@ -1470,8 +1470,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); -- 2.11.4.GIT