Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue about externalWidget launchapp #2698

Merged
merged 1 commit into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/core/flameshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

Flameshot::Flameshot()
: m_captureWindow(nullptr)
, m_haveExternalWidget(false)
#if defined(Q_OS_MACOS)
, m_HotkeyScreenshotCapture(nullptr)
, m_HotkeyScreenshotHistory(nullptr)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/core/flameshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -62,6 +64,7 @@ public slots:

// class members
static Origin m_origin;
bool m_haveExternalWidget;

QPointer<CaptureWidget> m_captureWindow;
QPointer<InfoWindow> m_infoWindow;
Expand Down
11 changes: 8 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/widgets/capture/capturewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down