diff options
author | Jon TURNEY <jon.turney@dronecode.org.uk> | 2015-04-28 16:04:40 +0100 |
---|---|---|
committer | Jon TURNEY <jon.turney@dronecode.org.uk> | 2015-04-29 12:26:05 +0100 |
commit | 196734d400bc480c5098835b83218bd47c8edc84 (patch) | |
tree | 53a07c8efcf1cc76126e4b4dccf351e4602510e6 | |
parent | 064382391c7a81632acc577c9df4312288c212e1 (diff) |
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.
-rw-r--r-- | hw/xwin/winmultiwindowwm.c | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/hw/xwin/winmultiwindowwm.c b/hw/xwin/winmultiwindowwm.c index 589b6e06d..e2bd7e127 100644 --- a/hw/xwin/winmultiwindowwm.c +++ b/hw/xwin/winmultiwindowwm.c @@ -503,27 +503,39 @@ GetWindowName(Display * pDisplay, Window iWin, char **ppWindowName, Atom atmNetW XFree(xtpWindowName.value); } + /* return the window name, unless... */ + *ppWindowName = pszWindowName; + if (g_fHostInTitle) { XTextProperty xtpClientMachine; - char *pszClientMachine; - char hostname[HOST_NAME_MAX + 1]; /* Try to get client machine name */ nResult = XGetWMClientMachine(pDisplay, iWin, &xtpClientMachine); if (nResult && xtpClientMachine.value && xtpClientMachine.nitems) { + char *pszClientMachine; + char *pszClientHostname; + char *dot; + char hostname[HOST_NAME_MAX + 1]; + pszClientMachine = Xutf8TextPropertyToString(pDisplay, &xtpClientMachine); XFree(xtpClientMachine.value); + /* 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 - and it's not the local host name + If we have a client machine hostname + and it's not the local hostname and it's not already in the window title... */ - if (strlen(pszClientMachine) && + if (strlen(pszClientHostname) && !gethostname(hostname, HOST_NAME_MAX + 1) && - strcmp(hostname, pszClientMachine) && - (strstr(pszWindowName, pszClientMachine) == 0)) { + strcmp(hostname, pszClientHostname) && + (strstr(pszWindowName, pszClientHostname) == 0)) { /* ... add '@<clientmachine>' to end of window name */ *ppWindowName = malloc(strlen(pszWindowName) + @@ -533,15 +545,12 @@ GetWindowName(Display * pDisplay, Window iWin, char **ppWindowName, Atom atmNetW strcat(*ppWindowName, pszClientMachine); free(pszWindowName); - free(pszClientMachine); - - return; } + + free(pszClientMachine); + free(pszClientHostname); } } - - /* otherwise just return the window name */ - *ppWindowName = pszWindowName; } /* |