Compare commits
3 Commits
9279500c18
...
64a4362580
Author | SHA1 | Date |
---|---|---|
|
64a4362580 | |
|
c175d16d3d | |
|
040027a6e3 |
|
@ -986,7 +986,7 @@ static constexpr const std::array<Win32Message, 333> g_win32MessageMap =
|
|||
if (it == g_win32UtilsData()->data.constEnd()) {
|
||||
return ::DefWindowProcW(hWnd, uMsg, wParam, lParam);
|
||||
}
|
||||
// https://github.com/qt/qtbase/blob/e26a87f1ecc40bc8c6aa5b889fce67410a57a702/src/plugins/platforms/windows/qwindowscontext.cpp#L1025C10-L1025C10
|
||||
// https://github.com/qt/qtbase/blob/e26a87f1ecc40bc8c6aa5b889fce67410a57a702/src/plugins/platforms/windows/qwindowscontext.cpp#L1025
|
||||
// We can see from the source code that Qt will filter out some messages first and then send the unfiltered
|
||||
// messages to the event dispatcher. To activate the Snap Layout feature on Windows 11, we must process
|
||||
// some non-client area messages ourself, but unfortunately these messages have been filtered out already
|
||||
|
@ -997,7 +997,14 @@ static constexpr const std::array<Win32Message, 333> g_win32MessageMap =
|
|||
// send it to our own custom native event filter to do all the magic works. But since the system menu feature
|
||||
// doesn't necessarily belong to the native implementation, we seperate the handling code and always process
|
||||
// the system menu part in this function for both implementations.
|
||||
if (!usePureQtImplementation()) {
|
||||
//
|
||||
// https://github.com/qt/qtbase/blob/946f15efb76fffda37b77f7d194d679b904305b1/src/plugins/platforms/windows/qwindowscontext.cpp#L1541
|
||||
// However, we can't just do this when the message is non-client area size re-calculating, because Qt QPA will
|
||||
// do some extra work after native event filter's handling to ensure Qt windows always have correct frame margins
|
||||
// (and correct client area size, especially when the window is maximized/fullscreen). So we still go through
|
||||
// the normal code path of the original qWindowsWndProc() function, but only for this specific message. It should
|
||||
// be OK because Qt won't prevent us from handling WM_NCCALCSIZE.
|
||||
if (!usePureQtImplementation() && (uMsg != WM_NCCALCSIZE)) {
|
||||
MSG message;
|
||||
SecureZeroMemory(&message, sizeof(message));
|
||||
message.hwnd = hWnd;
|
||||
|
|
|
@ -38,6 +38,8 @@
|
|||
#include <QtGui/qpainter.h>
|
||||
#include <QtGui/qevent.h>
|
||||
#include <QtGui/qfontmetrics.h>
|
||||
#include <QtGui/qscreen.h>
|
||||
#include <QtGui/qguiapplication.h>
|
||||
#include <QtWidgets/qboxlayout.h>
|
||||
|
||||
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||
|
@ -57,6 +59,42 @@ FRAMELESSHELPER_BEGIN_NAMESPACE
|
|||
|
||||
using namespace Global;
|
||||
|
||||
static inline void emulateLeaveEvent(QWidget *widget)
|
||||
{
|
||||
Q_ASSERT(widget);
|
||||
if (!widget) {
|
||||
return;
|
||||
}
|
||||
QTimer::singleShot(0, widget, [widget](){
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
const QScreen *screen = widget->screen();
|
||||
#else
|
||||
const QScreen *screen = QGuiApplication::primaryScreen();
|
||||
#endif
|
||||
const QPoint globalPos = QCursor::pos(screen);
|
||||
if (!QRect(widget->mapToGlobal(QPoint{ 0, 0 }), widget->size()).contains(globalPos)) {
|
||||
QCoreApplication::postEvent(widget, new QEvent(QEvent::Leave));
|
||||
if (widget->testAttribute(Qt::WA_Hover)) {
|
||||
const QPoint localPos = widget->mapFromGlobal(globalPos);
|
||||
const QPoint scenePos = widget->window()->mapFromGlobal(globalPos);
|
||||
static constexpr const auto oldPos = QPoint{};
|
||||
const Qt::KeyboardModifiers modifiers = QGuiApplication::keyboardModifiers();
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 4, 0))
|
||||
const auto event = new QHoverEvent(QEvent::HoverLeave, scenePos, globalPos, oldPos, modifiers);
|
||||
Q_UNUSED(localPos);
|
||||
#elif (QT_VERSION >= QT_VERSION_CHECK(6, 3, 0))
|
||||
const auto event = new QHoverEvent(QEvent::HoverLeave, localPos, globalPos, oldPos, modifiers);
|
||||
Q_UNUSED(scenePos);
|
||||
#else
|
||||
const auto event = new QHoverEvent(QEvent::HoverLeave, localPos, oldPos, modifiers);
|
||||
Q_UNUSED(scenePos);
|
||||
#endif
|
||||
QCoreApplication::postEvent(widget, event);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
StandardTitleBarPrivate::StandardTitleBarPrivate(StandardTitleBar *q) : QObject(q)
|
||||
{
|
||||
Q_ASSERT(q);
|
||||
|
@ -350,6 +388,11 @@ void StandardTitleBarPrivate::initialize()
|
|||
} else {
|
||||
window->showMaximized();
|
||||
}
|
||||
|
||||
// It's a Qt issue that if a QAbstractButton::clicked triggers a window's maximization,
|
||||
// the button remains to be hovered until the mouse move. As a result, we need to
|
||||
// manully send leave events to the button.
|
||||
emulateLeaveEvent(maximizeButton);
|
||||
});
|
||||
closeButton = new StandardSystemButton(SystemButtonType::Close, q);
|
||||
connect(closeButton, &StandardSystemButton::clicked, this, [this](){
|
||||
|
|
Loading…
Reference in New Issue