hw/xwin: Check for just the hostname in window title

When -hostintitle is enabled, only use the hostname, not a FQDN from
WM_CLIENT_MACHINE, when checking if the window title already contains it

Also restructure GetWindowName() to fix a potential memory leak.

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
This commit is contained in:
Jon Turney 2015-04-28 16:04:40 +01:00
parent c05c4360ee
commit 17c8bf348e

View File

@ -416,27 +416,39 @@ GetWindowName(WMInfoPtr pWMInfo, xcb_window_t iWin, char **ppWindowName)
xcb_icccm_get_text_property_reply_wipe(&reply); xcb_icccm_get_text_property_reply_wipe(&reply);
} }
/* return the window name, unless... */
*ppWindowName = pszWindowName;
if (g_fHostInTitle) { if (g_fHostInTitle) {
char *pszClientMachine;
char hostname[HOST_NAME_MAX + 1];
xcb_get_property_cookie_t cookie; xcb_get_property_cookie_t cookie;
xcb_icccm_get_text_property_reply_t reply; xcb_icccm_get_text_property_reply_t reply;
/* Try to get client machine name */ /* Try to get client machine name */
cookie = xcb_icccm_get_wm_client_machine(conn, iWin); cookie = xcb_icccm_get_wm_client_machine(conn, iWin);
if (xcb_icccm_get_wm_client_machine_reply(conn, cookie, &reply, NULL)) { if (xcb_icccm_get_wm_client_machine_reply(conn, cookie, &reply, NULL)) {
char *pszClientMachine;
char *pszClientHostname;
char *dot;
char hostname[HOST_NAME_MAX + 1];
pszClientMachine = Xutf8TextPropertyToString(pWMInfo, &reply); pszClientMachine = Xutf8TextPropertyToString(pWMInfo, &reply);
xcb_icccm_get_text_property_reply_wipe(&reply); xcb_icccm_get_text_property_reply_wipe(&reply);
/* If client machine name looks like a FQDN, find the hostname */
pszClientHostname = strdup(pszClientMachine);
dot = strchr(pszClientHostname, '.');
if (dot)
*dot = '\0';
/* /*
If we have a client machine name If we have a client machine hostname
and it's not the local host name and it's not the local hostname
and it's not already in the window title... and it's not already in the window title...
*/ */
if (strlen(pszClientMachine) && if (strlen(pszClientHostname) &&
!gethostname(hostname, HOST_NAME_MAX + 1) && !gethostname(hostname, HOST_NAME_MAX + 1) &&
strcmp(hostname, pszClientMachine) && strcmp(hostname, pszClientHostname) &&
(strstr(pszWindowName, pszClientMachine) == 0)) { (strstr(pszWindowName, pszClientHostname) == 0)) {
/* ... add '@<clientmachine>' to end of window name */ /* ... add '@<clientmachine>' to end of window name */
*ppWindowName = *ppWindowName =
malloc(strlen(pszWindowName) + malloc(strlen(pszWindowName) +
@ -446,15 +458,12 @@ GetWindowName(WMInfoPtr pWMInfo, xcb_window_t iWin, char **ppWindowName)
strcat(*ppWindowName, pszClientMachine); strcat(*ppWindowName, pszClientMachine);
free(pszWindowName); free(pszWindowName);
free(pszClientMachine);
return;
} }
free(pszClientMachine);
free(pszClientHostname);
} }
} }
/* otherwise just return the window name */
*ppWindowName = pszWindowName;
} }
/* /*