Commit b38e1dec authored by Ulrich Weigand's avatar Ulrich Weigand Committed by Alexandre Julliard

Better implementation of [GS]etForegroundWindow.

Fixed focus handling on inter-thread activation. Adapted FocusIn/Out event handling to per-queue focus.
parent 85bcb2e1
...@@ -899,17 +899,27 @@ BOOL16 WINAPI SetForegroundWindow16( HWND16 hwnd ) ...@@ -899,17 +899,27 @@ BOOL16 WINAPI SetForegroundWindow16( HWND16 hwnd )
*/ */
HWND WINAPI GetForegroundWindow(void) HWND WINAPI GetForegroundWindow(void)
{ {
return GetActiveWindow(); HWND hwndActive = 0;
}
/* Get the foreground window (active window of hActiveQueue) */
if ( hActiveQueue )
{
MESSAGEQUEUE *pActiveQueue = QUEUE_Lock( hActiveQueue );
if ( pActiveQueue )
hwndActive = PERQDATA_GetActiveWnd( pActiveQueue->pQData );
QUEUE_Unlock( pActiveQueue );
}
return hwndActive;
}
/******************************************************************* /*******************************************************************
* SetForegroundWindow (USER32.482) * SetForegroundWindow (USER32.482)
*/ */
BOOL WINAPI SetForegroundWindow( HWND hwnd ) BOOL WINAPI SetForegroundWindow( HWND hwnd )
{ {
SetActiveWindow( hwnd ); return WINPOS_ChangeActiveWindow( hwnd, FALSE );
return TRUE;
} }
...@@ -1643,6 +1653,8 @@ BOOL WINPOS_SetActiveWindow( HWND hWnd, BOOL fMouse, BOOL fChangeFocus) ...@@ -1643,6 +1653,8 @@ BOOL WINPOS_SetActiveWindow( HWND hWnd, BOOL fMouse, BOOL fChangeFocus)
HWND hwndActive = 0; HWND hwndActive = 0;
BOOL bRet = 0; BOOL bRet = 0;
TRACE( win, "(%04x, %d, %d)\n", hWnd, fMouse, fChangeFocus );
/* Get current active window from the active queue */ /* Get current active window from the active queue */
if ( hActiveQueue ) if ( hActiveQueue )
{ {
...@@ -1784,7 +1796,7 @@ BOOL WINPOS_SetActiveWindow( HWND hWnd, BOOL fMouse, BOOL fChangeFocus) ...@@ -1784,7 +1796,7 @@ BOOL WINPOS_SetActiveWindow( HWND hWnd, BOOL fMouse, BOOL fChangeFocus)
} }
WIN_ReleaseDesktop(); WIN_ReleaseDesktop();
if (!IsWindow(hWnd)) goto CLEANUP; if (hWnd && !IsWindow(hWnd)) goto CLEANUP;
} }
if (hWnd) if (hWnd)
...@@ -1808,13 +1820,27 @@ BOOL WINPOS_SetActiveWindow( HWND hWnd, BOOL fMouse, BOOL fChangeFocus) ...@@ -1808,13 +1820,27 @@ BOOL WINPOS_SetActiveWindow( HWND hWnd, BOOL fMouse, BOOL fChangeFocus)
} }
/* change focus if possible */ /* change focus if possible */
if( fChangeFocus && GetFocus() ) if ( fChangeFocus )
if( WIN_GetTopParent(GetFocus()) != hwndActive ) {
FOCUS_SwitchFocus( pNewActiveQueue, GetFocus(), if ( pNewActiveQueue )
(wndPtr && (wndPtr->dwStyle & WS_MINIMIZE))? {
0: HWND hOldFocus = PERQDATA_GetFocusWnd( pNewActiveQueue->pQData );
hwndActive
); if ( WIN_GetTopParent( hOldFocus ) != hwndActive )
FOCUS_SwitchFocus( pNewActiveQueue, hOldFocus,
(wndPtr && (wndPtr->dwStyle & WS_MINIMIZE))?
0 : hwndActive );
}
if ( pOldActiveQueue &&
( !pNewActiveQueue ||
pNewActiveQueue->pQData != pOldActiveQueue->pQData ) )
{
HWND hOldFocus = PERQDATA_GetFocusWnd( pOldActiveQueue->pQData );
if ( hOldFocus )
FOCUS_SwitchFocus( pOldActiveQueue, hOldFocus, 0 );
}
}
if( !hwndPrevActive && wndPtr ) if( !hwndPrevActive && wndPtr )
(*wndPtr->pDriver->pForceWindowRaise)(wndPtr); (*wndPtr->pDriver->pForceWindowRaise)(wndPtr);
......
...@@ -660,18 +660,12 @@ static void EVENT_ButtonRelease( HWND hWnd, XButtonEvent *event ) ...@@ -660,18 +660,12 @@ static void EVENT_ButtonRelease( HWND hWnd, XButtonEvent *event )
*/ */
static void EVENT_FocusIn( HWND hWnd, XFocusChangeEvent *event ) static void EVENT_FocusIn( HWND hWnd, XFocusChangeEvent *event )
{ {
if (Options.managed) EVENT_QueryZOrder( hWnd ); if (event->detail != NotifyPointer)
if (hWnd != GetForegroundWindow())
if (event->detail != NotifyPointer)
{
if (hWnd != GetActiveWindow())
{ {
WINPOS_ChangeActiveWindow( hWnd, FALSE ); SetForegroundWindow( hWnd );
X11DRV_KEYBOARD_UpdateState(); X11DRV_KEYBOARD_UpdateState();
} }
if ((hWnd != GetFocus()) && !IsChild( hWnd, GetFocus()))
SetFocus( hWnd );
}
} }
...@@ -683,15 +677,11 @@ static void EVENT_FocusIn( HWND hWnd, XFocusChangeEvent *event ) ...@@ -683,15 +677,11 @@ static void EVENT_FocusIn( HWND hWnd, XFocusChangeEvent *event )
static void EVENT_FocusOut( HWND hWnd, XFocusChangeEvent *event ) static void EVENT_FocusOut( HWND hWnd, XFocusChangeEvent *event )
{ {
if (event->detail != NotifyPointer) if (event->detail != NotifyPointer)
{ if (hWnd == GetForegroundWindow())
if (hWnd == GetActiveWindow())
{ {
SendMessageA( hWnd, WM_CANCELMODE, 0, 0 ); SendMessageA( hWnd, WM_CANCELMODE, 0, 0 );
WINPOS_ChangeActiveWindow( 0, FALSE ); SetForegroundWindow( 0 );
} }
if ((hWnd == GetFocus()) || IsChild( hWnd, GetFocus()))
SetFocus( 0 );
}
} }
/********************************************************************** /**********************************************************************
...@@ -699,13 +689,13 @@ static void EVENT_FocusOut( HWND hWnd, XFocusChangeEvent *event ) ...@@ -699,13 +689,13 @@ static void EVENT_FocusOut( HWND hWnd, XFocusChangeEvent *event )
*/ */
BOOL X11DRV_EVENT_CheckFocus(void) BOOL X11DRV_EVENT_CheckFocus(void)
{ {
WND* pWnd; HWND hWnd;
Window xW; Window xW;
int state; int state;
TSXGetInputFocus(display, &xW, &state); TSXGetInputFocus(display, &xW, &state);
if( xW == None || if( xW == None ||
TSXFindContext(display, xW, winContext, (char **)&pWnd) ) TSXFindContext(display, xW, winContext, (char **)&hWnd) )
return FALSE; return FALSE;
return TRUE; return TRUE;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment