hw/xwin: Add '@<WM_CLIENT_MACHINE>' to window name when it's useful to do so
authorJon TURNEY <jon.turney@dronecode.org.uk>
Mon, 7 Nov 2011 20:54:10 +0000 (20:54 +0000)
committerJon TURNEY <jon.turney@dronecode.org.uk>
Sat, 22 Mar 2014 18:55:47 +0000 (18:55 +0000)
Enhance GetWindowName() so it appends the result of XGetWMClientMachine() when
it is available and useful to do so

Add -hostintitle option to control this behaviour.  Add documentation for this
option to man page and -help text.

Also, fix warning in UpdateName()

v2: Provide a HOST_NAME_MAX definition for MinGW
v3: Use '@host' rather than ' (on host)'. Don't add host if it's already in the
title.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Yaakov Selkowitz <yselkowitz@users.sourceforge.net>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin/InitOutput.c
hw/xwin/man/XWin.man
hw/xwin/winglobals.c
hw/xwin/winglobals.h
hw/xwin/winmultiwindowwm.c
hw/xwin/winprocarg.c

index 04015cd..b3ff7c0 100644 (file)
@@ -786,6 +786,9 @@ winUseMsg(void)
 
     ErrorF("-fullscreen\n" "\tRun the server in fullscreen mode.\n");
 
+    ErrorF("-hostintitle\n"
+           "\tIn multiwindow mode, add remote host names to window titles.\n");
+
     ErrorF("-ignoreinput\n" "\tIgnore keyboard and mouse input.\n");
 
 #ifdef XWIN_MULTIWINDOWEXTWM
index 18ee667..c71f6a1 100644 (file)
@@ -165,6 +165,12 @@ The maximum dimensions of the screen are the dimensions of the \fIWindows\fP vir
 on its own is equivalent to \fB\-resize=randr\fP
 .RE
 
+.SH OPTIONS FOR MULTIWINDOW MODE
+.TP 8
+.B \-hostintitle
+Add the host name to the window title for X applications which are running
+on remote hosts, when that information is available and it's useful to do so.
+
 .SH OPTIONS CONTROLLING WINDOWS INTEGRATION
 .TP 8
 .B \-[no]clipboard
index d281322..b9ad294 100644 (file)
@@ -78,6 +78,7 @@ Bool g_fNoHelpMessageBox = FALSE;
 Bool g_fSoftwareCursor = FALSE;
 Bool g_fSilentDupError = FALSE;
 Bool g_fNativeGl = TRUE;
+Bool g_fHostInTitle = FALSE;
 pthread_mutex_t g_pmTerminating = PTHREAD_MUTEX_INITIALIZER;
 
 #ifdef XWIN_CLIPBOARD
index 58a919c..60c00da 100644 (file)
@@ -54,6 +54,7 @@ extern Bool g_fXdmcpEnabled;
 extern Bool g_fNoHelpMessageBox;
 extern Bool g_fSilentDupError;
 extern Bool g_fNativeGl;
+extern Bool g_fHostInTitle;
 
 extern HWND g_hDlgDepthChange;
 extern HWND g_hDlgExit;
index ec577a7..618e381 100644 (file)
@@ -60,6 +60,7 @@
 #include "window.h"
 #include "pixmapstr.h"
 #include "windowstr.h"
+#include "winglobals.h"
 
 #ifdef XWIN_MULTIWINDOWEXTWM
 #include <X11/extensions/windowswmstr.h>
 #define WINDOWSWM_NATIVE_HWND "_WINDOWSWM_NATIVE_HWND"
 #endif
 
+#ifndef HOST_NAME_MAX
+#define HOST_NAME_MAX 255
+#endif
+
 extern void winDebug(const char *format, ...);
 extern void winReshapeMultiWindow(WindowPtr pWin);
 extern void winUpdateRgnMultiWindow(WindowPtr pWin);
@@ -430,7 +435,10 @@ GetWindowName(Display * pDisplay, Window iWin, char **ppWindowName)
 {
     int nResult;
     XTextProperty xtpWindowName;
+    XTextProperty xtpClientMachine;
     char *pszWindowName;
+    char *pszClientMachine;
+    char hostname[HOST_NAME_MAX + 1];
 
 #if CYGMULTIWINDOW_DEBUG
     ErrorF("GetWindowName\n");
@@ -450,6 +458,41 @@ GetWindowName(Display * pDisplay, Window iWin, char **ppWindowName)
 
     pszWindowName = Xutf8TextPropertyToString(pDisplay, &xtpWindowName);
     XFree(xtpWindowName.value);
+
+    if (g_fHostInTitle) {
+        /* Try to get client machine name */
+        nResult = XGetWMClientMachine(pDisplay, iWin, &xtpClientMachine);
+        if (nResult && xtpClientMachine.value && xtpClientMachine.nitems) {
+            pszClientMachine =
+                Xutf8TextPropertyToString(pDisplay, &xtpClientMachine);
+            XFree(xtpClientMachine.value);
+
+            /*
+               If we have a client machine name
+               and it's not the local host name
+               and it's not already in the window title...
+             */
+            if (strlen(pszClientMachine) &&
+                !gethostname(hostname, HOST_NAME_MAX + 1) &&
+                strcmp(hostname, pszClientMachine) &&
+                (strstr(pszWindowName, pszClientMachine) == 0)) {
+                /* ... add '@<clientmachine>' to end of window name */
+                *ppWindowName =
+                    malloc(strlen(pszWindowName) +
+                           strlen(pszClientMachine) + 2);
+                strcpy(*ppWindowName, pszWindowName);
+                strcat(*ppWindowName, "@");
+                strcat(*ppWindowName, pszClientMachine);
+
+                free(pszWindowName);
+                free(pszClientMachine);
+
+                return;
+            }
+        }
+    }
+
+    /* otherwise just return the window name */
     *ppWindowName = pszWindowName;
 }
 
index 858be4a..f2bf05b 100644 (file)
@@ -1074,6 +1074,11 @@ ddxProcessArgument(int argc, char *argv[], int i)
         return 1;
     }
 
+    if (IS_OPTION("-hostintitle")) {
+        g_fHostInTitle = TRUE;
+        return 1;
+    }
+
     return 0;
 }