From 09287f3d9e9e88271de2bfd5388dae5a53e8c6f5 Mon Sep 17 00:00:00 2001 From: Sine Striker <trueful@163.com> Date: ćšć, 07 12æ 2023 15:03:24 +0800 Subject: [PATCH] Add host event filter --- src/core/contexts/win32windowcontext.cpp | 52 ++++++---------------------------------------------- 1 files changed, 6 insertions(+), 46 deletions(-) diff --git a/src/core/contexts/win32windowcontext.cpp b/src/core/contexts/win32windowcontext.cpp index a843e90..c5c1cbd 100644 --- a/src/core/contexts/win32windowcontext.cpp +++ b/src/core/contexts/win32windowcontext.cpp @@ -188,22 +188,14 @@ } static inline void triggerFrameChange(HWND hwnd) { - Q_ASSERT(hwnd); - if (!hwnd) { - return; - } ::SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED); } static inline quint32 getDpiForWindow(HWND hwnd) { - Q_ASSERT(hwnd); - if (!hwnd) { - return 0; - } const DynamicApis &apis = DynamicApis::instance(); - if (apis.pGetDpiForWindow) { // Win10 + if (apis.pGetDpiForWindow) { // Win10 return apis.pGetDpiForWindow(hwnd); } else if (apis.pGetDpiForMonitor) { // Win8.1 HMONITOR monitor = ::MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); @@ -221,10 +213,6 @@ } static inline quint32 getResizeBorderThickness(HWND hwnd) { - Q_ASSERT(hwnd); - if (!hwnd) { - return 0; - } const DynamicApis &apis = DynamicApis::instance(); if (apis.pGetSystemMetricsForDpi) { const quint32 dpi = getDpiForWindow(hwnd); @@ -236,10 +224,6 @@ } static inline quint32 getTitleBarHeight(HWND hwnd) { - Q_ASSERT(hwnd); - if (!hwnd) { - return 0; - } const auto captionHeight = [hwnd]() -> int { const DynamicApis &apis = DynamicApis::instance(); if (apis.pGetSystemMetricsForDpi) { @@ -253,11 +237,6 @@ } static inline void updateInternalWindowFrameMargins(HWND hwnd, QWindow *window) { - Q_ASSERT(hwnd); - Q_ASSERT(window); - if (!hwnd || !window) { - return; - } const auto margins = [hwnd]() -> QMargins { const int titleBarHeight = getTitleBarHeight(hwnd); if (isWin10OrGreater()) { @@ -285,10 +264,6 @@ } static inline MONITORINFOEXW getMonitorForWindow(HWND hwnd) { - Q_ASSERT(hwnd); - if (!hwnd) { - return {}; - } // Use "MONITOR_DEFAULTTONEAREST" here so that we can still get the correct // monitor even if the window is minimized. HMONITOR monitor = ::MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); @@ -299,10 +274,6 @@ }; static inline void moveToDesktopCenter(HWND hwnd) { - Q_ASSERT(hwnd); - if (!hwnd) { - return; - } const auto monitorInfo = getMonitorForWindow(hwnd); RECT windowRect{}; ::GetWindowRect(hwnd, &windowRect); @@ -443,17 +414,11 @@ static WindowsNativeEventFilter *instance; static inline void install() { - if (instance) { - return; - } instance = new WindowsNativeEventFilter(); installNativeEventFilter(instance); } static inline void uninstall() { - if (!instance) { - return; - } removeNativeEventFilter(instance); delete instance; instance = nullptr; @@ -545,8 +510,7 @@ return ::CallWindowProcW(g_qtWindowProc, hWnd, message, wParam, lParam); } - Win32WindowContext::Win32WindowContext(const QObject *host, const WindowItemDelegate *delegate) - : AbstractWindowContext(host, delegate) { + Win32WindowContext::Win32WindowContext() : AbstractWindowContext() { } Win32WindowContext::~Win32WindowContext() { @@ -561,11 +525,7 @@ } } - bool Win32WindowContext::setup() { - if (!m_windowHandle) { - return false; - } - + bool Win32WindowContext::setupHost() { // Install window hook auto winId = m_windowHandle->winId(); auto hWnd = reinterpret_cast<HWND>(winId); @@ -582,7 +542,9 @@ ::SetWindowLongPtrW(hWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(QWKHookedWndProc)); // Install global native event filter - WindowsNativeEventFilter::install(); + if (!WindowsNativeEventFilter::instance) { + WindowsNativeEventFilter::install(); + } // Cache window ID windowId = winId; @@ -1298,8 +1260,6 @@ break; case CoreWindowAgent::Close: *result = HTCLOSE; - break; - case CoreWindowAgent::Unknown: break; default: break; // unreachable -- Gitblit v1.9.1