Fixed RpWindow dragging on macOS with Qt 6.2.
This commit is contained in:
parent
f51ff6b513
commit
cc79439fee
1 changed files with 22 additions and 8 deletions
|
|
@ -85,24 +85,35 @@ private:
|
||||||
|
|
||||||
class EventFilter : public QObject, public QAbstractNativeEventFilter {
|
class EventFilter : public QObject, public QAbstractNativeEventFilter {
|
||||||
public:
|
public:
|
||||||
EventFilter(not_null<QObject*> parent, Fn<bool(void*)> checkPerformDrag)
|
EventFilter(
|
||||||
|
not_null<QObject*> parent,
|
||||||
|
Fn<bool()> checkStartDrag,
|
||||||
|
Fn<bool(void*)> checkPerformDrag)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
|
, _checkStartDrag(std::move(checkStartDrag))
|
||||||
, _checkPerformDrag(std::move(checkPerformDrag)) {
|
, _checkPerformDrag(std::move(checkPerformDrag)) {
|
||||||
Expects(_checkPerformDrag != nullptr);
|
Expects(_checkPerformDrag != nullptr);
|
||||||
|
Expects(_checkStartDrag != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool nativeEventFilter(
|
bool nativeEventFilter(
|
||||||
const QByteArray &eventType,
|
const QByteArray &eventType,
|
||||||
void *message,
|
void *message,
|
||||||
base::NativeEventResult *result) {
|
base::NativeEventResult *result) {
|
||||||
NSEvent *e = static_cast<NSEvent*>(message);
|
if (NSEvent *e = static_cast<NSEvent*>(message)) {
|
||||||
return (e && [e type] == NSEventTypeLeftMouseDragged)
|
if ([e type] == NSEventTypeLeftMouseDown) {
|
||||||
? _checkPerformDrag([e window])
|
_dragStarted = _checkStartDrag();
|
||||||
: false;
|
} else if (([e type] == NSEventTypeLeftMouseDragged)
|
||||||
|
&& _dragStarted) {
|
||||||
|
return _checkPerformDrag([e window]);
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool _dragStarted = false;
|
||||||
|
Fn<bool()> _checkStartDrag;
|
||||||
Fn<bool(void*)> _checkPerformDrag;
|
Fn<bool(void*)> _checkPerformDrag;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
@ -362,7 +373,10 @@ void WindowHelper::setGeometry(QRect rect) {
|
||||||
|
|
||||||
void WindowHelper::setupBodyTitleAreaEvents() {
|
void WindowHelper::setupBodyTitleAreaEvents() {
|
||||||
const auto controls = _private->controlsRect();
|
const auto controls = _private->controlsRect();
|
||||||
qApp->installNativeEventFilter(new EventFilter(window(), [=](void *nswindow) {
|
qApp->installNativeEventFilter(new EventFilter(window(), [=] {
|
||||||
|
const auto point = body()->mapFromGlobal(QCursor::pos());
|
||||||
|
return (bodyTitleAreaHit(point) & WindowTitleHitTestFlag::Move);
|
||||||
|
}, [=](void *nswindow) {
|
||||||
const auto point = body()->mapFromGlobal(QCursor::pos());
|
const auto point = body()->mapFromGlobal(QCursor::pos());
|
||||||
if (_private->checkNativeMove(nswindow)
|
if (_private->checkNativeMove(nswindow)
|
||||||
&& !controls.contains(point)
|
&& !controls.contains(point)
|
||||||
|
|
@ -401,9 +415,9 @@ void WindowHelper::init() {
|
||||||
}, _body->lifetime());
|
}, _body->lifetime());
|
||||||
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
setBodyTitleArea([=](QPoint widgetPoint) {
|
setBodyTitleArea([](QPoint widgetPoint) {
|
||||||
using Flag = Ui::WindowTitleHitTestFlag;
|
using Flag = Ui::WindowTitleHitTestFlag;
|
||||||
return (_body->y() > widgetPoint.y())
|
return (widgetPoint.y() < 0)
|
||||||
? (Flag::Move | Flag::Maximize)
|
? (Flag::Move | Flag::Maximize)
|
||||||
: Flag::None;
|
: Flag::None;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue