Minor fixes
1. Fix MainWindow example issue 2. Add a comment about the inverted argument 3. Fix some memory leaks Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
16f7d78035
commit
ef34a7c699
|
@ -34,6 +34,7 @@
|
||||||
Widget::Widget(QWidget *parent) : QtAcrylicWidget(parent)
|
Widget::Widget(QWidget *parent) : QtAcrylicWidget(parent)
|
||||||
{
|
{
|
||||||
createWinId();
|
createWinId();
|
||||||
|
setAcrylicEnabled(true);
|
||||||
setupUi();
|
setupUi();
|
||||||
startTimer(500);
|
startTimer(500);
|
||||||
}
|
}
|
||||||
|
@ -54,7 +55,6 @@ void Widget::showEvent(QShowEvent *event)
|
||||||
static bool inited = false;
|
static bool inited = false;
|
||||||
if (!inited) {
|
if (!inited) {
|
||||||
FramelessWindowsManager::addWindow(windowHandle());
|
FramelessWindowsManager::addWindow(windowHandle());
|
||||||
setAcrylicEnabled(true);
|
|
||||||
inited = true;
|
inited = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,10 +106,13 @@ bool QtAcrylicWinEventFilter::nativeEventFilter(const QByteArray &eventType, voi
|
||||||
shouldUpdate = true;
|
shouldUpdate = true;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
case WM_DPICHANGED: {
|
||||||
|
shouldClearWallpaper = true;
|
||||||
|
shouldUpdate = true;
|
||||||
|
} break;
|
||||||
case WM_THEMECHANGED:
|
case WM_THEMECHANGED:
|
||||||
case WM_DWMCOMPOSITIONCHANGED:
|
case WM_DWMCOMPOSITIONCHANGED:
|
||||||
case WM_DWMCOLORIZATIONCOLORCHANGED:
|
case WM_DWMCOLORIZATIONCOLORCHANGED:
|
||||||
case WM_DPICHANGED:
|
|
||||||
shouldUpdate = true;
|
shouldUpdate = true;
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
|
|
|
@ -165,6 +165,7 @@ void QtAcrylicMainWindow::showEvent(QShowEvent *event)
|
||||||
m_acrylicHelper.install(windowHandle());
|
m_acrylicHelper.install(windowHandle());
|
||||||
m_acrylicHelper.updateAcrylicBrush(tintColor());
|
m_acrylicHelper.updateAcrylicBrush(tintColor());
|
||||||
connect(&m_acrylicHelper, &QtAcrylicEffectHelper::needsRepaint, this, qOverload<>(&QtAcrylicMainWindow::update));
|
connect(&m_acrylicHelper, &QtAcrylicEffectHelper::needsRepaint, this, qOverload<>(&QtAcrylicMainWindow::update));
|
||||||
|
Utilities::setBlurEffectEnabled(windowHandle(), m_acrylicEnabled);
|
||||||
m_inited = true;
|
m_inited = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,6 +164,7 @@ void QtAcrylicWidget::showEvent(QShowEvent *event)
|
||||||
m_acrylicHelper.install(windowHandle());
|
m_acrylicHelper.install(windowHandle());
|
||||||
m_acrylicHelper.updateAcrylicBrush(tintColor());
|
m_acrylicHelper.updateAcrylicBrush(tintColor());
|
||||||
connect(&m_acrylicHelper, &QtAcrylicEffectHelper::needsRepaint, this, qOverload<>(&QtAcrylicWidget::update));
|
connect(&m_acrylicHelper, &QtAcrylicEffectHelper::needsRepaint, this, qOverload<>(&QtAcrylicWidget::update));
|
||||||
|
Utilities::setBlurEffectEnabled(windowHandle(), m_acrylicEnabled);
|
||||||
m_inited = true;
|
m_inited = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,6 +165,8 @@ static inline void expblur(QImage &img, const qreal radius, const bool improvedQ
|
||||||
qt_blurrow<aprec, zprec, alphaOnly>(img, row, alpha);
|
qt_blurrow<aprec, zprec, alphaOnly>(img, row, alpha);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// TODO: QImage(int width, int height, QImage::Format format)
|
||||||
|
// Why the argument order is inverted here?
|
||||||
QImage temp(img.height(), img.width(), img.format());
|
QImage temp(img.height(), img.width(), img.format());
|
||||||
temp.setDevicePixelRatio(img.devicePixelRatio());
|
temp.setDevicePixelRatio(img.devicePixelRatio());
|
||||||
if (transposed >= 0) {
|
if (transposed >= 0) {
|
||||||
|
|
|
@ -514,8 +514,12 @@ QImage Utilities::getDesktopWallpaperImage(const int screen)
|
||||||
if (SUCCEEDED(pDesktopWallpaper->GetMonitorDevicePathAt(monitorIndex, &monitorId)) && monitorId) {
|
if (SUCCEEDED(pDesktopWallpaper->GetMonitorDevicePathAt(monitorIndex, &monitorId)) && monitorId) {
|
||||||
LPWSTR wallpaperPath = nullptr;
|
LPWSTR wallpaperPath = nullptr;
|
||||||
if (SUCCEEDED(pDesktopWallpaper->GetWallpaper(monitorId, &wallpaperPath)) && wallpaperPath) {
|
if (SUCCEEDED(pDesktopWallpaper->GetWallpaper(monitorId, &wallpaperPath)) && wallpaperPath) {
|
||||||
return QImage(QString::fromWCharArray(wallpaperPath));
|
CoTaskMemFree(monitorId);
|
||||||
|
const QString _path = QString::fromWCharArray(wallpaperPath);
|
||||||
|
CoTaskMemFree(wallpaperPath);
|
||||||
|
return QImage(_path);
|
||||||
} else {
|
} else {
|
||||||
|
CoTaskMemFree(monitorId);
|
||||||
qWarning() << "IDesktopWallpaper::GetWallpaper() failed.";
|
qWarning() << "IDesktopWallpaper::GetWallpaper() failed.";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -543,10 +547,12 @@ QImage Utilities::getDesktopWallpaperImage(const int screen)
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
if (SUCCEEDED(CoCreateInstance(CLSID_ActiveDesktop, nullptr, CLSCTX_INPROC_SERVER, IID_IActiveDesktop, reinterpret_cast<void **>(&pActiveDesktop))) && pActiveDesktop) {
|
if (SUCCEEDED(CoCreateInstance(CLSID_ActiveDesktop, nullptr, CLSCTX_INPROC_SERVER, IID_IActiveDesktop, reinterpret_cast<void **>(&pActiveDesktop))) && pActiveDesktop) {
|
||||||
WCHAR wallpaperPath[MAX_PATH] = {};
|
const auto wallpaperPath = new WCHAR[MAX_PATH];
|
||||||
// TODO: AD_GETWP_BMP, AD_GETWP_IMAGE, AD_GETWP_LAST_APPLIED. What's the difference?
|
// TODO: AD_GETWP_BMP, AD_GETWP_IMAGE, AD_GETWP_LAST_APPLIED. What's the difference?
|
||||||
if (SUCCEEDED(pActiveDesktop->GetWallpaper(wallpaperPath, MAX_PATH, AD_GETWP_LAST_APPLIED))) {
|
if (SUCCEEDED(pActiveDesktop->GetWallpaper(wallpaperPath, MAX_PATH, AD_GETWP_LAST_APPLIED))) {
|
||||||
return QImage(QString::fromWCharArray(wallpaperPath));
|
const QString _path = QString::fromWCharArray(wallpaperPath);
|
||||||
|
delete [] wallpaperPath;
|
||||||
|
return QImage(_path);
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "IActiveDesktop::GetWallpaper() failed.";
|
qWarning() << "IActiveDesktop::GetWallpaper() failed.";
|
||||||
}
|
}
|
||||||
|
@ -559,7 +565,9 @@ QImage Utilities::getDesktopWallpaperImage(const int screen)
|
||||||
qDebug() << "Shell API failed. Using SystemParametersInfoW instead.";
|
qDebug() << "Shell API failed. Using SystemParametersInfoW instead.";
|
||||||
LPWSTR wallpaperPath = nullptr;
|
LPWSTR wallpaperPath = nullptr;
|
||||||
if (SystemParametersInfoW(SPI_GETDESKWALLPAPER, MAX_PATH, wallpaperPath, 0) != FALSE) {
|
if (SystemParametersInfoW(SPI_GETDESKWALLPAPER, MAX_PATH, wallpaperPath, 0) != FALSE) {
|
||||||
return QImage(QString::fromWCharArray(wallpaperPath));
|
const QString _path = QString::fromWCharArray(wallpaperPath);
|
||||||
|
CoTaskMemFree(wallpaperPath);
|
||||||
|
return QImage(_path);
|
||||||
}
|
}
|
||||||
qWarning() << "SystemParametersInfoW failed. Reading from the registry instead.";
|
qWarning() << "SystemParametersInfoW failed. Reading from the registry instead.";
|
||||||
const QSettings settings(g_desktopRegistryKey, QSettings::NativeFormat);
|
const QSettings settings(g_desktopRegistryKey, QSettings::NativeFormat);
|
||||||
|
|
Loading…
Reference in New Issue