diff --git a/src/blackgui/enableforframelesswindow.cpp b/src/blackgui/enableforframelesswindow.cpp index 18bc60b16..df1a8ea8f 100644 --- a/src/blackgui/enableforframelesswindow.cpp +++ b/src/blackgui/enableforframelesswindow.cpp @@ -29,6 +29,8 @@ #include #include #include +#include +#include using namespace BlackMisc; @@ -127,6 +129,8 @@ namespace BlackGui if (m_isMainApplicationWindow && CGuiUtility::isTopLevelWindow(m_widget)) { m_widget->setAttribute(Qt::WA_NativeWindow); + + // causeing a BLACK background m_widget->setAttribute(Qt::WA_NoSystemBackground, frameless); m_widget->setAttribute(Qt::WA_TranslucentBackground, frameless); // causing QTBUG-52206 } @@ -181,7 +185,7 @@ namespace BlackGui bool CEnableForFramelessWindow::handleMouseMoveEvent(QMouseEvent *event) { Q_ASSERT(m_widget); - if (m_windowMode == WindowFrameless && event->buttons() & Qt::LeftButton) + if (m_windowMode == WindowFrameless && event->buttons() & Qt::LeftButton && !m_framelessDragPosition.isNull()) { m_widget->move(event->globalPos() - m_framelessDragPosition); event->accept(); @@ -194,16 +198,21 @@ namespace BlackGui { if (event->type() != QEvent::WindowStateChange) { return false; } if (m_windowMode != WindowTool) { return false; } + if (!m_widget) { return false; } // make sure a tool window is changed to Normal window so it is show in taskbar // here we are already in transition state, so isMinimized means will be minimize right now // this check here is needed if minimized is called from somewhere else than ps_showMinimized + + QPointer widgetSelf(m_widget); // almost as good as myself if (m_widget->isMinimized()) { // still tool, force normal window // decouple, otherwise we end up in infinite loop as it triggers a new changeEvent - BlackMisc::singleShot(0, QThread::currentThread(), [ = ]() + + QTimer::singleShot(0, m_widget, [ = ] { + if (!widgetSelf) { return; } this->showMinimizedModeChecked(); }); } @@ -211,8 +220,9 @@ namespace BlackGui { // not tool, force tool window // decouple, otherwise we end up in infinite loop as it triggers a new changeEvent - BlackMisc::singleShot(0, QThread::currentThread(), [ = ]() + QTimer::singleShot(0, m_widget, [ = ] { + if (!widgetSelf) { return; } this->showNormalModeChecked(); }); } diff --git a/src/blackgui/enableforframelesswindow.h b/src/blackgui/enableforframelesswindow.h index a168276ee..a4e7f9b5d 100644 --- a/src/blackgui/enableforframelesswindow.h +++ b/src/blackgui/enableforframelesswindow.h @@ -87,7 +87,7 @@ namespace BlackGui static const QString &windowModeToString(WindowMode m); protected: - QPoint m_framelessDragPosition; //!< position, if moving is handled with frameless window */ + QPoint m_framelessDragPosition; //!< position, if moving is handled with frameless window QPushButton *m_framelessCloseButton = nullptr; //!< close button WindowMode m_windowMode = WindowNormal; //!< Window mode, \sa WindowMode WindowMode m_originalWindowMode = WindowNormal; //!< mode when initialized diff --git a/src/swiftguistandard/swiftguistd.cpp b/src/swiftguistandard/swiftguistd.cpp index 47f2693ac..3798c425f 100644 --- a/src/swiftguistandard/swiftguistd.cpp +++ b/src/swiftguistandard/swiftguistd.cpp @@ -94,6 +94,12 @@ void SwiftGuiStd::mousePressEvent(QMouseEvent *event) if (!handleMousePressEvent(event)) { QMainWindow::mousePressEvent(event); } } +void SwiftGuiStd::mouseReleaseEvent(QMouseEvent *event) +{ + m_framelessDragPosition = QPoint(); + QMainWindow::mouseReleaseEvent(event); +} + void SwiftGuiStd::performGracefulShutdown() { if (!m_init) { return; } diff --git a/src/swiftguistandard/swiftguistd.h b/src/swiftguistandard/swiftguistd.h index f3057d97b..3c5503158 100644 --- a/src/swiftguistandard/swiftguistd.h +++ b/src/swiftguistandard/swiftguistd.h @@ -85,6 +85,7 @@ protected: //! @{ virtual void mouseMoveEvent(QMouseEvent *event) override; virtual void mousePressEvent(QMouseEvent *event) override; + virtual void mouseReleaseEvent(QMouseEvent *event) override; virtual void closeEvent(QCloseEvent *event) override; virtual void changeEvent(QEvent *event) override; //! @} diff --git a/src/swiftlauncher/swiftlauncher.cpp b/src/swiftlauncher/swiftlauncher.cpp index c8beb2f64..dbb8b5443 100644 --- a/src/swiftlauncher/swiftlauncher.cpp +++ b/src/swiftlauncher/swiftlauncher.cpp @@ -124,11 +124,22 @@ CoreModes::CoreMode CSwiftLauncher::getCoreMode() const return CoreModes::CoreInGuiProcess; } +void CSwiftLauncher::mousePressEvent(QMouseEvent *event) +{ + if (!handleMousePressEvent(event)) { QDialog::mousePressEvent(event); } +} + void CSwiftLauncher::mouseMoveEvent(QMouseEvent *event) { if (!handleMouseMoveEvent(event)) { QDialog::mouseMoveEvent(event); } } +void CSwiftLauncher::mouseReleaseEvent(QMouseEvent *event) +{ + m_framelessDragPosition = QPoint(); + QDialog::mouseReleaseEvent(event); +} + void CSwiftLauncher::displayLatestNews(QNetworkReply *reply) { QScopedPointer nwReply(reply); @@ -157,11 +168,6 @@ void CSwiftLauncher::updateInfoAvailable() this->loadLatestNews(); } -void CSwiftLauncher::mousePressEvent(QMouseEvent *event) -{ - if (!handleMousePressEvent(event)) { QDialog::mousePressEvent(event); } -} - void CSwiftLauncher::init() { Q_ASSERT_X(sGui, Q_FUNC_INFO, "Need sGui"); diff --git a/src/swiftlauncher/swiftlauncher.h b/src/swiftlauncher/swiftlauncher.h index f2d076ba6..890ebe84b 100644 --- a/src/swiftlauncher/swiftlauncher.h +++ b/src/swiftlauncher/swiftlauncher.h @@ -73,11 +73,11 @@ public: bool startDetached(); protected: - //! \copydoc QDialog::mousePressEvent + //! Mouse events for frameless window @{ virtual void mousePressEvent(QMouseEvent *event) override; - - //! \copydoc QDialog::mouseMoveEvent - void mouseMoveEvent(QMouseEvent *event) override; + virtual void mouseMoveEvent(QMouseEvent *event) override; + virtual void mouseReleaseEvent(QMouseEvent *event) override; + //! @} private slots: //! Show the log page