summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon TURNEY <jon.turney@dronecode.org.uk>2012-07-20 13:51:35 +0100
committerJon TURNEY <jon.turney@dronecode.org.uk>2012-08-03 22:46:18 +0100
commit2a47c91eb382d1ff0fb009a39efa7dc9c6fd5112 (patch)
treebacb8b466835689209baea7261602f42c74c77d5
parentafa53fe7cffd430cf11f25ca818cb955a78c0c1c (diff)
hw/xwin: Refactor Xutf8TextPropertyToString() from GetWindowName() as a separate utility function
Simplify GetWindowName() by moving UTF-8 to wchar conversion out to it's call site. This allows us to do extra processing on the window name in future. Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk> Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
-rw-r--r--hw/xwin/winmultiwindowwm.c105
1 files changed, 62 insertions, 43 deletions
diff --git a/hw/xwin/winmultiwindowwm.c b/hw/xwin/winmultiwindowwm.c
index 76b46837c..754b53036 100644
--- a/hw/xwin/winmultiwindowwm.c
+++ b/hw/xwin/winmultiwindowwm.c
@@ -151,7 +151,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);
@@ -399,38 +399,19 @@ InitQueue(WMMsgQueuePtr pQueue)
return TRUE;
}
-/*
- * GetWindowName - Retrieve the title of an X Window
- */
-
-static void
-GetWindowName(Display * pDisplay, Window iWin, wchar_t ** ppName)
+static
+char *
+Xutf8TextPropertyToString(Display * pDisplay, XTextProperty * xtp)
{
- int nResult, nNum;
+ int nNum;
char **ppList;
char *pszReturnData;
- int iLen, i;
- XTextProperty xtpName;
-
-#if CYGMULTIWINDOW_DEBUG
- ErrorF("GetWindowName\n");
-#endif
- /* Intialize ppName to NULL */
- *ppName = NULL;
+ if (Xutf8TextPropertyToTextList(pDisplay, xtp, &ppList, &nNum) >= Success &&
+ nNum > 0 && *ppList) {
+ int i;
+ int iLen = 0;
- /* Try to get --- */
- nResult = XGetWMName(pDisplay, iWin, &xtpName);
- if (!nResult || !xtpName.value || !xtpName.nitems) {
-#if CYGMULTIWINDOW_DEBUG
- ErrorF("GetWindowName - XGetWMName failed. No name.\n");
-#endif
- 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);
@@ -444,15 +425,40 @@ GetWindowName(Display * pDisplay, Window iWin, wchar_t ** ppName)
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);
+ return pszReturnData;
+}
+
+/*
+ * GetWindowName - Retrieve the title of an X Window
+ */
+
+static void
+GetWindowName(Display * pDisplay, Window iWin, char **ppWindowName)
+{
+ int nResult;
+ XTextProperty xtpWindowName;
+ char *pszWindowName;
+
+#if CYGMULTIWINDOW_DEBUG
+ ErrorF("GetWindowName\n");
+#endif
+
+ /* Intialize ppWindowName to NULL */
+ *ppWindowName = NULL;
+
+ /* Try to get window name */
+ nResult = XGetWMName(pDisplay, iWin, &xtpWindowName);
+ if (!nResult || !xtpWindowName.value || !xtpWindowName.nitems) {
#if CYGMULTIWINDOW_DEBUG
- ErrorF("GetWindowName - Returning\n");
+ ErrorF("GetWindowName - XGetWMName failed. No name.\n");
#endif
+ return;
+ }
+
+ pszWindowName = Xutf8TextPropertyToString(pDisplay, &xtpWindowName);
+ XFree(xtpWindowName.value);
+ *ppWindowName = pszWindowName;
}
/*
@@ -528,17 +534,30 @@ UpdateName(WMInfoPtr pWMInfo, Window iWindow)
if (!hWnd)
return;
- /* Set the Windows window name */
- GetWindowName(pWMInfo->pDisplay, iWindow, &pszName);
- if (pszName) {
- /* Get the window attributes */
- XGetWindowAttributes(pWMInfo->pDisplay, iWindow, &attr);
- if (!attr.override_redirect) {
- SetWindowTextW(hWnd, pszName);
+ /* If window isn't override-redirect */
+ XGetWindowAttributes(pWMInfo->pDisplay, iWindow, &attr);
+ if (!attr.override_redirect) {
+ char *pszWindowName;
+
+ /* Get the X windows window name */
+ GetWindowName(pWMInfo->pDisplay, iWindow, &pszWindowName);
+
+ 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(pszName);
+ free(pwszWideWindowName);
+ free(pszWindowName);
+ }
}
}