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>
This commit is contained in:
parent
afa53fe7cf
commit
2a47c91eb3
|
@ -151,7 +151,7 @@ static Bool
|
||||||
InitQueue(WMMsgQueuePtr pQueue);
|
InitQueue(WMMsgQueuePtr pQueue);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
GetWindowName(Display * pDpy, Window iWin, wchar_t ** ppName);
|
GetWindowName(Display * pDpy, Window iWin, char **ppWindowName);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
SendXMessage(Display * pDisplay, Window iWin, Atom atmType, long nData);
|
SendXMessage(Display * pDisplay, Window iWin, Atom atmType, long nData);
|
||||||
|
@ -399,38 +399,19 @@ InitQueue(WMMsgQueuePtr pQueue)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static
|
||||||
* GetWindowName - Retrieve the title of an X Window
|
char *
|
||||||
*/
|
Xutf8TextPropertyToString(Display * pDisplay, XTextProperty * xtp)
|
||||||
|
|
||||||
static void
|
|
||||||
GetWindowName(Display * pDisplay, Window iWin, wchar_t ** ppName)
|
|
||||||
{
|
{
|
||||||
int nResult, nNum;
|
int nNum;
|
||||||
char **ppList;
|
char **ppList;
|
||||||
char *pszReturnData;
|
char *pszReturnData;
|
||||||
int iLen, i;
|
|
||||||
XTextProperty xtpName;
|
|
||||||
|
|
||||||
#if CYGMULTIWINDOW_DEBUG
|
if (Xutf8TextPropertyToTextList(pDisplay, xtp, &ppList, &nNum) >= Success &&
|
||||||
ErrorF("GetWindowName\n");
|
nNum > 0 && *ppList) {
|
||||||
#endif
|
int i;
|
||||||
|
int iLen = 0;
|
||||||
|
|
||||||
/* Intialize ppName to NULL */
|
|
||||||
*ppName = NULL;
|
|
||||||
|
|
||||||
/* 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++)
|
for (i = 0; i < nNum; i++)
|
||||||
iLen += strlen(ppList[i]);
|
iLen += strlen(ppList[i]);
|
||||||
pszReturnData = (char *) malloc(iLen + 1);
|
pszReturnData = (char *) malloc(iLen + 1);
|
||||||
|
@ -444,15 +425,40 @@ GetWindowName(Display * pDisplay, Window iWin, wchar_t ** ppName)
|
||||||
pszReturnData = (char *) malloc(1);
|
pszReturnData = (char *) malloc(1);
|
||||||
pszReturnData[0] = '\0';
|
pszReturnData[0] = '\0';
|
||||||
}
|
}
|
||||||
iLen = MultiByteToWideChar(CP_UTF8, 0, pszReturnData, -1, NULL, 0);
|
|
||||||
*ppName = (wchar_t *) malloc(sizeof(wchar_t) * (iLen + 1));
|
return pszReturnData;
|
||||||
MultiByteToWideChar(CP_UTF8, 0, pszReturnData, -1, *ppName, iLen);
|
}
|
||||||
XFree(xtpName.value);
|
|
||||||
free(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
|
#if CYGMULTIWINDOW_DEBUG
|
||||||
ErrorF("GetWindowName - Returning\n");
|
ErrorF("GetWindowName\n");
|
||||||
#endif
|
#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 - 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)
|
if (!hWnd)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Set the Windows window name */
|
/* If window isn't override-redirect */
|
||||||
GetWindowName(pWMInfo->pDisplay, iWindow, &pszName);
|
XGetWindowAttributes(pWMInfo->pDisplay, iWindow, &attr);
|
||||||
if (pszName) {
|
if (!attr.override_redirect) {
|
||||||
/* Get the window attributes */
|
char *pszWindowName;
|
||||||
XGetWindowAttributes(pWMInfo->pDisplay, iWindow, &attr);
|
|
||||||
if (!attr.override_redirect) {
|
|
||||||
SetWindowTextW(hWnd, pszName);
|
|
||||||
winUpdateIcon(iWindow);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(pszName);
|
/* 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(pwszWideWindowName);
|
||||||
|
free(pszWindowName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue