Windows: Update layered state on creation instead of backingstore flush

The WS_EX_LAYERED state of a window can be determined on creation, and
the logic to do so should be centralized to QWindowsWindow::setWindowLayered,
so that we don't have divergence.

This fixes an issue where child windows would only support transparency
if they had Qt::FramelessWindowHint set, as the QWindowBackingStore had
a different idea about when to enable WS_EX_LAYERED than QWindowsWindow.

Task-number: QTBUG-122590
Task-number: QTBUG-135859
Pick-to: 6.9 6.8
Change-Id: I453967a5a2ce8974cdd1dbf6e36327e97384c33d
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Reviewed-by: Zhao Yuhang <2546789017@qq.com>
Reviewed-by: Pavel Dubsky <pavel.dubsky@qt.io>
This commit is contained in:
Tor Arne Vestbø 2025-05-08 10:57:56 +02:00
parent 369d975c90
commit 876bf141cf
3 changed files with 5 additions and 14 deletions

View File

@ -50,9 +50,7 @@ void QWindowsBackingStore::flush(QWindow *window, const QRegion &region,
QWindowsWindow *rw = QWindowsWindow::windowsWindowOf(window);
Q_ASSERT(rw);
const bool hasAlpha = rw->format().hasAlpha();
const Qt::WindowFlags flags = window->flags();
if ((flags & Qt::FramelessWindowHint) && QWindowsWindow::setWindowLayered(rw->handle(), flags, hasAlpha, rw->opacity()) && hasAlpha) {
if (rw->isLayered()) {
// Windows with alpha: Use blend function to update.
QRect r = QHighDpi::toNativePixels(window->frameGeometry(), window);
QMargins frameMargins = rw->frameMargins();

View File

@ -538,14 +538,6 @@ static void setWindowOpacity(HWND hwnd, Qt::WindowFlags flags, bool hasAlpha, bo
}
}
static inline void updateGLWindowSettings(const QWindow *w, HWND hwnd, Qt::WindowFlags flags, qreal opacity)
{
const bool isAccelerated = windowIsAccelerated(w);
const bool hasAlpha = w->format().hasAlpha();
setWindowOpacity(hwnd, flags, hasAlpha, isAccelerated, opacity);
}
[[nodiscard]] static inline int getResizeBorderThickness(const UINT dpi)
{
// The width of the padded border will always be 0 if DWM composition is
@ -1046,10 +1038,13 @@ void WindowCreationData::initialize(const QWindow *w, HWND hwnd, bool frameChang
MARGINS margins = { -1, -1, -1, -1 };
DwmExtendFrameIntoClientArea(hwnd, &margins);
}
updateGLWindowSettings(w, hwnd, flags, opacityLevel);
} else { // child.
SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, swpFlags);
}
const bool isAccelerated = windowIsAccelerated(w);
const bool hasAlpha = w->format().hasAlpha();
setWindowOpacity(hwnd, flags, hasAlpha, isAccelerated, opacityLevel);
}

View File

@ -69,8 +69,6 @@ int main(int argc, char *argv[])
QSurfaceFormat format = transparentChildWindow->format();
format.setAlphaBufferSize(8);
transparentChildWindow->setFormat(format);
// FIXME: Windows requires this, even for child windows
transparentChildWindow->setFlag(Qt::FramelessWindowHint);
transparentChildWindow->setParent(&window);
transparentChildWindow->setGeometry(350, 50, 100, 100);
transparentChildWindow->showNormal();