Fix window activation in QWindowsWindow::setCustomMargins()

Currently, code paths that call QWindowsWindow:setCustomMargins()
automatically also activate the window (=give the window focus).
The reason for this is the call of SetWindowPos (Windows API)
without the flag SWP_NOACTIVATE.

From the Windows API documentation about SetWindowPos() about the
flag SWP_NOACTIVATE:

   Does not activate the window. If this flag is not set, the
   window is activated and moved to the top of either the
   topmost or non-topmost group (depending on the setting of
   the hWndInsertAfter parameter).

It seems the flag SWP_NOACTIVATE is accidentally missing in the
call of SetWindowPos() in setCustomMargins(), especially since
the flag is present in pretty much all other calls of SetWindowPos().

The obvious fix is to add the flag SWP_NOACTIVATE to the call
of SetWindowPos() in setCustomMargins().

So far, this issue exists for a long time, an was possibly
introduced with commit f5fd534603, where setCustomMargins()
was initially added.

Change-Id: Id3f058f8762df17eb3f033ab0b3e1791283937fc
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
Dominik Haumann 2018-01-29 19:38:49 +01:00
parent b44df9937e
commit 1f0c228448

View File

@ -2401,7 +2401,7 @@ void QWindowsWindow::setCustomMargins(const QMargins &newCustomMargins)
newFrame.moveTo(topLeft);
qCDebug(lcQpaWindows) << __FUNCTION__ << oldCustomMargins << "->" << newCustomMargins
<< currentFrameGeometry << "->" << newFrame;
SetWindowPos(m_data.hwnd, 0, newFrame.x(), newFrame.y(), newFrame.width(), newFrame.height(), SWP_NOZORDER | SWP_FRAMECHANGED);
SetWindowPos(m_data.hwnd, 0, newFrame.x(), newFrame.y(), newFrame.width(), newFrame.height(), SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE);
}
}