From 3973c2f38d7b18fb11632e0affda7f9b5c161666 Mon Sep 17 00:00:00 2001 From: Yuriy Puchkov Date: Mon, 8 Feb 2021 15:14:56 +0200 Subject: [PATCH] Remove possibility of the infinitive loop on screen capture and remove activeModalWidget check on screen capture for MacOS (cherry picked from commit 305e054c9c97e47e092ad974a683cdf5753ab4a9) --- src/core/controller.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/core/controller.cpp b/src/core/controller.cpp index 2f05e0cc..cbd21bb1 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -36,11 +36,13 @@ #include #include #include +#include #include #include #include #include #include +#include #ifdef Q_OS_WIN #include "src/core/globalshortcutfilter.h" @@ -262,15 +264,29 @@ void Controller::startVisualCapture(const uint id, } #endif - if (!m_captureWindow) { - QWidget* modalWidget = nullptr; - do { - modalWidget = qApp->activeModalWidget(); + if (nullptr == m_captureWindow) { +#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \ + defined(Q_OS_MACX)) + // It seems that the following code is not required for MacOS because it + // has another type of CaptureWidget editor (FullScreen instead Flags: + // Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::Popup + int timeout = 5000; // 5 seconds + for (; timeout >= 0; timeout -= 10) { + qDebug() << "timeout" << timeout; + QWidget* modalWidget = qApp->activeModalWidget(); if (modalWidget) { modalWidget->close(); modalWidget->deleteLater(); + } else { + break; } - } while (modalWidget); + QThread::msleep(10); + } + if (0 == timeout) { + QMessageBox::warning( + nullptr, tr("Error"), tr("Unable to close active modal widgets")); + } +#endif m_captureWindow = new CaptureWidget(id, forcedSavePath); // m_captureWindow = new CaptureWidget(id, forcedSavePath, false); //