diff --git a/src/core/flameshot.cpp b/src/core/flameshot.cpp index cf112d79..6ab5bb80 100644 --- a/src/core/flameshot.cpp +++ b/src/core/flameshot.cpp @@ -37,6 +37,7 @@ Flameshot::Flameshot() : m_captureWindow(nullptr) + , m_haveExternalWidget(false) #if defined(Q_OS_MACOS) , m_HotkeyScreenshotCapture(nullptr) , m_HotkeyScreenshotHistory(nullptr) @@ -411,12 +412,15 @@ void Flameshot::exportCapture(QPixmap capture, if (!(tasks & CR::UPLOAD)) { emit captureTaken(capture); } - // hacks: close a window to trigger qt's quitOnLastWindowClose - // if not create tmp_window and close, the `flameshot gui` won't exit after - // click copy button - QWidget* tmp = new QWidget(); - tmp->show(); - tmp->close(); +} + +void Flameshot::setExternalWidget(bool b) +{ + m_haveExternalWidget = b; +} +bool Flameshot::haveExternalWidget() +{ + return m_haveExternalWidget; } // STATIC ATTRIBUTES diff --git a/src/core/flameshot.h b/src/core/flameshot.h index ec8ce98c..01f13f8a 100644 --- a/src/core/flameshot.h +++ b/src/core/flameshot.h @@ -47,6 +47,8 @@ public slots: public: static void setOrigin(Origin origin); static Origin origin(); + void setExternalWidget(bool b); + bool haveExternalWidget(); signals: void captureTaken(QPixmap p); @@ -62,6 +64,7 @@ private: // class members static Origin m_origin; + bool m_haveExternalWidget; QPointer m_captureWindow; QPointer m_infoWindow; diff --git a/src/main.cpp b/src/main.cpp index 62d75b61..fd2768b3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -49,14 +49,19 @@ void requestCaptureAndWait(const CaptureRequest& req) { Flameshot* flameshot = Flameshot::instance(); flameshot->requestCapture(req); -#if defined(Q_OS_MACOS) - // Only useful on MacOS because each instance hosts its own widgets QObject::connect(flameshot, &Flameshot::captureTaken, [&](const QPixmap&) { +#if defined(Q_OS_MACOS) + // Only useful on MacOS because each instance hosts its own widgets if (!FlameshotDaemon::isThisInstanceHostingWidgets()) { qApp->exit(0); } - }); +#else + // if this instance is not daemon, make sure it exit after caputre finish + if (FlameshotDaemon::instance() == nullptr && !Flameshot::instance()->haveExternalWidget()) { + qApp->exit(0); + } #endif + }); QObject::connect(flameshot, &Flameshot::captureFailed, []() { AbstractLogger::info() << "Screenshot aborted."; qApp->exit(1); diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index 1f2bc24a..8e53aa2d 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/src/widgets/capture/capturewidget.cpp @@ -1200,6 +1200,7 @@ void CaptureWidget::handleToolSignal(CaptureTool::Request r) w->setAttribute(Qt::WA_DeleteOnClose); w->activateWindow(); w->show(); + Flameshot::instance()->setExternalWidget(true); } break; case CaptureTool::REQ_INCREASE_TOOL_SIZE: