summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon TURNEY <jon.turney@dronecode.org.uk>2011-11-07 20:54:10 +0000
committerJon TURNEY <jon.turney@dronecode.org.uk>2012-03-10 13:26:24 +0000
commit786a4bcc935fe5354e815487d6a6a3383006a9c7 (patch)
tree0f29a50ad21723c7e3957f2c48de4a939b4f39ac
parentefeb9f72d1b3f0a5a62d56bbb54489a100dbb925 (diff)
Add ' (on <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 avilable and useful to do so Refactor Xutf8TextPropertyToString() from GetWindowName() as a separate utility function Simplify GetWindowName() by moving UTF-8 to whcar conversion out to it's call site Add -hostintitle option to control this behaviour. Add documentation for this option to man page and -help text. Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
-rw-r--r--hw/xwin/InitOutput.c3
-rw-r--r--hw/xwin/man/XWin.man6
-rw-r--r--hw/xwin/winglobals.c1
-rw-r--r--hw/xwin/winglobals.h1
-rw-r--r--hw/xwin/winmultiwindowwm.c151
-rw-r--r--hw/xwin/winprocarg.c6
6 files changed, 118 insertions, 50 deletions
diff --git a/hw/xwin/InitOutput.c b/hw/xwin/InitOutput.c
index 691ec4f69..c86ca34e8 100644
--- a/hw/xwin/InitOutput.c
+++ b/hw/xwin/InitOutput.c
@@ -814,6 +814,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");
diff --git a/hw/xwin/man/XWin.man b/hw/xwin/man/XWin.man
index d03a36521..fdf7b60cf 100644
--- a/hw/xwin/man/XWin.man
+++ b/hw/xwin/man/XWin.man
@@ -163,6 +163,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
diff --git a/hw/xwin/winglobals.c b/hw/xwin/winglobals.c
index 888fcea5c..da8ea0b7d 100644
--- a/hw/xwin/winglobals.c
+++ b/hw/xwin/winglobals.c
@@ -77,6 +77,7 @@ Bool g_fNoHelpMessageBox = FALSE;
Bool g_fSoftwareCursor = FALSE;
Bool g_fSilentDupError = FALSE;
Bool g_fNativeGl = FALSE;
+Bool g_fHostInTitle = FALSE;
pthread_mutex_t g_pmTerminating = PTHREAD_MUTEX_INITIALIZER;
#ifdef XWIN_CLIPBOARD
diff --git a/hw/xwin/winglobals.h b/hw/xwin/winglobals.h
index 6b65667bf..fe647f70b 100644
--- a/hw/xwin/winglobals.h
+++ b/hw/xwin/winglobals.h
@@ -47,6 +47,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;
diff --git a/hw/xwin/winmultiwindowwm.c b/hw/xwin/winmultiwindowwm.c
index da5fd9b9c..abe35efb5 100644
--- a/hw/xwin/winmultiwindowwm.c
+++ b/hw/xwin/winmultiwindowwm.c
@@ -61,6 +61,7 @@
#include "window.h"
#include "pixmapstr.h"
#include "windowstr.h"
+#include "winglobals.h"
#include <shlwapi.h>
@@ -158,7 +159,7 @@ static Bool
InitQueue (WMMsgQueuePtr pQueue);
static void
-GetWindowName (Display * pDpy, Window iWin, wchar_t **ppName);
+GetWindowName (Display * pDpy, Window iWin, char **ppWindowName);
static int
SendXMessage (Display *pDisplay, Window iWin, Atom atmType, long nData);
@@ -425,30 +426,60 @@ InitQueue (WMMsgQueuePtr pQueue)
return TRUE;
}
+static
+char *Xutf8TextPropertyToString(Display *pDisplay, XTextProperty *xtp)
+{
+ int nNum;
+ char **ppList;
+ char *pszReturnData;
+
+ if (Xutf8TextPropertyToTextList (pDisplay, xtp, &ppList, &nNum) >= Success && nNum > 0 && *ppList)
+ {
+ int i;
+ int iLen = 0;
+
+ for (i = 0; i < nNum; i++)
+ iLen += strlen(ppList[i]);
+ pszReturnData = (char *) malloc (iLen + 1);
+ pszReturnData[0] = '\0';
+ for (i = 0; i < nNum; i++)
+ strcat (pszReturnData, ppList[i]);
+ if (ppList)
+ XFreeStringList (ppList);
+ }
+ else
+ {
+ pszReturnData = (char *) malloc (1);
+ pszReturnData[0] = '\0';
+ }
+
+ return pszReturnData;
+}
/*
* GetWindowName - Retrieve the title of an X Window
*/
static void
-GetWindowName (Display *pDisplay, Window iWin, wchar_t **ppName)
+GetWindowName (Display *pDisplay, Window iWin, char **ppWindowName)
{
- int nResult, nNum;
- char **ppList;
- char *pszReturnData;
- int iLen, i;
- XTextProperty xtpName;
-
+ int nResult;
+ XTextProperty xtpWindowName;
+ XTextProperty xtpClientMachine;
+ char *pszWindowName;
+ char *pszClientMachine;
+ char hostname[HOST_NAME_MAX + 1];
+
#if CYGMULTIWINDOW_DEBUG
ErrorF ("GetWindowName\n");
#endif
- /* Intialize ppName to NULL */
- *ppName = NULL;
+ /* Intialize ppWindowName to NULL */
+ *ppWindowName = NULL;
- /* Try to get --- */
- nResult = XGetWMName (pDisplay, iWin, &xtpName);
- if (!nResult || !xtpName.value || !xtpName.nitems)
+ /* Try to get window name */
+ nResult = XGetWMName (pDisplay, iWin, &xtpWindowName);
+ if (!nResult || !xtpWindowName.value || !xtpWindowName.nitems)
{
#if CYGMULTIWINDOW_DEBUG
ErrorF ("GetWindowName - XGetWMName failed. No name.\n");
@@ -456,29 +487,43 @@ GetWindowName (Display *pDisplay, Window iWin, wchar_t **ppName)
return;
}
- if (Xutf8TextPropertyToTextList (pDisplay, &xtpName, &ppList, &nNum) >= Success && nNum > 0 && *ppList)
- {
- iLen = 0;
- for (i = 0; i < nNum; i++) iLen += strlen(ppList[i]);
- pszReturnData = (char *) malloc (iLen + 1);
- pszReturnData[0] = '\0';
- for (i = 0; i < nNum; i++) strcat (pszReturnData, ppList[i]);
- if (ppList) XFreeStringList (ppList);
- }
- else
- {
- pszReturnData = (char *) malloc (1);
- pszReturnData[0] = '\0';
- }
- iLen = MultiByteToWideChar (CP_UTF8, 0, pszReturnData, -1, NULL, 0);
- *ppName = (wchar_t*)malloc(sizeof(wchar_t)*(iLen + 1));
- MultiByteToWideChar (CP_UTF8, 0, pszReturnData, -1, *ppName, iLen);
- XFree (xtpName.value);
- free (pszReturnData);
+ pszWindowName = Xutf8TextPropertyToString(pDisplay, &xtpWindowName);
+ XFree(xtpWindowName.value);
-#if CYGMULTIWINDOW_DEBUG
- ErrorF ("GetWindowName - Returning\n");
-#endif
+ 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...
+ */
+ if (strlen(pszClientMachine) &&
+ !gethostname(hostname, HOST_NAME_MAX + 1) &&
+ strcmp (hostname, pszClientMachine))
+ {
+ /* ... add ' (on <clientmachine>)' to end of window name */
+ *ppWindowName = malloc(strlen(pszWindowName) + strlen(pszClientMachine) + 7);
+ strcpy(*ppWindowName, pszWindowName);
+ strcat(*ppWindowName, " (on ");
+ strcat(*ppWindowName, pszClientMachine);
+ strcat(*ppWindowName, ")");
+
+ free(pszWindowName);
+ free(pszClientMachine);
+
+ return;
+ }
+ }
+ }
+
+ /* otherwise just return the window name */
+ *ppWindowName = pszWindowName;
}
@@ -511,7 +556,6 @@ SendXMessage (Display *pDisplay, Window iWin, Atom atmType, long nData)
static void
UpdateName (WMInfoPtr pWMInfo, Window iWindow)
{
- wchar_t *pszName;
Atom atmType;
int fmtRet;
unsigned long items, remain;
@@ -540,26 +584,33 @@ UpdateName (WMInfoPtr pWMInfo, Window iWindow)
XFree (retHwnd);
}
}
-
+
/* Some sanity checks */
if (!hWnd) return;
if (!IsWindow (hWnd)) return;
- /* Set the Windows window name */
- GetWindowName (pWMInfo->pDisplay, iWindow, &pszName);
- if (pszName)
+ /* If window isn't override-redirect */
+ XGetWindowAttributes (pWMInfo->pDisplay, iWindow, &attr);
+ if (!attr.override_redirect)
{
- /* Get the window attributes */
- XGetWindowAttributes (pWMInfo->pDisplay,
- iWindow,
- &attr);
- if (!attr.override_redirect)
- {
- SetWindowTextW (hWnd, pszName);
- winUpdateIcon (iWindow);
- }
+ char *pszWindowName;
+ /* Get the X windows window name */
+ GetWindowName (pWMInfo->pDisplay, iWindow, &pszWindowName);
- free (pszName);
+ if (pszWindowName)
+ {
+ /* Convert from UTF-8 to wide char */
+ int iLen = MultiByteToWideChar (CP_UTF8, 0, pszWindowName, -1, NULL, 0);
+ wchar_t *pwszWideWindowName = (wchar_t*)malloc(sizeof(wchar_t)*(iLen + 1));
+ MultiByteToWideChar (CP_UTF8, 0, pszWindowName, -1, pwszWideWindowName, iLen);
+
+ /* Set the Windows window name */
+ SetWindowTextW (hWnd, pwszWideWindowName);
+ winUpdateIcon (iWindow);
+
+ free (pwszWideWindowName);
+ free (pszWindowName);
+ }
}
}
diff --git a/hw/xwin/winprocarg.c b/hw/xwin/winprocarg.c
index 1de3dcb4c..95dc06b12 100644
--- a/hw/xwin/winprocarg.c
+++ b/hw/xwin/winprocarg.c
@@ -1147,6 +1147,12 @@ ddxProcessArgument (int argc, char *argv[], int i)
return 1;
}
+ if (IS_OPTION("-hostintitle"))
+ {
+ g_fHostInTitle = TRUE;
+ return 1;
+ }
+
return 0;
}