diff --git a/framelesshelper.cpp b/framelesshelper.cpp index 91c9e37..4a9c829 100644 --- a/framelesshelper.cpp +++ b/framelesshelper.cpp @@ -99,7 +99,7 @@ void FramelessHelper::updateQtFrame(QWindow *window, const int titleBarHeight) marginsVar); } #else - auto *platformWindow = qobject_cast( + auto *platformWindow = dynamic_cast( window->handle()); if (platformWindow) { platformWindow->setCustomMargins(margins); diff --git a/winnativeeventfilter.cpp b/winnativeeventfilter.cpp index 586a38b..767640e 100644 --- a/winnativeeventfilter.cpp +++ b/winnativeeventfilter.cpp @@ -58,8 +58,8 @@ #include #include #endif -#ifdef WNEF_LINK_SYSLIB #include +#ifdef WNEF_LINK_SYSLIB #include #include #include @@ -369,22 +369,6 @@ using BP_PAINTPARAMS = struct _BP_PAINTPARAMS CONST BLENDFUNCTION *pBlendFunction; }; -using D2D1_FACTORY_TYPE = enum _D2D1_FACTORY_TYPE { D2D1_FACTORY_TYPE_SINGLE_THREADED = 0 }; - -using D2D1_DEBUG_LEVEL = enum _D2D1_DEBUG_LEVEL { - D2D1_DEBUG_LEVEL_NONE = 0, - D2D1_DEBUG_LEVEL_ERROR = 1, - D2D1_DEBUG_LEVEL_WARNING = 2, - D2D1_DEBUG_LEVEL_INFORMATION = 3, - D2D1_DEBUG_LEVEL_FORCE_DWORD = 0xffffffff - -}; - -using D2D1_FACTORY_OPTIONS = struct _D2D1_FACTORY_OPTIONS -{ - D2D1_DEBUG_LEVEL debugLevel; -}; - using DWM_BLURBEHIND = struct _DWM_BLURBEHIND { DWORD dwFlags; @@ -810,26 +794,22 @@ BOOL IsApplicationDpiAware() UINT GetDotsPerInchForSystem() { const auto getScreenDpi = [](const UINT defaultValue) -> UINT { - /* - if (m_lpD2D1CreateFactory) { - // Using Direct2D to get the screen DPI. - // Available since Windows 7. - ID2D1Factory *m_pDirect2dFactory = nullptr; - if (SUCCEEDED(WNEF_EXECUTE_WINAPI_RETURN(D2D1CreateFactory, - E_FAIL, - D2D1_FACTORY_TYPE_SINGLE_THREADED, - __uuidof(ID2D1Factory), - nullptr, - reinterpret_cast(&m_pDirect2dFactory))) - && m_pDirect2dFactory) { - m_pDirect2dFactory->ReloadSystemMetrics(); - FLOAT dpiX = defaultValue, dpiY = defaultValue; - m_pDirect2dFactory->GetDesktopDpi(&dpiX, &dpiY); - // The values of *dpiX and *dpiY are identical. - return qRound(dpiX == dpiY ? dpiY : dpiX); - } + // Using Direct2D to get the screen DPI. + // Available since Windows 7. + ID2D1Factory *m_pDirect2dFactory = nullptr; + if (SUCCEEDED(WNEF_EXECUTE_WINAPI_RETURN(D2D1CreateFactory, + E_FAIL, + D2D1_FACTORY_TYPE_SINGLE_THREADED, + __uuidof(ID2D1Factory), + nullptr, + reinterpret_cast(&m_pDirect2dFactory))) + && m_pDirect2dFactory) { + m_pDirect2dFactory->ReloadSystemMetrics(); + FLOAT dpiX = defaultValue, dpiY = defaultValue; + m_pDirect2dFactory->GetDesktopDpi(&dpiX, &dpiY); + // The values of *dpiX and *dpiY are identical. + return qRound(dpiX == dpiY ? dpiY : dpiX); } - */ // Available since Windows 2000. const HDC hdc = WNEF_EXECUTE_WINAPI_RETURN(GetDC, nullptr, nullptr); if (hdc) { @@ -1002,22 +982,7 @@ void UpdateFrameMarginsForWindow(const HWND handle) // the client area in WM_NCCALCSIZE so we won't see it due to // it's covered by the client area (in other words, it's still // there, we just can't see it). - if (shouldHaveWindowFrame()) { - const auto GetTopBorderHeight = [](const HWND handle) -> int { - Q_ASSERT(handle); - if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, handle)) { - if (IsDwmCompositionEnabled() && !IsMaximized(handle) && !IsFullScreen(handle)) { - return 1; - } - } - return 0; - }; - if (GetTopBorderHeight(handle) != 0) { - margins.cyTopHeight = GetFrameSizeForWindow(handle, TRUE).top; - } - } else { - margins.cyTopHeight = 1; - } + margins.cyTopHeight = 1; if (shouldUseNativeTitleBar() || dontExtendFrame()) { // If we are going to use the native title bar, // we should use the original window frame as well. @@ -2328,7 +2293,7 @@ void WinNativeEventFilter::updateQtFrame(QWindow *window, const int titleBarHeig marginsVar); } #else - auto *platformWindow = qobject_cast( + auto *platformWindow = dynamic_cast( window->handle()); if (platformWindow) { platformWindow->setCustomMargins(margins);