aboutsummaryrefslogtreecommitdiffstats
path: root/src/nativewindow/native/win32
diff options
context:
space:
mode:
Diffstat (limited to 'src/nativewindow/native/win32')
-rw-r--r--src/nativewindow/native/win32/WindowsDWM.c115
-rw-r--r--src/nativewindow/native/win32/WindowsDWM.h34
2 files changed, 97 insertions, 52 deletions
diff --git a/src/nativewindow/native/win32/WindowsDWM.c b/src/nativewindow/native/win32/WindowsDWM.c
index cc9ed6d8c..925ddd1d1 100644
--- a/src/nativewindow/native/win32/WindowsDWM.c
+++ b/src/nativewindow/native/win32/WindowsDWM.c
@@ -1,4 +1,5 @@
+#include <windows.h>
#include "WindowsDWM.h"
#include <stdlib.h>
@@ -21,39 +22,68 @@ typedef HRESULT (WINAPI *DwmEnableCompositionPROCADDR)(UINT uCompositionAction);
typedef HRESULT (WINAPI *DwmIsCompositionEnabledPROCADDR)(BOOL * pfEnabled);
typedef HRESULT (WINAPI *DwmEnableBlurBehindWindowPROCADDR)(HWND hWnd, const DWM_BLURBEHIND* pBlurBehind);
typedef HRESULT (WINAPI *DwmExtendFrameIntoClientAreaPROCADDR)(HWND hwnd, const MARGINS *pMarInset);
+typedef HRESULT (WINAPI *DwmGetWindowAttributePROCADDR)(HWND hwnd, DWORD dwAttribute, PVOID pvAttribute, DWORD cbAttribute);
+typedef HRESULT (WINAPI *DwmSetWindowAttributePROCADDR)(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute);
+typedef BOOL (WINAPI *GetWindowCompositionAttributePROCADDR)(HWND hwnd, WINCOMPATTRDATA* pAttrData);
+typedef BOOL (WINAPI *SetWindowCompositionAttributePROCADDR)(HWND hwnd, WINCOMPATTRDATA* pAttrData);
-static int _init = 0; // 1: init, 2: has DWM extension
+#define INIT_CALLED_MASK 1 << 0
+#define INIT_HAS_DWM_EXT_MASK 1 << 1
+#define INIT_HAS_WINCOMP_EXT_MASK 1 << 2
+
+#define HAS_INIT(a) ( 0 != ( INIT_CALLED_MASK & (a) ) )
+#define HAS_DWM_EXT(a) ( 0 != ( INIT_HAS_DWM_EXT_MASK & (a) ) )
+#define HAS_WINCOMP_EXT(a) ( 0 != ( INIT_HAS_WINCOMP_EXT_MASK & (a) ) )
+
+static int _init = 0; // INIT_ bits, see above
static DwmEnableCompositionPROCADDR _DwmEnableComposition = NULL;
static DwmIsCompositionEnabledPROCADDR _DwmIsCompositionEnabled = NULL;
static DwmEnableBlurBehindWindowPROCADDR _DwmEnableBlurBehindWindow = NULL;
static DwmExtendFrameIntoClientAreaPROCADDR _DwmExtendFrameIntoClientArea = NULL;
+static DwmGetWindowAttributePROCADDR _DwmGetWindowAttribute = NULL;
+static DwmSetWindowAttributePROCADDR _DwmSetWindowAttribute = NULL;
+static GetWindowCompositionAttributePROCADDR _GetWindowCompositionAttribute = NULL;
+static SetWindowCompositionAttributePROCADDR _SetWindowCompositionAttribute = NULL;
static int initWindowsDWM() {
- if(0 == _init) {
- _init = 1;
- HANDLE shell = LoadLibrary(TEXT("dwmapi.dll"));
- if (shell) {
- _DwmEnableComposition = (DwmEnableCompositionPROCADDR) GetProcAddressA (shell, "DwmEnableComposition");
- _DwmIsCompositionEnabled = (DwmIsCompositionEnabledPROCADDR) GetProcAddressA (shell, "DwmIsCompositionEnabled");
- _DwmEnableBlurBehindWindow = (DwmEnableBlurBehindWindowPROCADDR) GetProcAddressA (shell, "DwmEnableBlurBehindWindow");
- _DwmExtendFrameIntoClientArea = (DwmExtendFrameIntoClientAreaPROCADDR) GetProcAddressA (shell, "DwmExtendFrameIntoClientArea");
+ if( !HAS_INIT(_init) ) {
+ _init |= INIT_CALLED_MASK;
+ HANDLE hDwmAPI = LoadLibrary(TEXT("dwmapi.dll"));
+ if (hDwmAPI) {
+ _DwmEnableComposition = (DwmEnableCompositionPROCADDR) GetProcAddressA (hDwmAPI, "DwmEnableComposition");
+ _DwmIsCompositionEnabled = (DwmIsCompositionEnabledPROCADDR) GetProcAddressA (hDwmAPI, "DwmIsCompositionEnabled");
+ _DwmEnableBlurBehindWindow = (DwmEnableBlurBehindWindowPROCADDR) GetProcAddressA (hDwmAPI, "DwmEnableBlurBehindWindow");
+ _DwmExtendFrameIntoClientArea = (DwmExtendFrameIntoClientAreaPROCADDR) GetProcAddressA (hDwmAPI, "DwmExtendFrameIntoClientArea");
+ _DwmGetWindowAttribute = (DwmGetWindowAttributePROCADDR) GetProcAddressA (hDwmAPI, "DwmGetWindowAttribute");
+ _DwmSetWindowAttribute = (DwmSetWindowAttributePROCADDR) GetProcAddressA (hDwmAPI, "DwmSetWindowAttribute");
if(NULL != _DwmEnableComposition && NULL != _DwmIsCompositionEnabled &&
- NULL != _DwmEnableBlurBehindWindow && NULL != _DwmExtendFrameIntoClientArea) {
- _init = 2;
+ NULL != _DwmEnableBlurBehindWindow && NULL != _DwmExtendFrameIntoClientArea &&
+ NULL != _DwmGetWindowAttribute && NULL != _DwmSetWindowAttribute) {
+ _init |= INIT_HAS_DWM_EXT_MASK;
+ }
+ }
+ // FreeLibrary (hDwmAPI);
+ HANDLE hUser32 = LoadLibrary(TEXT("user32.dll"));
+ if (hUser32) {
+ _GetWindowCompositionAttribute = (GetWindowCompositionAttributePROCADDR) GetProcAddressA (hUser32, "GetWindowCompositionAttribute");
+ _SetWindowCompositionAttribute = (SetWindowCompositionAttributePROCADDR) GetProcAddressA (hUser32, "SetWindowCompositionAttribute");
+ if( NULL != _GetWindowCompositionAttribute &&
+ NULL != _SetWindowCompositionAttribute ) {
+ _init |= INIT_HAS_WINCOMP_EXT_MASK;
}
}
- // FreeLibrary (shell);
- DBG_PRINT("DWM - initWindowsDWM: %d - s %p, e %p, c %p\n", _init, shell, _DwmEnableBlurBehindWindow, _DwmExtendFrameIntoClientArea);
+ // FreeLibrary (hUser32);
+ DBG_PRINT("DWM - initWindowsDWM: hasDWM %d, hasWinComp %d\n", HAS_DWM_EXT(_init), HAS_WINCOMP_EXT(_init));
}
return _init;
}
BOOL DwmIsExtensionAvailable() {
- return (2 == initWindowsDWM()) ? TRUE : FALSE;
+ return HAS_DWM_EXT( initWindowsDWM() ) ? TRUE : FALSE;
}
BOOL DwmIsCompositionEnabled( ) {
- if(2 == initWindowsDWM()) {
+ if( HAS_DWM_EXT( initWindowsDWM() ) ) {
BOOL fEnabled = FALSE;
if( 0 == _DwmIsCompositionEnabled(&fEnabled) ) {
DBG_PRINT("DWM - DwmIsCompositionEnabled: %d\n", fEnabled);
@@ -65,14 +95,14 @@ BOOL DwmIsCompositionEnabled( ) {
}
BOOL DwmEnableComposition( UINT uCompositionAction ) {
- if(2 == initWindowsDWM()) {
+ if( HAS_DWM_EXT( initWindowsDWM() ) ) {
return 0 == _DwmEnableComposition(uCompositionAction) ? TRUE : FALSE;
}
return FALSE;
}
BOOL DwmEnableBlurBehindWindow(HWND hwnd, const DWM_BLURBEHIND* pBlurBehind) {
- if(2 == initWindowsDWM()) {
+ if( HAS_DWM_EXT( initWindowsDWM() ) ) {
_DwmEnableBlurBehindWindow(hwnd, pBlurBehind);
DBG_PRINT("DWM - DwmEnableBlurBehindWindow: hwnd %p, f %d, on %d, %p\n",
(void *)hwnd,
@@ -86,10 +116,59 @@ BOOL DwmEnableBlurBehindWindow(HWND hwnd, const DWM_BLURBEHIND* pBlurBehind) {
}
BOOL DwmExtendFrameIntoClientArea(HWND hwnd, const MARGINS *pMarInset) {
- if(2 == initWindowsDWM()) {
+ if( HAS_DWM_EXT( initWindowsDWM() ) ) {
_DwmExtendFrameIntoClientArea(hwnd, pMarInset);
return TRUE;
}
return FALSE;
}
+HRESULT DwmGetWindowAttribute(HWND hwnd, DWORD dwAttribute, PVOID pvAttribute, DWORD cbAttribute) {
+ if( HAS_DWM_EXT( initWindowsDWM() ) ) {
+ return _DwmGetWindowAttribute(hwnd, dwAttribute, pvAttribute, cbAttribute);
+ }
+ return E_NOINTERFACE;
+}
+
+HRESULT DwmSetWindowAttribute(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute) {
+ if( HAS_DWM_EXT( initWindowsDWM() ) ) {
+ return _DwmSetWindowAttribute(hwnd, dwAttribute, pvAttribute, cbAttribute);
+ }
+ return E_NOINTERFACE;
+}
+
+BOOL IsWindowCompositionExtensionAvailable() {
+ return HAS_WINCOMP_EXT( initWindowsDWM() ) ? TRUE : FALSE;
+}
+
+BOOL GetWindowCompositionAccentPolicy(HWND hwnd, AccentPolicy* pAccentPolicy) {
+ if( HAS_WINCOMP_EXT( initWindowsDWM() ) ) {
+ WINCOMPATTRDATA attrData = { WCA_ACCENT_POLICY, pAccentPolicy, sizeof(AccentPolicy) };
+ return _GetWindowCompositionAttribute(hwnd, &attrData);
+ }
+ return FALSE;
+}
+BOOL SetWindowCompositionAccentPolicy(HWND hwnd, const AccentPolicy* pAccentPolicy) {
+ if( HAS_WINCOMP_EXT( initWindowsDWM() ) ) {
+ WINCOMPATTRDATA attrData = { WCA_ACCENT_POLICY, (AccentPolicy*)pAccentPolicy, sizeof(AccentPolicy) };
+ return _SetWindowCompositionAttribute(hwnd, &attrData);
+ }
+ return FALSE;
+}
+
+#if 0
+BOOL GetWindowCompositionAttribute(HWND hwnd, WINCOMPATTRDATA* pAttrData) {
+ if( HAS_WINCOMP_EXT( initWindowsDWM() ) ) {
+ return _GetWindowCompositionAttribute(hwnd, pAttrData);
+ }
+ return FALSE;
+}
+
+BOOL SetWindowCompositionAttribute(HWND hwnd, WINCOMPATTRDATA* pAttrData) {
+ if( HAS_WINCOMP_EXT( initWindowsDWM() ) ) {
+ return _SetWindowCompositionAttribute(hwnd, pAttrData);
+ }
+ return FALSE;
+}
+#endif
+
diff --git a/src/nativewindow/native/win32/WindowsDWM.h b/src/nativewindow/native/win32/WindowsDWM.h
deleted file mode 100644
index 6e5160fa4..000000000
--- a/src/nativewindow/native/win32/WindowsDWM.h
+++ /dev/null
@@ -1,34 +0,0 @@
-#ifndef _WINDOWS_DWM_H_
-#define _WINDOWS_DWM_H_
-
- #include <windows.h>
-
- #define DWM_BB_ENABLE 0x00000001 // fEnable has been specified
- #define DWM_BB_BLURREGION 0x00000002
- #define DWM_BB_TRANSITIONONMAXIMIZED 0x00000004
- #define DWM_EC_DISABLECOMPOSITION 0
- #define DWM_EC_ENABLECOMPOSITION 1
-
- typedef struct _DWM_BLURBEHIND
- {
- DWORD dwFlags;
- BOOL fEnable;
- HRGN hRgnBlur;
- BOOL fTransitionOnMaximized;
- } DWM_BLURBEHIND, *PDWM_BLURBEHIND;
-
- typedef struct _MARGINS
- {
- int cxLeftWidth; // width of left border that retains its size
- int cxRightWidth; // width of right border that retains its size
- int cyTopHeight; // height of top border that retains its size
- int cyBottomHeight; // height of bottom border that retains its size
- } MARGINS, *PMARGINS;
-
- BOOL DwmIsExtensionAvailable();
- BOOL DwmIsCompositionEnabled();
- BOOL DwmEnableComposition( UINT uCompositionAction );
- BOOL DwmEnableBlurBehindWindow(HWND hwnd, const DWM_BLURBEHIND* pBlurBehind);
- BOOL DwmExtendFrameIntoClientArea(HWND hwnd, const MARGINS *pMarInset);
-
-#endif /* _WINDOWS_DWM_H_ */