Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
linux: workaround qt missing mouse release event
Browse files Browse the repository at this point in the history
  • Loading branch information
wangwenx190 committed Aug 7, 2023
1 parent 177e377 commit e1e38ac
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/core/utils_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "framelessmanager_p.h"
#include <cstring> // for std::memcpy
#include <QtCore/qloggingcategory.h>
#include <QtGui/qevent.h>
#include <QtGui/qwindow.h>
#include <QtGui/qscreen.h>
#include <QtGui/qpalette.h>
Expand Down Expand Up @@ -120,6 +121,26 @@ extern QString gtkSettings(const gchar *);
return _NET_WM_MOVERESIZE_CANCEL;
}

[[maybe_unused]] static inline void generateMouseReleaseEvent(QWindow *window, const QPoint &globalPos)
{
Q_ASSERT(window);
if (!window) {
return;
}
// https://bugreports.qt.io/browse/QTBUG-102488
const QPoint localPos = window->mapFromGlobal(globalPos);
const QPoint scenePos = localPos; // windowPos in Qt5.
const auto event = std::make_unique<QMouseEvent>(
QEvent::MouseButtonRelease,
localPos,
scenePos,
globalPos,
Qt::LeftButton,
QGuiApplication::mouseButtons() ^ Qt::LeftButton,
QGuiApplication::keyboardModifiers());
QGuiApplication::sendEvent(window, event.get());
}

QScreen *Utils::x11_findScreenForVirtualDesktop(const int virtualDesktopNumber)
{
#ifdef FRAMELESSHELPER_CORE_NO_PRIVATE
Expand Down Expand Up @@ -351,8 +372,8 @@ void Utils::startSystemMove(QWindow *window, const QPoint &globalPos)
return;
}
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
Q_UNUSED(globalPos);
window->startSystemMove();
generateMouseReleaseEvent(window, globalPos);
#else // (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
const QPoint nativeGlobalPos = Utils::toNativeGlobalPosition(window, globalPos);
sendMoveResizeMessage(window->winId(), _NET_WM_MOVERESIZE_MOVE, nativeGlobalPos);
Expand All @@ -369,8 +390,8 @@ void Utils::startSystemResize(QWindow *window, const Qt::Edges edges, const QPoi
return;
}
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
Q_UNUSED(globalPos);
window->startSystemResize(edges);
generateMouseReleaseEvent(window, globalPos);
#else // (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
const QPoint nativeGlobalPos = Utils::toNativeGlobalPosition(window, globalPos);
const int netWmOperation = qtEdgesToWmMoveOrResizeOperation(edges);
Expand Down

0 comments on commit e1e38ac

Please sign in to comment.