From 1e3d68df1c7442a380a23a854a67552ea2973077 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Sat, 24 Jun 2023 16:43:31 +0800 Subject: [PATCH] fix: disable resizing and moving in maximized or fullscreen window --- app/framelesswindow.cpp | 34 ++++++++++++++++++---------------- app/mainwindow.cpp | 2 +- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/app/framelesswindow.cpp b/app/framelesswindow.cpp index 510afe9..d5c0a39 100644 --- a/app/framelesswindow.cpp +++ b/app/framelesswindow.cpp @@ -68,24 +68,26 @@ bool FramelessWindow::eventFilter(QObject* o, QEvent* e) bool FramelessWindow::mouseHover(QHoverEvent* event, QWidget* wg) { - QWindow* win = window()->windowHandle(); - Qt::Edges edges = this->getEdgesByPos(wg->mapToGlobal(event->oldPos()), win->frameGeometry()); + if (!isMaximized() && !isFullScreen()) { + QWindow* win = window()->windowHandle(); + Qt::Edges edges = this->getEdgesByPos(wg->mapToGlobal(event->oldPos()), win->frameGeometry()); - // backup & restore cursor shape - if (edges && !m_oldEdges) - // entering the edge. backup cursor shape - m_oldCursorShape = win->cursor().shape(); - if (!edges && m_oldEdges) - // leaving the edge. restore cursor shape - win->setCursor(m_oldCursorShape); + // backup & restore cursor shape + if (edges && !m_oldEdges) + // entering the edge. backup cursor shape + m_oldCursorShape = win->cursor().shape(); + if (!edges && m_oldEdges) + // leaving the edge. restore cursor shape + win->setCursor(m_oldCursorShape); - // save the latest edges status - m_oldEdges = edges; + // save the latest edges status + m_oldEdges = edges; - // show resize cursor shape if cursor is within border - if (edges) { - win->setCursor(this->getCursorByEdge(edges, Qt::ArrowCursor)); - return true; + // show resize cursor shape if cursor is within border + if (edges) { + win->setCursor(this->getCursorByEdge(edges, Qt::ArrowCursor)); + return true; + } } return false; @@ -93,7 +95,7 @@ bool FramelessWindow::mouseHover(QHoverEvent* event, QWidget* wg) bool FramelessWindow::mousePress(QMouseEvent* event) { - if (event->buttons() & Qt::LeftButton && !isMaximized()) { + if (event->buttons() & Qt::LeftButton && !isMaximized() && !isFullScreen()) { QWindow* win = window()->windowHandle(); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) Qt::Edges edges = this->getEdgesByPos(event->globalPosition().toPoint(), win->frameGeometry()); diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index eb2c08e..75ac843 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -328,7 +328,7 @@ void MainWindow::mousePressEvent(QMouseEvent *event) void MainWindow::mouseMoveEvent(QMouseEvent *event) { - if (event->buttons() & Qt::LeftButton && m_clickedOnWindow && !isMaximized()) { + if (event->buttons() & Qt::LeftButton && m_clickedOnWindow && !isMaximized() && !isFullScreen()) { if (!window()->windowHandle()->startSystemMove()) { #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) move(event->globalPosition().toPoint() - m_oldMousePos);