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 HWND
static void getHwnd(WMInfoPtr pWMInfo, Window iWindow)
UpdateName(WMInfoPtr pWMInfo, Window iWindow)
{ {
wchar_t *pszName;
Atom atmType; Atom atmType;
int fmtRet; int fmtRet;
unsigned long items, remain; unsigned long items, remain;
HWND *retHwnd, hWnd; HWND *retHwnd, hWnd = NULL;
XWindowAttributes attr;
hWnd = 0; if (XGetWindowProperty(pWMInfo->pDisplay,
iWindow,
/* See if we can get the cached HWND for this window... */ pWMInfo->atmPrivMap,
if (XGetWindowProperty(pWMInfo->pDisplay, iWindow, pWMInfo->atmPrivMap, 0, 1, False, XA_INTEGER, //pWMInfo->atmPrivMap, 0,
1,
False,
XA_INTEGER,
&atmType, &atmType,
&fmtRet, &fmtRet,
&items, &items,
@ -506,8 +506,26 @@ UpdateName(WMInfoPtr pWMInfo, Window iWindow)
/* Some sanity checks */ /* Some sanity checks */
if (!hWnd) if (!hWnd)
return; return NULL;
if (!IsWindow(hWnd)) 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; return;
/* Set the Windows window name */ /* Set the Windows window name */
@ -532,27 +550,12 @@ UpdateName(WMInfoPtr pWMInfo, Window iWindow)
static void static void
PreserveWin32Stack(WMInfoPtr pWMInfo, Window iWindow, UINT direction) PreserveWin32Stack(WMInfoPtr pWMInfo, Window iWindow, UINT direction)
{ {
Atom atmType; HWND hWnd;
int fmtRet;
unsigned long items, remain;
HWND hWnd, *retHwnd;
DWORD myWinProcID, winProcID; DWORD myWinProcID, winProcID;
Window xWindow; Window xWindow;
WINDOWPLACEMENT wndPlace; WINDOWPLACEMENT wndPlace;
hWnd = NULL; hWnd = getHwnd(pWMInfo, iWindow);
/* 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);
}
}
if (!hWnd) if (!hWnd)
return; return;