|
|
|
|
@ -33,40 +33,6 @@ |
|
|
|
|
|
|
|
|
|
#ifdef Q_WS_WIN |
|
|
|
|
#include <qt_windows.h> |
|
|
|
|
|
|
|
|
|
// Blur behind data structures
|
|
|
|
|
#define DWM_BB_ENABLE 0x00000001 // fEnable has been specified
|
|
|
|
|
#define DWM_BB_BLURREGION 0x00000002 // hRgnBlur has been specified
|
|
|
|
|
#define DWM_BB_TRANSITIONONMAXIMIZED 0x00000004 // fTransitionOnMaximized has been specified
|
|
|
|
|
#define WM_DWMCOMPOSITIONCHANGED 0x031E // Composition changed window message
|
|
|
|
|
|
|
|
|
|
typedef struct _DWM_BLURBEHIND |
|
|
|
|
{ |
|
|
|
|
DWORD dwFlags; |
|
|
|
|
BOOL fEnable; |
|
|
|
|
HRGN hRgnBlur; |
|
|
|
|
BOOL fTransitionOnMaximized; |
|
|
|
|
} DWM_BLURBEHIND, *PDWM_BLURBEHIND; |
|
|
|
|
|
|
|
|
|
typedef struct _MARGINS |
|
|
|
|
{ |
|
|
|
|
int cxLeftWidth; |
|
|
|
|
int cxRightWidth; |
|
|
|
|
int cyTopHeight; |
|
|
|
|
int cyBottomHeight; |
|
|
|
|
} MARGINS, *PMARGINS; |
|
|
|
|
|
|
|
|
|
typedef HRESULT (WINAPI *PtrDwmIsCompositionEnabled)(BOOL* pfEnabled); |
|
|
|
|
typedef HRESULT (WINAPI *PtrDwmExtendFrameIntoClientArea)(HWND hWnd, const MARGINS* pMarInset); |
|
|
|
|
typedef HRESULT (WINAPI *PtrDwmEnableBlurBehindWindow)(HWND hWnd, const DWM_BLURBEHIND* pBlurBehind); |
|
|
|
|
typedef HRESULT (WINAPI *PtrDwmGetColorizationColor)(DWORD *pcrColorization, BOOL *pfOpaqueBlend); |
|
|
|
|
|
|
|
|
|
static PtrDwmIsCompositionEnabled pDwmIsCompositionEnabled= 0; |
|
|
|
|
static PtrDwmEnableBlurBehindWindow pDwmEnableBlurBehindWindow = 0; |
|
|
|
|
static PtrDwmExtendFrameIntoClientArea pDwmExtendFrameIntoClientArea = 0; |
|
|
|
|
static PtrDwmGetColorizationColor pDwmGetColorizationColor = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Internal helper class that notifies windows if the |
|
|
|
|
* DWM compositing state changes and updates the widget |
|
|
|
|
@ -84,22 +50,10 @@ private: |
|
|
|
|
QWidgetList widgets; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static bool resolveLibs() |
|
|
|
|
{ |
|
|
|
|
if (!pDwmIsCompositionEnabled) { |
|
|
|
|
QLibrary dwmLib(QString::fromAscii("dwmapi")); |
|
|
|
|
pDwmIsCompositionEnabled =(PtrDwmIsCompositionEnabled)dwmLib.resolve("DwmIsCompositionEnabled"); |
|
|
|
|
pDwmExtendFrameIntoClientArea = (PtrDwmExtendFrameIntoClientArea)dwmLib.resolve("DwmExtendFrameIntoClientArea"); |
|
|
|
|
pDwmEnableBlurBehindWindow = (PtrDwmEnableBlurBehindWindow)dwmLib.resolve("DwmEnableBlurBehindWindow"); |
|
|
|
|
pDwmGetColorizationColor = (PtrDwmGetColorizationColor)dwmLib.resolve("DwmGetColorizationColor"); |
|
|
|
|
} |
|
|
|
|
return pDwmIsCompositionEnabled != 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* Chekcs and returns true if Windows version |
|
|
|
|
* Checks and returns true if Windows version |
|
|
|
|
* currently running is Windows 7 |
|
|
|
|
* |
|
|
|
|
* This function is useful when you are using |
|
|
|
|
@ -127,13 +81,11 @@ bool QtWin::isRunningWindows7() |
|
|
|
|
bool QtWin::isCompositionEnabled() |
|
|
|
|
{ |
|
|
|
|
#ifdef Q_WS_WIN |
|
|
|
|
if (resolveLibs()) { |
|
|
|
|
HRESULT hr = S_OK; |
|
|
|
|
BOOL isEnabled = false; |
|
|
|
|
hr = pDwmIsCompositionEnabled(&isEnabled); |
|
|
|
|
if (SUCCEEDED(hr)) |
|
|
|
|
return isEnabled; |
|
|
|
|
} |
|
|
|
|
HRESULT hr = S_OK; |
|
|
|
|
BOOL isEnabled = false; |
|
|
|
|
hr = DwmIsCompositionEnabled(&isEnabled); |
|
|
|
|
if (SUCCEEDED(hr)) |
|
|
|
|
return isEnabled; |
|
|
|
|
#endif |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
@ -150,19 +102,17 @@ bool QtWin::enableBlurBehindWindow(QWidget *widget, bool enable) |
|
|
|
|
Q_ASSERT(widget); |
|
|
|
|
bool result = false; |
|
|
|
|
#ifdef Q_WS_WIN |
|
|
|
|
if (resolveLibs()) { |
|
|
|
|
DWM_BLURBEHIND bb = {0}; |
|
|
|
|
HRESULT hr = S_OK; |
|
|
|
|
bb.fEnable = enable; |
|
|
|
|
bb.dwFlags = DWM_BB_ENABLE; |
|
|
|
|
bb.hRgnBlur = NULL; |
|
|
|
|
widget->setAttribute(Qt::WA_TranslucentBackground, enable); |
|
|
|
|
widget->setAttribute(Qt::WA_NoSystemBackground, enable); |
|
|
|
|
hr = pDwmEnableBlurBehindWindow(widget->winId(), &bb); |
|
|
|
|
if (SUCCEEDED(hr)) { |
|
|
|
|
result = true; |
|
|
|
|
windowNotifier()->addWidget(widget); |
|
|
|
|
} |
|
|
|
|
DWM_BLURBEHIND bb = {0}; |
|
|
|
|
HRESULT hr = S_OK; |
|
|
|
|
bb.fEnable = enable; |
|
|
|
|
bb.dwFlags = DWM_BB_ENABLE; |
|
|
|
|
bb.hRgnBlur = NULL; |
|
|
|
|
widget->setAttribute(Qt::WA_TranslucentBackground, enable); |
|
|
|
|
widget->setAttribute(Qt::WA_NoSystemBackground, enable); |
|
|
|
|
hr = DwmEnableBlurBehindWindow(widget->winId(), &bb); |
|
|
|
|
if (SUCCEEDED(hr)) { |
|
|
|
|
result = true; |
|
|
|
|
windowNotifier()->addWidget(widget); |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
return result; |
|
|
|
|
@ -192,17 +142,14 @@ bool QtWin::extendFrameIntoClientArea(QWidget *widget, int left, int top, int ri |
|
|
|
|
|
|
|
|
|
bool result = false; |
|
|
|
|
#ifdef Q_WS_WIN |
|
|
|
|
if (resolveLibs()) { |
|
|
|
|
QLibrary dwmLib(QString::fromAscii("dwmapi")); |
|
|
|
|
HRESULT hr = S_OK; |
|
|
|
|
MARGINS m = {left, top, right, bottom}; |
|
|
|
|
hr = pDwmExtendFrameIntoClientArea(widget->winId(), &m); |
|
|
|
|
if (SUCCEEDED(hr)) { |
|
|
|
|
result = true; |
|
|
|
|
windowNotifier()->addWidget(widget); |
|
|
|
|
} |
|
|
|
|
widget->setAttribute(Qt::WA_TranslucentBackground, result); |
|
|
|
|
HRESULT hr = S_OK; |
|
|
|
|
MARGINS m = {left, top, right, bottom}; |
|
|
|
|
hr = DwmExtendFrameIntoClientArea(widget->winId(), &m); |
|
|
|
|
if (SUCCEEDED(hr)) { |
|
|
|
|
result = true; |
|
|
|
|
windowNotifier()->addWidget(widget); |
|
|
|
|
} |
|
|
|
|
widget->setAttribute(Qt::WA_TranslucentBackground, result); |
|
|
|
|
#endif |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
@ -217,15 +164,12 @@ QColor QtWin::colorizatinColor() |
|
|
|
|
QColor resultColor = QApplication::palette().window().color(); |
|
|
|
|
|
|
|
|
|
#ifdef Q_WS_WIN |
|
|
|
|
if (resolveLibs()) { |
|
|
|
|
DWORD color = 0; |
|
|
|
|
BOOL opaque = FALSE; |
|
|
|
|
QLibrary dwmLib(QString::fromAscii("dwmapi")); |
|
|
|
|
HRESULT hr = S_OK; |
|
|
|
|
hr = pDwmGetColorizationColor(&color, &opaque); |
|
|
|
|
if (SUCCEEDED(hr)) |
|
|
|
|
resultColor = QColor(color); |
|
|
|
|
} |
|
|
|
|
DWORD color = 0; |
|
|
|
|
BOOL opaque = FALSE; |
|
|
|
|
HRESULT hr = S_OK; |
|
|
|
|
hr = DwmGetColorizationColor(&color, &opaque); |
|
|
|
|
if (SUCCEEDED(hr)) |
|
|
|
|
resultColor = QColor(color); |
|
|
|
|
#endif |
|
|
|
|
return resultColor; |
|
|
|
|
} |
|
|
|
|
|