Remove use of X11Extras and WinExtras

Modules are deprecated in Qt 6
See: QTBUG-83251
This commit is contained in:
jonas@jkvinge.net
2021-05-12 20:08:06 +02:00
parent a01541d7ca
commit efcd35d4a1
14 changed files with 160 additions and 97 deletions

View File

@@ -28,6 +28,7 @@
#include <QtGlobal>
#include <QApplication>
#include <QCoreApplication>
#include <QWindow>
#include <QWidget>
#include <QObject>
#include <QIODevice>
@@ -51,6 +52,7 @@
#include <QRegularExpressionMatch>
#include <QSize>
#include <QColor>
#include <QRegion>
#include <QMetaEnum>
#include <QXmlStreamReader>
#include <QSettings>
@@ -79,6 +81,7 @@
# include <sys/statvfs.h>
#elif defined(Q_OS_WIN)
# include <windows.h>
# include <dwmapi.h>
#endif
#ifdef Q_OS_MACOS
@@ -952,6 +955,62 @@ QString MimeTypeFromData(const QByteArray &data) {
}
#ifdef Q_OS_WIN
HRGN qt_RectToHRGN(const QRect &rc);
HRGN qt_RectToHRGN(const QRect &rc) {
return CreateRectRgn(rc.left(), rc.top(), rc.right() + 1, rc.bottom() + 1);
}
HRGN toHRGN(const QRegion &region);
HRGN toHRGN(const QRegion &region) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return region.toHRGN();
#else
const int rect_count = region.rectCount();
if (rect_count == 0) {
return nullptr;
}
HRGN resultRgn = nullptr;
QRegion::const_iterator rects = region.begin();
resultRgn = qt_RectToHRGN(rects[0]);
for (int i = 1 ; i < rect_count ; ++i) {
HRGN tmpRgn = qt_RectToHRGN(rects[i]);
const int res = CombineRgn(resultRgn, resultRgn, tmpRgn, RGN_OR);
if (res == ERROR) qWarning("Error combining HRGNs.");
DeleteObject(tmpRgn);
}
return resultRgn;
#endif // Qt 6
}
void enableBlurBehindWindow(QWindow *window, const QRegion &region) {
DWM_BLURBEHIND dwmbb = {0, 0, nullptr, 0};
dwmbb.dwFlags = DWM_BB_ENABLE;
dwmbb.fEnable = TRUE;
HRGN rgn = nullptr;
if (!region.isNull()) {
rgn = toHRGN(region);
if (rgn) {
dwmbb.hRgnBlur = rgn;
dwmbb.dwFlags |= DWM_BB_BLURREGION;
}
}
DwmEnableBlurBehindWindow(reinterpret_cast<HWND>(window->winId()), &dwmbb);
if (rgn) {
DeleteObject(rgn);
}
}
#endif // Q_OS_WIN
} // namespace Utilities
ScopedWCharArray::ScopedWCharArray(const QString &str)

View File

@@ -27,6 +27,7 @@
#include <memory>
#include <QtGlobal>
#include <QWindow>
#include <QByteArray>
#include <QFile>
#include <QSize>
@@ -38,6 +39,7 @@
#include <QStringList>
#include <QUrl>
#include <QColor>
#include <QRegion>
#include <QtEvents>
#include "core/song.h"
@@ -146,6 +148,10 @@ bool IsColorDark(const QColor &color);
QByteArray ReadDataFromFile(const QString &filename);
QString MimeTypeFromData(const QByteArray &data);
#ifdef Q_OS_WIN
void enableBlurBehindWindow(QWindow *window, const QRegion &region);
#endif
} // namespace
class ScopedWCharArray {