hw/xwin: Consolidate duplicated code as getHwnd() function

Consolidate code to find the native HWND of an X window, stored in the _WINDOWSWM_NATIVE_HWND
property, duplicated in UpdateName() and PreserveWin32Stack() as getHwnd()

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
This commit is contained in:
Jon TURNEY 2012-07-05 18:00:06 +01:00
parent df7636dddb
commit c98471fad7

View File

@ -477,23 +477,23 @@ SendXMessage(Display * pDisplay, Window iWin, Atom atmType, long nData)
}
/*
* Updates the name of a HWND according to its X WM_NAME property
* See if we can get the stored HWND for this window...
*/
static void
UpdateName(WMInfoPtr pWMInfo, Window iWindow)
static HWND
getHwnd(WMInfoPtr pWMInfo, Window iWindow)
{
wchar_t *pszName;
Atom atmType;
int fmtRet;
unsigned long items, remain;
HWND *retHwnd, hWnd;
XWindowAttributes attr;
HWND *retHwnd, hWnd = NULL;
hWnd = 0;
/* See if we can get the cached HWND for this window... */
if (XGetWindowProperty(pWMInfo->pDisplay, iWindow, pWMInfo->atmPrivMap, 0, 1, False, XA_INTEGER, //pWMInfo->atmPrivMap,
if (XGetWindowProperty(pWMInfo->pDisplay,
iWindow,
pWMInfo->atmPrivMap,
0,
1,
False,
XA_INTEGER,
&atmType,
&fmtRet,
&items,
@ -506,8 +506,26 @@ UpdateName(WMInfoPtr pWMInfo, Window iWindow)
/* Some sanity checks */
if (!hWnd)
return;
return NULL;
if (!IsWindow(hWnd))
return NULL;
return hWnd;
}
/*
* Updates the name of a HWND according to its X WM_NAME property
*/
static void
UpdateName(WMInfoPtr pWMInfo, Window iWindow)
{
wchar_t *pszName;
HWND hWnd;
XWindowAttributes attr;
hWnd = getHwnd(pWMInfo, iWindow);
if (!hWnd)
return;
/* Set the Windows window name */
@ -532,27 +550,12 @@ UpdateName(WMInfoPtr pWMInfo, Window iWindow)
static void
PreserveWin32Stack(WMInfoPtr pWMInfo, Window iWindow, UINT direction)
{
Atom atmType;
int fmtRet;
unsigned long items, remain;
HWND hWnd, *retHwnd;
HWND hWnd;
DWORD myWinProcID, winProcID;
Window xWindow;
WINDOWPLACEMENT wndPlace;
hWnd = NULL;
/* See if we can get the cached HWND for this window... */
if (XGetWindowProperty(pWMInfo->pDisplay, iWindow, pWMInfo->atmPrivMap, 0, 1, False, XA_INTEGER, //pWMInfo->atmPrivMap,
&atmType,
&fmtRet,
&items,
&remain, (unsigned char **) &retHwnd) == Success) {
if (retHwnd) {
hWnd = *retHwnd;
XFree(retHwnd);
}
}
hWnd = getHwnd(pWMInfo, iWindow);
if (!hWnd)
return;