linux: update the implementation based on previous commit

When implementing macOS functionalities, some functions changed signature, update accordingly.

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2022-04-18 19:11:23 +08:00
parent 976b2463d7
commit 68296cc1ae
12 changed files with 114 additions and 128 deletions

View File

@ -68,8 +68,8 @@ public Q_SLOTS:
void toggleMaximized(); void toggleMaximized();
void toggleFullScreen(); void toggleFullScreen();
void showSystemMenu(const QPoint &pos); void showSystemMenu(const QPoint &pos);
void startSystemMove2(); void startSystemMove2(const QPoint &pos);
void startSystemResize2(const Qt::Edges edges); void startSystemResize2(const Qt::Edges edges, const QPoint &pos);
void setTitleBarItem(QQuickItem *item); void setTitleBarItem(QQuickItem *item);
void setHitTestVisible(QQuickItem *item); void setHitTestVisible(QQuickItem *item);
void moveToDesktopCenter(); void moveToDesktopCenter();

View File

@ -61,8 +61,8 @@ public Q_SLOTS:
void moveToDesktopCenter(); void moveToDesktopCenter();
void bringToFront(); void bringToFront();
void showSystemMenu(const QPoint &pos); void showSystemMenu(const QPoint &pos);
void startSystemMove2(); void startSystemMove2(const QPoint &pos);
void startSystemResize2(const Qt::Edges edges); void startSystemResize2(const Qt::Edges edges, const QPoint &pos);
Q_SIGNALS: Q_SIGNALS:
void hiddenChanged(); void hiddenChanged();

View File

@ -65,8 +65,8 @@ public Q_SLOTS:
void moveToDesktopCenter(); void moveToDesktopCenter();
void bringToFront(); void bringToFront();
void showSystemMenu(const QPoint &pos); void showSystemMenu(const QPoint &pos);
void startSystemMove2(); void startSystemMove2(const QPoint &pos);
void startSystemResize2(const Qt::Edges edges); void startSystemResize2(const Qt::Edges edges, const QPoint &pos);
Q_SIGNALS: Q_SIGNALS:
void hiddenChanged(); void hiddenChanged();

View File

@ -77,8 +77,8 @@ public Q_SLOTS:
void moveToDesktopCenter(); void moveToDesktopCenter();
void bringToFront(); void bringToFront();
void showSystemMenu(const QPoint &pos); void showSystemMenu(const QPoint &pos);
void startSystemMove2(); void startSystemMove2(const QPoint &pos);
void startSystemResize2(const Qt::Edges edges); void startSystemResize2(const Qt::Edges edges, const QPoint &pos);
protected: protected:
Q_NODISCARD bool eventFilter(QObject *object, QEvent *event) override; Q_NODISCARD bool eventFilter(QObject *object, QEvent *event) override;

View File

