From f874811443991759df4231b5127788af059a0df9 Mon Sep 17 00:00:00 2001 From: Sine Striker <trueful@163.com> Date: 周二, 19 12月 2023 15:55:52 +0800 Subject: [PATCH] Add raise hook --- src/core/contexts/abstractwindowcontext.cpp | 12 +++++++++--- src/core/contexts/qtwindowcontext.cpp | 6 ------ README.md | 2 ++ src/core/contexts/win32windowcontext.cpp | 20 ++++++++++++++++++++ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index c8f6c14..88076e0 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ + Fix window 10 top border color in dark background + Fix `isFixedSize` code + Support customized system button area on Mac ++ Implement Mac window context hook ++ Support window attribute switching on Windows ## Supported Platforms diff --git a/src/core/contexts/abstractwindowcontext.cpp b/src/core/contexts/abstractwindowcontext.cpp index a62d037..5ce7c8c 100644 --- a/src/core/contexts/abstractwindowcontext.cpp +++ b/src/core/contexts/abstractwindowcontext.cpp @@ -2,6 +2,7 @@ #include <QtGui/QPen> #include <QtGui/QPainter> +#include <QtGui/QScreen> #include "qwkglobal_p.h" @@ -154,12 +155,17 @@ void AbstractWindowContext::virtual_hook(int id, void *data) { switch (id) { case CentralizeHook: { - // TODO: Qt + QRect screenGeometry = m_windowHandle->screen()->geometry(); + int x = screenGeometry.width() / 2 - m_windowHandle->width() / 2; + int y = screenGeometry.height() / 2 - m_windowHandle->height() / 2; + m_windowHandle->setPosition(x, y); break; } - case ShowSystemMenuHook: { - // TODO: Qt + case RaiseWindowHook: { + if (m_windowHandle->windowStates() & Qt::WindowMinimized) + m_windowHandle->showNormal(); + m_windowHandle->raise(); break; } diff --git a/src/core/contexts/qtwindowcontext.cpp b/src/core/contexts/qtwindowcontext.cpp index 8a71c2b..4bbb0e6 100644 --- a/src/core/contexts/qtwindowcontext.cpp +++ b/src/core/contexts/qtwindowcontext.cpp @@ -244,12 +244,6 @@ } void QtWindowContext::virtual_hook(int id, void *data) { - switch (id) { - case ShowSystemMenuHook: - return; - default: - break; - } AbstractWindowContext::virtual_hook(id, data); } diff --git a/src/core/contexts/win32windowcontext.cpp b/src/core/contexts/win32windowcontext.cpp index 8af6a3f..9b3e179 100644 --- a/src/core/contexts/win32windowcontext.cpp +++ b/src/core/contexts/win32windowcontext.cpp @@ -812,6 +812,26 @@ return; } + case RaiseWindowHook: { + if (m_windowHandle->windowStates() & Qt::WindowMinimized) + m_windowHandle->showNormal(); + + auto hWnd = reinterpret_cast<HWND>(windowId); + + // I have no idea what this does, but it works mostly + // https://www.codeproject.com/Articles/1724/Some-handy-dialog-box-tricks-tips-and-workarounds + + ::AttachThreadInput(::GetWindowThreadProcessId(::GetForegroundWindow(), nullptr), + ::GetCurrentThreadId(), TRUE); + + ::SetForegroundWindow(hWnd); + ::SetFocus(hWnd); + + ::AttachThreadInput(GetWindowThreadProcessId(GetForegroundWindow(), nullptr), + GetCurrentThreadId(), FALSE); + return; + } + case ShowSystemMenuHook: { const auto &pos = *static_cast<const QPoint *>(data); auto hWnd = reinterpret_cast<HWND>(windowId); -- Gitblit v1.9.1