[WIN32K] Properly reference owner window

This commit is contained in:
Timo Kreuzer 2022-12-06 07:02:12 +01:00
parent 12ed9f30a7
commit e56da4854f
3 changed files with 30 additions and 16 deletions

View file

@ -1192,7 +1192,7 @@ VOID FASTCALL IntImeSetFutureOwner(PWND pImeWnd, PWND pwndOwner)
pwndParent = pwndNode->spwndParent;
if (!pwndParent || pwndOwner != pwndNode)
{
pImeWnd->spwndOwner = pwndNode;
WndSetOwner(pImeWnd, pwndNode);
return;
}
@ -1218,7 +1218,7 @@ VOID FASTCALL IntImeSetFutureOwner(PWND pImeWnd, PWND pwndOwner)
}
}
pImeWnd->spwndOwner = pwndNode;
WndSetOwner(pImeWnd, pwndNode);
}
// Get the last non-IME-like top-most window on the desktop.
@ -1401,7 +1401,7 @@ NtUserSetImeOwnerWindow(HWND hImeWnd, HWND hwndFocus)
}
}
pImeWnd->spwndOwner = pwndTopLevel;
WndSetOwner(pImeWnd, pwndTopLevel);
IntImeCheckTopmost(pImeWnd);
}
else
@ -1413,7 +1413,7 @@ NtUserSetImeOwnerWindow(HWND hImeWnd, HWND hwndFocus)
{
if (pwndActive && ptiIme == pwndActive->head.pti && !IS_WND_IMELIKE(pwndActive))
{
pImeWnd->spwndOwner = pwndActive;
WndSetOwner(pImeWnd, pwndActive);
}
else
{
@ -2127,7 +2127,7 @@ BOOL FASTCALL IntImeCanDestroyDefIME(PWND pImeWnd, PWND pwndTarget)
if (pImeWnd->spwndOwner && pwndTarget != pImeWnd->spwndOwner)
return FALSE;
pImeWnd->spwndOwner = NULL;
WndSetOwner(pImeWnd, NULL);
return TRUE;
}

View file

@ -588,6 +588,7 @@ LRESULT co_UserFreeWindow(PWND Window,
Window->style &= ~WS_VISIBLE;
Window->head.pti->cVisWindows--;
WndSetOwner(Window, NULL);
/* remove the window already at this point from the thread window list so we
don't get into trouble when destroying the thread windows while we're still
@ -662,7 +663,7 @@ LRESULT co_UserFreeWindow(PWND Window,
if (ThreadData->spwndDefaultIme &&
ThreadData->spwndDefaultIme->spwndOwner == Window)
{
ThreadData->spwndDefaultIme->spwndOwner = NULL;
WndSetOwner(ThreadData->spwndDefaultIme, NULL);
}
if (IS_IMM_MODE() && Window == ThreadData->spwndDefaultIme)
@ -1091,6 +1092,7 @@ IntProcessOwnerSwap(PWND Wnd, PWND WndNewOwner, PWND WndOldOwner)
// FIXME: System Tray checks.
}
static
HWND FASTCALL
IntSetOwner(HWND hWnd, HWND hWndNewOwner)
{
@ -1119,14 +1121,7 @@ IntSetOwner(HWND hWnd, HWND hWndNewOwner)
if (IntValidateOwnerDepth(Wnd, WndNewOwner))
{
if (WndNewOwner)
{
Wnd->spwndOwner= WndNewOwner;
}
else
{
Wnd->spwndOwner = NULL;
}
WndSetOwner(Wnd, WndNewOwner);
}
else
{
@ -1869,7 +1864,7 @@ PWND FASTCALL IntCreateWindow(CREATESTRUCTW* Cs,
*/
/* Remember, pWnd->head is setup in object.c ... */
pWnd->spwndParent = ParentWindow;
pWnd->spwndOwner = OwnerWindow;
WndSetOwner(pWnd, OwnerWindow);
pWnd->fnid = 0;
pWnd->spwndLastActive = pWnd;
// Ramp up compatible version sets.
@ -2825,7 +2820,7 @@ VOID FASTCALL IntDestroyOwnedWindows(PWND Window)
continue;
}
pWnd->spwndOwner = NULL;
WndSetOwner(pWnd, NULL);
if (IntWndBelongsToThread(pWnd, PsGetCurrentThreadWin32Thread()))
{
UserRefObjectCo(pWnd, &Ref); // Temp HACK?

View file

@ -124,4 +124,23 @@ BOOL FASTCALL IntBroadcastImeShowStatusChange(PWND pImeWnd, BOOL bShow);
VOID FASTCALL IntNotifyImeShowStatus(PWND pImeWnd);
VOID FASTCALL IntCheckImeShowStatusInThread(PWND pImeWnd);
static inline
VOID
WndSetOwner(_Inout_ PWND pwnd, _In_opt_ PWND pwndOwner)
{
/* First reference the new owner window */
if (pwndOwner != NULL)
{
UserReferenceObject(pwndOwner);
}
/* Now dereference the previous owner window */
if (pwnd->spwndOwner != NULL)
{
UserDereferenceObject(pwnd->spwndOwner);
}
pwnd->spwndOwner = pwndOwner;
}
/* EOF */