Commit 72cd3425 authored by Hennadii Chernyshchyk's avatar Hennadii Chernyshchyk
Browse files

Do not display screenshot dialog if interactive is set to false

BUG: 435781
parent 24445b6b
......@@ -105,10 +105,12 @@ uint ScreenshotPortal::Screenshot(const QDBusObjectPath &handle,
const bool interactive = options.value(QStringLiteral("interactive"), false).toBool();
if (!interactive) {
screenshotDialog->takeScreenshot();
screenshotDialog->takeScreenshotNonInteractive();
} else {
screenshotDialog->exec();
}
QImage screenshot = screenshotDialog->exec() ? screenshotDialog->image() : QImage();
const QImage screenshot = screenshotDialog->image();
if (screenshotDialog) {
screenshotDialog->deleteLater();
......
......@@ -99,21 +99,28 @@ ScreenshotDialog::~ScreenshotDialog()
{
delete m_dialog;
}
void ScreenshotDialog::takeScreenshot()
QImage ScreenshotDialog::image() const
{
int pipeFds[2];
if (pipe2(pipeFds, O_CLOEXEC | O_NONBLOCK) != 0) {
Q_EMIT failed();
return m_image;
}
void ScreenshotDialog::takeScreenshotNonInteractive()
{
QFuture<QImage> future = takeScreenshot();
if (!future.isStarted()) {
return;
}
QDBusInterface interface(QStringLiteral("org.kde.KWin"), QStringLiteral("/Screenshot"), QStringLiteral("org.kde.kwin.Screenshot"));
if (m_dialog->areaComboBox->currentIndex() < 2) {
interface.asyncCall(m_dialog->areaComboBox->currentIndex() ? QStringLiteral("screenshotScreen") : QStringLiteral("screenshotFullscreen"),
QVariant::fromValue(QDBusUnixFileDescriptor(pipeFds[1])),
m_dialog->includeCursorCheckbox->isChecked());
} else {
interface.asyncCall(QStringLiteral("interactive"), QVariant::fromValue(QDBusUnixFileDescriptor(pipeFds[1])), mask());
future.waitForFinished();
m_image = future.result();
}
void ScreenshotDialog::takeScreenshotInteractive()
{
const QFuture<QImage> future = takeScreenshot();
if (!future.isStarted()) {
return;
}
QFutureWatcher<QImage> *watcher = new QFutureWatcher<QImage>(this);
......@@ -124,14 +131,7 @@ void ScreenshotDialog::takeScreenshot()
m_dialog->buttonBox->button(QDialogButtonBox::Save)->setEnabled(true);
});
watcher->setFuture(QtConcurrent::run(readImage, pipeFds[0]));
::close(pipeFds[1]);
}
QImage ScreenshotDialog::image() const
{
return m_image;
watcher->setFuture(future);
}
int ScreenshotDialog::mask()
......@@ -145,3 +145,24 @@ int ScreenshotDialog::mask()
}
return mask;
}
QFuture<QImage> ScreenshotDialog::takeScreenshot()
{
int pipeFds[2];
if (pipe2(pipeFds, O_CLOEXEC | O_NONBLOCK) != 0) {
Q_EMIT failed();
return {};
}
QDBusInterface interface(QStringLiteral("org.kde.KWin"), QStringLiteral("/Screenshot"), QStringLiteral("org.kde.kwin.Screenshot"));
if (m_dialog->areaComboBox->currentIndex() < 2) {
interface.asyncCall(m_dialog->areaComboBox->currentIndex() ? QStringLiteral("screenshotScreen") : QStringLiteral("screenshotFullscreen"),
QVariant::fromValue(QDBusUnixFileDescriptor(pipeFds[1])),
m_dialog->includeCursorCheckbox->isChecked());
} else {
interface.asyncCall(QStringLiteral("interactive"), QVariant::fromValue(QDBusUnixFileDescriptor(pipeFds[1])), mask());
}
::close(pipeFds[1]);
return QtConcurrent::run(readImage, pipeFds[0]);
}
......@@ -22,6 +22,7 @@
#define XDG_DESKTOP_PORTAL_KDE_SCREENSHOT_DIALOG_H
#include <QDialog>
#include <QFuture>
namespace Ui
{
......@@ -37,8 +38,10 @@ public:
QImage image() const;
public Q_SLOTS:
void takeScreenshot();
void takeScreenshotNonInteractive();
private Q_SLOTS:
void takeScreenshotInteractive();
Q_SIGNALS:
void failed();
......@@ -48,6 +51,7 @@ private:
QImage m_image;
int mask();
QFuture<QImage> takeScreenshot();
};
#endif // XDG_DESKTOP_PORTAL_KDE_SCREENSHOT_DIALOG_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment