Fix the context menu issue.
Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
d3f58ae98f
commit
f38b86e992
|
@ -26,8 +26,14 @@
|
||||||
#include "../../winnativeeventfilter.h"
|
#include "../../winnativeeventfilter.h"
|
||||||
#include "ui_widget.h"
|
#include "ui_widget.h"
|
||||||
#include <QColorDialog>
|
#include <QColorDialog>
|
||||||
|
#include <QDebug>
|
||||||
#include <QOperatingSystemVersion>
|
#include <QOperatingSystemVersion>
|
||||||
#include <QStyleOption>
|
#include <QStyleOption>
|
||||||
|
#include <qt_windows.h>
|
||||||
|
|
||||||
|
// Copied from windowsx.h
|
||||||
|
#define GET_X_LPARAM(lp) ((int) (short) LOWORD(lp))
|
||||||
|
#define GET_Y_LPARAM(lp) ((int) (short) HIWORD(lp))
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -175,3 +181,31 @@ bool Widget::eventFilter(QObject *object, QEvent *event)
|
||||||
}
|
}
|
||||||
return QWidget::eventFilter(object, event);
|
return QWidget::eventFilter(object, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Widget::nativeEvent(const QByteArray &eventType, void *message, long *result)
|
||||||
|
{
|
||||||
|
Q_ASSERT(eventType == "windows_generic_MSG");
|
||||||
|
Q_ASSERT(message);
|
||||||
|
Q_ASSERT(result);
|
||||||
|
const auto msg = static_cast<LPMSG>(message);
|
||||||
|
const auto getCursorPosition = [](const LPARAM lParam) -> QPoint {
|
||||||
|
return {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
|
||||||
|
};
|
||||||
|
switch (msg->message) {
|
||||||
|
case WM_NCRBUTTONUP: {
|
||||||
|
const QPoint pos = getCursorPosition(msg->lParam);
|
||||||
|
qDebug() << "WM_NCRBUTTONUP -->" << pos;
|
||||||
|
if (WinNativeEventFilter::displaySystemMenu(msg->hwnd, false, pos.x(), pos.y())) {
|
||||||
|
*result = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case WM_RBUTTONUP:
|
||||||
|
qDebug() << "WM_RBUTTONUP -->" << getCursorPosition(msg->lParam);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return QWidget::nativeEvent(eventType, message, result);
|
||||||
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool eventFilter(QObject *object, QEvent *event) override;
|
bool eventFilter(QObject *object, QEvent *event) override;
|
||||||
|
bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::Widget *ui = nullptr;
|
Ui::Widget *ui = nullptr;
|
||||||
|
|
|
@ -987,8 +987,8 @@ void UpdateFrameMarginsForWindow(const HWND handle)
|
||||||
margins.cyTopHeight = GetFrameSizeForWindow(handle, TRUE).top;
|
margins.cyTopHeight = GetFrameSizeForWindow(handle, TRUE).top;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
margins.cyTopHeight = 1;
|
//margins.cyTopHeight = 1;
|
||||||
//margins.cyTopHeight = GetFrameSizeForWindow(handle, TRUE).top;
|
margins.cyTopHeight = GetFrameSizeForWindow(handle, TRUE).top;
|
||||||
}
|
}
|
||||||
if (shouldUseNativeTitleBar()) {
|
if (shouldUseNativeTitleBar()) {
|
||||||
// If we are going to use the native title bar,
|
// If we are going to use the native title bar,
|
||||||
|
@ -1133,7 +1133,7 @@ bool displaySystemMenu_internal(const HWND handle, const bool isRtl, const LPARA
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString getCurrentScreenSerialNumber(const HWND handle)
|
QString getCurrentScreenIdentifier(const HWND handle)
|
||||||
{
|
{
|
||||||
Q_ASSERT(handle);
|
Q_ASSERT(handle);
|
||||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, handle)) {
|
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, handle)) {
|
||||||
|
@ -1326,7 +1326,7 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
||||||
// Avoid initializing a same window twice.
|
// Avoid initializing a same window twice.
|
||||||
data->initialized = true;
|
data->initialized = true;
|
||||||
// Record the current screen.
|
// Record the current screen.
|
||||||
data->currentScreen = getCurrentScreenSerialNumber(msg->hwnd);
|
data->currentScreen = getCurrentScreenIdentifier(msg->hwnd);
|
||||||
Q_ASSERT(!data->currentScreen.isEmpty());
|
Q_ASSERT(!data->currentScreen.isEmpty());
|
||||||
// Don't restore the window styles to default when you are
|
// Don't restore the window styles to default when you are
|
||||||
// developing Qt Quick applications because the QWindow
|
// developing Qt Quick applications because the QWindow
|
||||||
|
@ -2003,6 +2003,7 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
||||||
*result = ret;
|
*result = ret;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
case WM_ACTIVATE:
|
||||||
case WM_DWMCOMPOSITIONCHANGED: {
|
case WM_DWMCOMPOSITIONCHANGED: {
|
||||||
if (shouldUseNativeTitleBar()) {
|
if (shouldUseNativeTitleBar()) {
|
||||||
break;
|
break;
|
||||||
|
@ -2059,7 +2060,7 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString sn = getCurrentScreenSerialNumber(msg->hwnd);
|
const QString sn = getCurrentScreenIdentifier(msg->hwnd);
|
||||||
if (data->currentScreen.toUpper() != sn) {
|
if (data->currentScreen.toUpper() != sn) {
|
||||||
data->currentScreen = sn;
|
data->currentScreen = sn;
|
||||||
updateWindow(msg->hwnd, true, true);
|
updateWindow(msg->hwnd, true, true);
|
||||||
|
|
Loading…
Reference in New Issue