diff --git a/src/wgl_context.c b/src/wgl_context.c index 0c3ebfae2..9a1fbf423 100644 --- a/src/wgl_context.c +++ b/src/wgl_context.c @@ -493,6 +493,28 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window, } } + if (window->transparent) { + if (!isCompositionEnabled || !_glfw_DwmEnableBlurBehindWindow) { + window->transparent = GLFW_FALSE; + } + else + { + HRESULT hr = S_OK; + + DWM_BLURBEHIND bb = { 0 }; + bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION; + bb.hRgnBlur = CreateRectRgn(0, 0, -1, -1); // makes the window transparent + bb.fEnable = TRUE; + hr = _glfw_DwmEnableBlurBehindWindow(window->win32.handle, &bb); + + if (!SUCCEEDED(hr)) { + window->transparent = GLFW_FALSE; + _glfwInputError(GLFW_PLATFORM_ERROR, + "WGL: Failed to enable blur behind window required for transparency"); + } + } + } + return GLFW_TRUE; } diff --git a/src/win32_platform.h b/src/win32_platform.h index eabf40376..643991a91 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -120,6 +120,12 @@ typedef enum PROCESS_DPI_AWARENESS } PROCESS_DPI_AWARENESS; #endif /*DPI_ENUMS_DECLARED*/ +#if !defined(_DWMAPI_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 + typedef struct _DWM_BLURBEHIND { DWORD dwFlags; @@ -127,31 +133,31 @@ typedef struct _DWM_BLURBEHIND HRGN hRgnBlur; BOOL fTransitionOnMaximized; } DWM_BLURBEHIND, *PDWM_BLURBEHIND; +#endif // winmm.dll function pointer typedefs typedef MMRESULT (WINAPI * JOYGETDEVCAPS_T)(UINT,LPJOYCAPS,UINT); typedef MMRESULT (WINAPI * JOYGETPOS_T)(UINT,LPJOYINFO); typedef MMRESULT (WINAPI * JOYGETPOSEX_T)(UINT,LPJOYINFOEX); typedef DWORD (WINAPI * TIMEGETTIME_T)(void); -typedef HRESULT(WINAPI * DWMENABLEBLURBEHINDWINDOW_T)(HWND, const DWM_BLURBEHIND*); #define _glfw_joyGetDevCaps _glfw.win32.winmm.joyGetDevCaps #define _glfw_joyGetPos _glfw.win32.winmm.joyGetPos #define _glfw_joyGetPosEx _glfw.win32.winmm.joyGetPosEx #define _glfw_timeGetTime _glfw.win32.winmm.timeGetTime -#define _glfw_DwmEnableBlurBehindWindow _glfw.win32.dwmapi.DwmEnableBlurBehindWindow // user32.dll function pointer typedefs typedef BOOL (WINAPI * SETPROCESSDPIAWARE_T)(void); typedef BOOL (WINAPI * CHANGEWINDOWMESSAGEFILTEREX_T)(HWND,UINT,DWORD,PCHANGEFILTERSTRUCT); #define _glfw_SetProcessDPIAware _glfw.win32.user32.SetProcessDPIAware #define _glfw_ChangeWindowMessageFilterEx _glfw.win32.user32.ChangeWindowMessageFilterEx -#define _glfw_DwmEnableBlurBehindWindow _glfw.win32.dwmapi.DwmEnableBlurBehindWindow // dwmapi.dll function pointer typedefs typedef HRESULT (WINAPI * DWMISCOMPOSITIONENABLED_T)(BOOL*); typedef HRESULT (WINAPI * DWMFLUSH_T)(VOID); +typedef HRESULT (WINAPI * DWMENABLEBLURBEHINDWINDOW_T)(HWND, const DWM_BLURBEHIND*); #define _glfw_DwmIsCompositionEnabled _glfw.win32.dwmapi.DwmIsCompositionEnabled #define _glfw_DwmFlush _glfw.win32.dwmapi.DwmFlush +#define _glfw_DwmEnableBlurBehindWindow _glfw.win32.dwmapi.DwmEnableBlurBehindWindow // shcore.dll function pointer typedefs typedef HRESULT (WINAPI * SETPROCESSDPIAWARENESS_T)(PROCESS_DPI_AWARENESS); diff --git a/src/win32_window.c b/src/win32_window.c index 13375bdf3..5bbd04096 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -732,19 +732,6 @@ static int createWindow(_GLFWwindow* window, const _GLFWwndconfig* wndconfig) window->win32.numer = GLFW_DONT_CARE; window->win32.denom = GLFW_DONT_CARE; - // Accelerated transparent windows - // It currently doesn't support decorated windows. - // If decorated is required we just return an opaque window. - // Since DwmEnableBlurBehindWindow is supported since Vista, - // previous versions will simply get an opaque window. - if (!window->decorated && _glfw_DwmEnableBlurBehindWindow && window->transparent) { - DWM_BLURBEHIND bb = { 0 }; - bb.dwFlags = 3; // DWM_BB_ENABLE | DWM_BB_BLURREGION - bb.hRgnBlur = CreateRectRgn(0, 0, -1, -1); // an invalid hRgnBlur makes the the window transparent - bb.fEnable = TRUE; - _glfw_DwmEnableBlurBehindWindow(window->win32.handle, &bb); - } - return GLFW_TRUE; }