@ -50,8 +50,10 @@ Q_GLOBAL_STATIC(FramelessWindowsManagerHelper, g_helper)
Q_GLOBAL_STATIC(FramelessWindowsManager, g_manager) Q_GLOBAL_STATIC(FramelessWindowsManager, g_manager)
[[maybe_unused]] static constexpr const char QT_QPA_ENV_VAR[] = "QT_QPA_PLATFORM";
[[maybe_unused]] static constexpr const char MAC_LAYER_ENV_VAR[] = "QT_MAC_WANTS_LAYER"; [[maybe_unused]] static constexpr const char MAC_LAYER_ENV_VAR[] = "QT_MAC_WANTS_LAYER";
FRAMELESSHELPER_BYTEARRAY_CONSTANT2(OptionEnabled, "1") FRAMELESSHELPER_BYTEARRAY_CONSTANT(xcb)
FRAMELESSHELPER_BYTEARRAY_CONSTANT2(ValueOne, "1")
FramelessWindowsManagerPrivate::FramelessWindowsManagerPrivate(FramelessWindowsManager *q) : QObject(q) FramelessWindowsManagerPrivate::FramelessWindowsManagerPrivate(FramelessWindowsManager *q) : QObject(q)
{ {
@ -149,11 +151,6 @@ void FramelessWindowsManagerPrivate::addWindow(const UserSettings &settings, con
Utils::installSystemMenuHook(windowId, settings.options, settings.systemMenuOffset, params.isWindowFixedSize); Utils::installSystemMenuHook(windowId, settings.options, settings.systemMenuOffset, params.isWindowFixedSize);
} }
#endif #endif
#ifdef Q_OS_MACOS
if (qEnvironmentVariableIntValue(MAC_LAYER_ENV_VAR) != 1) {
qputenv(MAC_LAYER_ENV_VAR, kOptionEnabled);
}
#endif
} }
void FramelessWindowsManagerPrivate::notifySystemThemeHasChangedOrNot() void FramelessWindowsManagerPrivate::notifySystemThemeHasChangedOrNot()
@ -229,6 +226,19 @@ void FramelessHelper::Core::initialize(const Options options)
return; return;
} }
inited = true; inited = true;
#ifdef Q_OS_LINUX
// ### FIXME: Crash on Wayland, so we force xcb here.
// Remove this ugly hack when the crash is fixed!
// We are setting the preferred QPA backend, so we have to set it early
// enough, that is, before the construction of any Q(Gui)Application
// instances.
qputenv(QT_QPA_ENV_VAR, kxcb);
#endif
#ifdef Q_OS_MACOS
if (qEnvironmentVariableIntValue(MAC_LAYER_ENV_VAR) != 1) {
qputenv(MAC_LAYER_ENV_VAR, kValueOne);
}
#endif
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
if (!(options & Option::DontTouchProcessDpiAwarenessLevel)) { if (!(options & Option::DontTouchProcessDpiAwarenessLevel)) {
// This is equivalent to set the "dpiAware" and "dpiAwareness" field in // This is equivalent to set the "dpiAware" and "dpiAwareness" field in

View File

@ -58,13 +58,13 @@ FRAMELESSHELPER_STRING_CONSTANT(dark)
FRAMELESSHELPER_STRING_CONSTANT(highcontrast) FRAMELESSHELPER_STRING_CONSTANT(highcontrast)
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
[[nodiscard]] extern bool shouldAppsUseDarkMode_windows(); [[nodiscard]] extern bool shouldAppsUseDarkMode_windows();
#endif #endif
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
[[nodiscard]] extern bool shouldAppsUseDarkMode_linux(); [[nodiscard]] extern bool shouldAppsUseDarkMode_linux();
#endif #endif
#ifdef Q_OS_MACOS #ifdef Q_OS_MACOS
[[nodiscard]] extern bool shouldAppsUseDarkMode_macos(); [[nodiscard]] extern bool shouldAppsUseDarkMode_macos();
#endif #endif
Qt::CursorShape Utils::calculateCursorShape(const QWindow *window, const QPoint &pos) Qt::CursorShape Utils::calculateCursorShape(const QWindow *window, const QPoint &pos)

View File

@ -25,7 +25,6 @@
#include "utils.h" #include "utils.h"
#include <QtCore/qdebug.h> #include <QtCore/qdebug.h>
#include <QtCore/qregularexpression.h> #include <QtCore/qregularexpression.h>
#include <QtGui/qcursor.h>
#include <QtGui/qguiapplication.h> #include <QtGui/qguiapplication.h>
#include <QtGui/qwindow.h> #include <QtGui/qwindow.h>
#include <QtGui/qscreen.h> #include <QtGui/qscreen.h>
@ -40,7 +39,6 @@ FRAMELESSHELPER_BEGIN_NAMESPACE
using namespace Global; using namespace Global;
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
static constexpr const auto _NET_WM_MOVERESIZE_SIZE_TOPLEFT = 0; static constexpr const auto _NET_WM_MOVERESIZE_SIZE_TOPLEFT = 0;
static constexpr const auto _NET_WM_MOVERESIZE_SIZE_TOP = 1; static constexpr const auto _NET_WM_MOVERESIZE_SIZE_TOP = 1;
static constexpr const auto _NET_WM_MOVERESIZE_SIZE_TOPRIGHT = 2; static constexpr const auto _NET_WM_MOVERESIZE_SIZE_TOPRIGHT = 2;
@ -50,7 +48,6 @@ static constexpr const auto _NET_WM_MOVERESIZE_SIZE_BOTTOM = 5;
static constexpr const auto _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT = 6; static constexpr const auto _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT = 6;
static constexpr const auto _NET_WM_MOVERESIZE_SIZE_LEFT = 7; static constexpr const auto _NET_WM_MOVERESIZE_SIZE_LEFT = 7;
static constexpr const auto _NET_WM_MOVERESIZE_MOVE = 8; static constexpr const auto _NET_WM_MOVERESIZE_MOVE = 8;
#endif
static constexpr const char GTK_THEME_NAME_ENV_VAR[] = "GTK_THEME"; static constexpr const char GTK_THEME_NAME_ENV_VAR[] = "GTK_THEME";
static constexpr const char GTK_THEME_NAME_PROP[] = "gtk-theme-name"; static constexpr const char GTK_THEME_NAME_PROP[] = "gtk-theme-name";
@ -62,6 +59,8 @@ FRAMELESSHELPER_BYTEARRAY_CONSTANT(rootwindow)
FRAMELESSHELPER_STRING_CONSTANT2(GTK_THEME_DARK_REGEX, "[:-]dark") FRAMELESSHELPER_STRING_CONSTANT2(GTK_THEME_DARK_REGEX, "[:-]dark")
static constexpr const char WM_MOVERESIZE_OPERATION_NAME[] = "_NET_WM_MOVERESIZE";
template<typename T> template<typename T>
[[nodiscard]] static inline T gtkSetting(const gchar *propertyName) [[nodiscard]] static inline T gtkSetting(const gchar *propertyName)
{ {
@ -91,39 +90,37 @@ template<typename T>
return result; return result;
} }
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0)) [[nodiscard]] static inline int qtEdgesToWmMoveOrResizeOperation(const Qt::Edges edges)
[[nodiscard]] static inline Qt::WindowFrameSection qtEdgesToQtWindowFrameSection(const Qt::Edges edges)
{ {
if (edges == Qt::Edges{}) { if (edges == Qt::Edges{}) {
return Qt::NoSection; return -1;
} }
if (edges & Qt::TopEdge) { if (edges & Qt::TopEdge) {
if (edges & Qt::LeftEdge) { if (edges & Qt::LeftEdge) {
return Qt::TopLeftSection; return _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
} }
if (edges & Qt::RightEdge) { if (edges & Qt::RightEdge) {
return Qt::TopRightSection; return _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
} }
return Qt::TopSection; return _NET_WM_MOVERESIZE_SIZE_TOP;
} }
if (edges & Qt::BottomEdge) { if (edges & Qt::BottomEdge) {
if (edges & Qt::LeftEdge) { if (edges & Qt::LeftEdge) {
return Qt::BottomLeftSection; return _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
} }
if (edges & Qt::RightEdge) { if (edges & Qt::RightEdge) {
return Qt::BottomRightSection; return _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
} }
return Qt::BottomSection; return _NET_WM_MOVERESIZE_SIZE_BOTTOM;
} }
if (edges & Qt::LeftEdge) { if (edges & Qt::LeftEdge) {
return Qt::LeftSection; return _NET_WM_MOVERESIZE_SIZE_LEFT;
} }
if (edges & Qt::RightEdge) { if (edges & Qt::RightEdge) {
return Qt::RightSection; return _NET_WM_MOVERESIZE_SIZE_RIGHT;
} }
return Qt::NoSection; return -1;
} }
#endif
[[nodiscard]] bool shouldAppsUseDarkMode_linux() [[nodiscard]] bool shouldAppsUseDarkMode_linux()
{ {
@ -169,17 +166,18 @@ template<typename T>
return false; return false;
} }
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
[[nodiscard]] static inline Display *x11_get_display() [[nodiscard]] static inline Display *x11_get_display()
{ {
if (!qGuiApp) { if (!qGuiApp) {
return nullptr; return nullptr;
} }
QPlatformNativeInterface * const iface = qGuiApp->platformNativeInterface(); QPlatformNativeInterface * const iface = qGuiApp->platformNativeInterface();
Q_ASSERT(iface);
if (!iface) { if (!iface) {
return nullptr; return nullptr;
} }
const auto display = iface->nativeResourceForIntegration(kdisplay); const auto display = iface->nativeResourceForIntegration(kdisplay);
Q_ASSERT(display);
if (!display) { if (!display) {
return nullptr; return nullptr;
} }
@ -192,10 +190,12 @@ template<typename T>
return 0; return 0;
} }
QPlatformNativeInterface * const iface = qGuiApp->platformNativeInterface(); QPlatformNativeInterface * const iface = qGuiApp->platformNativeInterface();
Q_ASSERT(iface);
if (!iface) { if (!iface) {
return 0; return 0;
} }
const auto screen = iface->nativeResourceForIntegration(kx11screen); const auto screen = iface->nativeResourceForIntegration(kx11screen);
//Q_ASSERT(screen); // Always zero on both X11 and Wayland. Why? Is zero a valid value?
if (!screen) { if (!screen) {
return 0; return 0;
} }
@ -230,18 +230,21 @@ template<typename T>
return 0; return 0;
} }
QPlatformNativeInterface * const iface = qGuiApp->platformNativeInterface(); QPlatformNativeInterface * const iface = qGuiApp->platformNativeInterface();
Q_ASSERT(iface);
if (!iface) { if (!iface) {
return 0; return 0;
} }
QScreen * const screen = x11_getScreenForVirtualDesktop(desktop); QScreen * const screen = x11_getScreenForVirtualDesktop(desktop);
Q_ASSERT(screen);
if (!screen) { if (!screen) {
return 0; return 0;
} }
const auto rootWindow = iface->nativeResourceForScreen(krootwindow, screen); const auto window = iface->nativeResourceForScreen(krootwindow, screen);
if (!rootWindow) { Q_ASSERT(window); // Always zero on Wayland, non-zero on X11.
if (!window) {
return 0; return 0;
} }
return reinterpret_cast<quintptr>(rootWindow); return reinterpret_cast<quintptr>(window);
} }
static inline void x11_emulateButtonRelease(const WId windowId, const QPoint &globalPos, const QPoint &localPos) static inline void x11_emulateButtonRelease(const WId windowId, const QPoint &globalPos, const QPoint &localPos)
@ -250,11 +253,14 @@ static inline void x11_emulateButtonRelease(const WId windowId, const QPoint &gl
if (!windowId) { if (!windowId) {
return; return;
} }
const Window window = windowId;
Display * const display = x11_get_display(); Display * const display = x11_get_display();
Q_ASSERT(display);
if (!display) {
return;
}
const Window window = windowId;
XEvent event; XEvent event;
memset(&event, 0, sizeof(event)); memset(&event, 0, sizeof(event));
event.xbutton.button = 0;
event.xbutton.same_screen = True; event.xbutton.same_screen = True;
event.xbutton.send_event = True; event.xbutton.send_event = True;
event.xbutton.window = window; event.xbutton.window = window;
@ -274,23 +280,28 @@ static inline void x11_emulateButtonRelease(const WId windowId, const QPoint &gl
static inline void x11_moveOrResizeWindow(const WId windowId, const QPoint &pos, const int section) static inline void x11_moveOrResizeWindow(const WId windowId, const QPoint &pos, const int section)
{ {
Q_ASSERT(windowId); Q_ASSERT(windowId);
if (!windowId) { Q_ASSERT(section >= 0);
if (!windowId || (section < 0)) {
return; return;
} }
Display * const display = x11_get_display(); Display * const display = x11_get_display();
static const Atom netMoveResize = XInternAtom(display, "_NET_WM_MOVERESIZE", False); Q_ASSERT(display);
if (!display) {
return;
}
static const Atom netMoveResize = XInternAtom(display, WM_MOVERESIZE_OPERATION_NAME, False);
Q_ASSERT(netMoveResize);
if (!netMoveResize) {
return;
}
// First we need to ungrab the pointer that may have been // First we need to ungrab the pointer that may have been
// automatically grabbed by Qt on ButtonPressEvent // automatically grabbed by Qt on ButtonPressEvent
XUngrabPointer(display, CurrentTime); XUngrabPointer(display, CurrentTime);
XEvent event; XEvent event;
memset(&event, 0, sizeof(event)); memset(&event, 0, sizeof(event));
event.xclient.type = ClientMessage; event.xclient.type = ClientMessage;
event.xclient.window = windowId; event.xclient.window = windowId;
event.xclient.message_type = netMoveResize; event.xclient.message_type = netMoveResize;
event.xclient.serial = 0;
event.xclient.display = display; event.xclient.display = display;
event.xclient.send_event = True; event.xclient.send_event = True;
event.xclient.format = 32; event.xclient.format = 32;
@ -298,7 +309,6 @@ static inline void x11_moveOrResizeWindow(const WId windowId, const QPoint &pos,
event.xclient.data.l[1] = pos.y(); event.xclient.data.l[1] = pos.y();
event.xclient.data.l[2] = section; event.xclient.data.l[2] = section;
event.xclient.data.l[3] = Button1; event.xclient.data.l[3] = Button1;
event.xclient.data.l[4] = 0; // unused
if (XSendEvent(display, x11_get_window(x11_get_desktop()), if (XSendEvent(display, x11_get_window(x11_get_desktop()),
False, (SubstructureRedirectMask | SubstructureNotifyMask), &event) == 0) { False, (SubstructureRedirectMask | SubstructureNotifyMask), &event) == 0) {
qWarning() << "Failed to send _NET_WM_MOVERESIZE event for native dragging."; qWarning() << "Failed to send _NET_WM_MOVERESIZE event for native dragging.";
@ -306,53 +316,19 @@ static inline void x11_moveOrResizeWindow(const WId windowId, const QPoint &pos,
XFlush(display); XFlush(display);
} }
static inline void x11_windowStartNativeDrag(const WId windowId, const QPoint &globalPos, const QPoint &localPos, const Qt::WindowFrameSection frameSection) static inline void x11_windowStartNativeDrag(const WId windowId, const QPoint &globalPos, const QPoint &localPos, const int section)
{ {
Q_ASSERT(windowId); Q_ASSERT(windowId);
if (!windowId) { if (!windowId) {
return; return;
} }
int nativeSection = -1; if (section < 0) {
switch (frameSection)
{
case Qt::LeftSection:
nativeSection = _NET_WM_MOVERESIZE_SIZE_LEFT;
break;
case Qt::TopLeftSection:
nativeSection = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
break;
case Qt::TopSection:
nativeSection = _NET_WM_MOVERESIZE_SIZE_TOP;
break;
case Qt::TopRightSection:
nativeSection = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
break;
case Qt::RightSection:
nativeSection = _NET_WM_MOVERESIZE_SIZE_RIGHT;
break;
case Qt::BottomRightSection:
nativeSection = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
break;
case Qt::BottomSection:
nativeSection = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
break;
case Qt::BottomLeftSection:
nativeSection = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
break;
case Qt::TitleBarArea:
nativeSection = _NET_WM_MOVERESIZE_MOVE;
break;
default:
break;
}
if (nativeSection == -1) {
return; return;
} }
// Before start the drag we need to tell Qt that the mouse is Released! // Before we start dragging we need to tell Qt that the mouse is released.
x11_emulateButtonRelease(windowId, globalPos, localPos); x11_emulateButtonRelease(windowId, globalPos, localPos);
x11_moveOrResizeWindow(windowId, globalPos, nativeSection); x11_moveOrResizeWindow(windowId, globalPos, section);
} }
#endif
SystemTheme Utils::getSystemTheme() SystemTheme Utils::getSystemTheme()
{ {
@ -360,23 +336,21 @@ SystemTheme Utils::getSystemTheme()
return (shouldAppsUseDarkMode() ? SystemTheme::Dark : SystemTheme::Light); return (shouldAppsUseDarkMode() ? SystemTheme::Dark : SystemTheme::Light);
} }
void Utils::startSystemMove(QWindow *window) void Utils::startSystemMove(QWindow *window, const QPoint &globalPos)
{ {
Q_ASSERT(window); Q_ASSERT(window);
if (!window) { if (!window) {
return; return;
} }
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) // Qt always gives us logical coordinates, however, the native APIs
window->startSystemMove(); // are expecting device coordinates.
#else
const qreal dpr = window->devicePixelRatio(); const qreal dpr = window->devicePixelRatio();
const QPoint globalPos = QPointF(QPointF(QCursor::pos(window->screen())) * dpr).toPoint(); const QPoint globalPos2 = QPointF(QPointF(globalPos) * dpr).toPoint();
const QPoint localPos = QPointF(QPointF(window->mapFromGlobal(globalPos)) * dpr).toPoint(); const QPoint localPos2 = QPointF(QPointF(window->mapFromGlobal(globalPos)) * dpr).toPoint();
x11_windowStartNativeDrag(window->winId(), globalPos, localPos, Qt::TitleBarArea); x11_windowStartNativeDrag(window->winId(), globalPos2, localPos2, _NET_WM_MOVERESIZE_MOVE);
#endif
} }
void Utils::startSystemResize(QWindow *window, const Qt::Edges edges) void Utils::startSystemResize(QWindow *window, const Qt::Edges edges, const QPoint &globalPos)
{ {
Q_ASSERT(window); Q_ASSERT(window);
if (!window) { if (!window) {
@ -385,14 +359,16 @@ void Utils::startSystemResize(QWindow *window, const Qt::Edges edges)
if (edges == Qt::Edges{}) { if (edges == Qt::Edges{}) {
return; return;
} }
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) const int section = qtEdgesToWmMoveOrResizeOperation(edges);
window->startSystemResize(edges); if (section < 0) {
#else return;
}
// Qt always gives us logical coordinates, however, the native APIs
// are expecting device coordinates.
const qreal dpr = window->devicePixelRatio(); const qreal dpr = window->devicePixelRatio();
const QPoint globalPos = QPointF(QPointF(QCursor::pos(window->screen())) * dpr).toPoint(); const QPoint globalPos2 = QPointF(QPointF(globalPos) * dpr).toPoint();
const QPoint localPos = QPointF(QPointF(window->mapFromGlobal(globalPos)) * dpr).toPoint(); const QPoint localPos2 = QPointF(QPointF(window->mapFromGlobal(globalPos)) * dpr).toPoint();
x11_windowStartNativeDrag(window->winId(), globalPos, localPos, qtEdgesToQtWindowFrameSection(edges)); x11_windowStartNativeDrag(window->winId(), globalPos2, localPos2, section);
#endif
} }
FRAMELESSHELPER_END_NAMESPACE FRAMELESSHELPER_END_NAMESPACE

View File

@ -24,7 +24,6 @@
#include "framelessquickwindow.h" #include "framelessquickwindow.h"
#include "framelessquickwindow_p.h" #include "framelessquickwindow_p.h"
#include <QtGui/qcursor.h>
#include <QtQuick/private/qquickitem_p.h> #include <QtQuick/private/qquickitem_p.h>
#include <QtQuick/private/qquickrectangle_p.h> #include <QtQuick/private/qquickrectangle_p.h>
#include <QtQuick/private/qquickanchors_p.h> #include <QtQuick/private/qquickanchors_p.h>
@ -371,13 +370,13 @@ void FramelessQuickWindowPrivate::showSystemMenu(const QPoint &pos)
#endif #endif
} }
void FramelessQuickWindowPrivate::startSystemMove2() void FramelessQuickWindowPrivate::startSystemMove2(const QPoint &pos)
{ {
Q_Q(FramelessQuickWindow); Q_Q(FramelessQuickWindow);
Utils::startSystemMove(q, QCursor::pos(q->screen())); Utils::startSystemMove(q, pos);
} }
void FramelessQuickWindowPrivate::startSystemResize2(const Qt::Edges edges) void FramelessQuickWindowPrivate::startSystemResize2(const Qt::Edges edges, const QPoint &pos)
{ {
if (isFixedSize()) { if (isFixedSize()) {
return; return;
@ -386,7 +385,7 @@ void FramelessQuickWindowPrivate::startSystemResize2(const Qt::Edges edges)
return; return;
} }
Q_Q(FramelessQuickWindow); Q_Q(FramelessQuickWindow);
Utils::startSystemResize(q, edges, QCursor::pos(q->screen())); Utils::startSystemResize(q, edges, pos);
} }
void FramelessQuickWindowPrivate::initialize() void FramelessQuickWindowPrivate::initialize()
@ -607,8 +606,10 @@ void FramelessQuickWindowPrivate::mouseMoveEventHandler(QMouseEvent *event)
} }
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
const QPoint scenePos = event->scenePosition().toPoint(); const QPoint scenePos = event->scenePosition().toPoint();
const QPoint globalPos = event->globalPosition().toPoint();
#else #else
const QPoint scenePos = event->windowPos().toPoint(); const QPoint scenePos = event->windowPos().toPoint();
const QPoint globalPos = event->screenPos().toPoint();
#endif #endif
if (shouldIgnoreMouseEvents(scenePos)) { if (shouldIgnoreMouseEvents(scenePos)) {
return; return;
@ -616,7 +617,7 @@ void FramelessQuickWindowPrivate::mouseMoveEventHandler(QMouseEvent *event)
if (!isInTitleBarDraggableArea(scenePos)) { if (!isInTitleBarDraggableArea(scenePos)) {
return; return;
} }
startSystemMove2(); startSystemMove2(globalPos);
} }
void FramelessQuickWindowPrivate::mouseReleaseEventHandler(QMouseEvent *event) void FramelessQuickWindowPrivate::mouseReleaseEventHandler(QMouseEvent *event)
@ -807,19 +808,19 @@ void FramelessQuickWindow::showSystemMenu(const QPoint &pos)
d->showSystemMenu(pos); d->showSystemMenu(pos);
} }
void FramelessQuickWindow::startSystemMove2() void FramelessQuickWindow::startSystemMove2(const QPoint &pos)
{ {
Q_D(FramelessQuickWindow); Q_D(FramelessQuickWindow);
d->startSystemMove2(); d->startSystemMove2(pos);
} }
void FramelessQuickWindow::startSystemResize2(const Qt::Edges edges) void FramelessQuickWindow::startSystemResize2(const Qt::Edges edges, const QPoint &pos)
{ {
if (edges == Qt::Edges{}) { if (edges == Qt::Edges{}) {
return; return;
} }
Q_D(FramelessQuickWindow); Q_D(FramelessQuickWindow);
d->startSystemResize2(edges); d->startSystemResize2(edges, pos);
} }
FRAMELESSHELPER_END_NAMESPACE FRAMELESSHELPER_END_NAMESPACE

View File

@ -75,8 +75,8 @@ public Q_SLOTS:
void toggleMaximized(); void toggleMaximized();
void toggleFullScreen(); void toggleFullScreen();
void showSystemMenu(const QPoint &pos); void showSystemMenu(const QPoint &pos);
void startSystemMove2(); void startSystemMove2(const QPoint &pos);
void startSystemResize2(const Qt::Edges edges); void startSystemResize2(const Qt::Edges edges, const QPoint &pos);
void setTitleBarItem(QQuickItem *item); void setTitleBarItem(QQuickItem *item);
void setHitTestVisible(QQuickItem *item); void setHitTestVisible(QQuickItem *item);
void moveToDesktopCenter(); void moveToDesktopCenter();

View File

@ -96,14 +96,14 @@ void FramelessMainWindow::showSystemMenu(const QPoint &pos)
m_helper->showSystemMenu(pos); m_helper->showSystemMenu(pos);
} }
void FramelessMainWindow::startSystemMove2() void FramelessMainWindow::startSystemMove2(const QPoint &pos)
{ {
m_helper->startSystemMove2(); m_helper->startSystemMove2(pos);
} }
void FramelessMainWindow::startSystemResize2(const Qt::Edges edges) void FramelessMainWindow::startSystemResize2(const Qt::Edges edges, const QPoint &pos)
{ {
m_helper->startSystemResize2(edges); m_helper->startSystemResize2(edges, pos);
} }
FRAMELESSHELPER_END_NAMESPACE FRAMELESSHELPER_END_NAMESPACE

View File

@ -106,14 +106,14 @@ void FramelessWidget::showSystemMenu(const QPoint &pos)
m_helper->showSystemMenu(pos); m_helper->showSystemMenu(pos);
} }
void FramelessWidget::startSystemMove2() void FramelessWidget::startSystemMove2(const QPoint &pos)
{ {
m_helper->startSystemMove2(); m_helper->startSystemMove2(pos);
} }
void FramelessWidget::startSystemResize2(const Qt::Edges edges) void FramelessWidget::startSystemResize2(const Qt::Edges edges, const QPoint &pos)
{ {
m_helper->startSystemResize2(edges); m_helper->startSystemResize2(edges, pos);
} }
FRAMELESSHELPER_END_NAMESPACE FRAMELESSHELPER_END_NAMESPACE

View File

@ -27,7 +27,6 @@
#include <QtCore/qdebug.h> #include <QtCore/qdebug.h>
#include <QtGui/qpainter.h> #include <QtGui/qpainter.h>
#include <QtGui/qevent.h> #include <QtGui/qevent.h>
#include <QtGui/qcursor.h>
#include <QtWidgets/qboxlayout.h> #include <QtWidgets/qboxlayout.h>
#include <QtWidgets/qlabel.h> #include <QtWidgets/qlabel.h>
#include <framelesswindowsmanager.h> #include <framelesswindowsmanager.h>
@ -277,8 +276,10 @@ void FramelessWidgetsHelper::mouseMoveEventHandler(QMouseEvent *event)
} }
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
const QPoint scenePos = event->scenePosition().toPoint(); const QPoint scenePos = event->scenePosition().toPoint();
const QPoint globalPos = event->globalPosition().toPoint();
#else #else
const QPoint scenePos = event->windowPos().toPoint(); const QPoint scenePos = event->windowPos().toPoint();
const QPoint globalPos = event->screenPos().toPoint();
#endif #endif
if (shouldIgnoreMouseEvents(scenePos)) { if (shouldIgnoreMouseEvents(scenePos)) {
return; return;
@ -286,7 +287,7 @@ void FramelessWidgetsHelper::mouseMoveEventHandler(QMouseEvent *event)
if (!isInTitleBarDraggableArea(scenePos)) { if (!isInTitleBarDraggableArea(scenePos)) {
return; return;
} }
startSystemMove2(); startSystemMove2(globalPos);
} }
void FramelessWidgetsHelper::mouseReleaseEventHandler(QMouseEvent *event) void FramelessWidgetsHelper::mouseReleaseEventHandler(QMouseEvent *event)
@ -776,16 +777,14 @@ void FramelessWidgetsHelper::showSystemMenu(const QPoint &pos)
#endif #endif
} }
void FramelessWidgetsHelper::startSystemMove2() void FramelessWidgetsHelper::startSystemMove2(const QPoint &pos)
{ {
QWindow * const window = q->windowHandle(); Utils::startSystemMove(q->windowHandle(), pos);
Utils::startSystemMove(window, QCursor::pos(window->screen()));
} }
void FramelessWidgetsHelper::startSystemResize2(const Qt::Edges edges) void FramelessWidgetsHelper::startSystemResize2(const Qt::Edges edges, const QPoint &pos)
{ {
QWindow * const window = q->windowHandle(); Utils::startSystemResize(q->windowHandle(), edges, pos);
Utils::startSystemResize(window, edges, QCursor::pos(window->screen()));
} }
bool FramelessWidgetsHelper::eventFilter(QObject *object, QEvent *event) bool FramelessWidgetsHelper::eventFilter(QObject *object, QEvent *event)