Skip to content

Commit

Permalink
fix: webengineView abnormal in DMainWindow
Browse files Browse the repository at this point in the history
`DPlatformWindowHandle::setWindowSurcetype(QWindow::OpenGLSurface)`
needs to be called before constructing DMainWindow when use
webengineview
  • Loading branch information
kegechen committed Dec 7, 2024
1 parent b3410a0 commit 2804e2f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/widgets/dplatformwindowhandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class DPlatformWindowHandle : public DPlatformHandle
static bool setWindowBlurAreaByWM(QWidget *widget, const QList<QPainterPath> &paths);
static bool setWindowWallpaperParaByWM(QWidget *widget, const QRect &area, WallpaperScaleMode sMode, WallpaperFillMode fMode);

// for webengineView you may need this to set `QWindow::SurfaceType::OpenGLSurface`
static void setWindowSurcetype(QWindow::SurfaceType surfaceType);

using DPlatformHandle::setWindowBlurAreaByWM;
using DPlatformHandle::setWindowWallpaperParaByWM;
};
Expand Down
15 changes: 15 additions & 0 deletions src/widgets/dplatformwindowhandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

#include <QWidget>
#include <QApplication>
#include <QWindow>

DWIDGET_BEGIN_NAMESPACE

static QWindow::SurfaceType g_surfaceType = QWindow::RasterSurface;

static QWindow *ensureWindowHandle(QWidget *widget)
{
QWidget *window = widget->window();
Expand All @@ -25,6 +28,11 @@ static QWindow *ensureWindowHandle(QWidget *widget)

window->setAttribute(Qt::WA_NativeWindow);
handle = window->windowHandle();

// default type is `RasterSurface`
if (g_surfaceType != QWindow::RasterSurface)
handle->setSurfaceType(g_surfaceType);

window->setAttribute(Qt::WA_NativeWindow, false);

// dxcb version >= 1.1.6
Expand Down Expand Up @@ -237,4 +245,11 @@ bool DPlatformWindowHandle::setWindowWallpaperParaByWM(QWidget *widget, const QR
return DPlatformHandle::setWindowWallpaperParaByWM(ensureWindowHandle(widget), area, sMode, fMode);
}

void DPlatformWindowHandle::setWindowSurcetype(QWindow::SurfaceType surfaceType)
{
if (g_surfaceType != surfaceType) {
g_surfaceType = surfaceType;

Check warning on line 251 in src/widgets/dplatformwindowhandle.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The statement 'if (g_surfaceType!=surfaceType) g_surfaceType=surfaceType' is logically equivalent to 'g_surfaceType=surfaceType'.
}
}

DWIDGET_END_NAMESPACE

0 comments on commit 2804e2f

Please sign in to comment.