Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma
KDE Portal for XDG Desktop
Commits
72cd3425
Commit
72cd3425
authored
May 01, 2021
by
Hennadii Chernyshchyk
Browse files
Do not display screenshot dialog if interactive is set to false
BUG: 435781
parent
24445b6b
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/screenshot.cpp
View file @
72cd3425
...
...
@@ -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
()
:
QI
mage
();
const
QImage
screenshot
=
screenshotDialog
->
i
mage
();
if
(
screenshotDialog
)
{
screenshotDialog
->
deleteLater
();
...
...
src/screenshotdialog.cpp
View file @
72cd3425
...
...
@@ -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
]);
}
src/screenshotdialog.h
View file @
72cd3425
...
...
@@ -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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment