hw/xwin: Add '@<WM_CLIENT_MACHINE>' to window name when it's useful to do so

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>
This commit is contained in:
Jon TURNEY 2011-11-07 20:54:10 +00:00
parent 6804acfe4f
commit 03e1cc6f25
6 changed files with 59 additions and 0 deletions

View 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

View 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

View 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

View 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;

View 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>
@ -69,6 +70,10 @@
#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;
}

View 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;
}