mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-08-03 10:14:45 +00:00
Merge branch 'lnj/plasma-phone-components-fix/screen-not-fully-captured'
This commit is contained in:
commit
913b9d6db9
1 changed files with 42 additions and 35 deletions
|
|
@ -80,47 +80,54 @@ void PhonePanel::toggleTorch()
|
||||||
|
|
||||||
void PhonePanel::takeScreenshot()
|
void PhonePanel::takeScreenshot()
|
||||||
{
|
{
|
||||||
auto *interface = new org::kde::kwin::Screenshot(QStringLiteral("org.kde.KWin"), QStringLiteral("/Screenshot"), QDBusConnection::sessionBus(), this);
|
// wait ~200 ms to wait for rest of animations
|
||||||
QDBusPendingReply<QString> reply = interface->screenshotFullscreen();
|
QTimer::singleShot(200, [=]() {
|
||||||
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
|
auto *interface = new org::kde::kwin::Screenshot(QStringLiteral("org.kde.KWin"), QStringLiteral("/Screenshot"), QDBusConnection::sessionBus(), this);
|
||||||
|
|
||||||
connect(watcher, &QDBusPendingCallWatcher::finished, this, [=](QDBusPendingCallWatcher *watcher) {
|
// screenshot fullscreen currently doesn't work on all devices -> we need to use screenshot area
|
||||||
QDBusPendingReply<QString> reply = *watcher;
|
// this won't work with multiple screens
|
||||||
|
QSize screenSize = QGuiApplication::primaryScreen()->size();
|
||||||
|
QDBusPendingReply<QString> reply = interface->screenshotArea(0, 0, screenSize.width(), screenSize.height());
|
||||||
|
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
|
||||||
|
|
||||||
if (reply.isError()) {
|
connect(watcher, &QDBusPendingCallWatcher::finished, this, [=](QDBusPendingCallWatcher *watcher) {
|
||||||
qWarning() << "Creating the screenshot failed:" << reply.error().name() << reply.error().message();
|
QDBusPendingReply<QString> reply = *watcher;
|
||||||
} else {
|
|
||||||
QString filePath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
|
|
||||||
if (filePath.isEmpty()) {
|
|
||||||
qWarning() << "Couldn't find a writable location for the screenshot! The screenshot is in /tmp.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QDir picturesDir(filePath);
|
if (reply.isError()) {
|
||||||
if (!picturesDir.mkpath(QStringLiteral("Screenshots"))) {
|
qWarning() << "Creating the screenshot failed:" << reply.error().name() << reply.error().message();
|
||||||
qWarning() << "Couldn't create folder at"
|
} else {
|
||||||
<< picturesDir.path() + QStringLiteral("/Screenshots")
|
QString filePath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
|
||||||
<< "to take screenshot.";
|
if (filePath.isEmpty()) {
|
||||||
return;
|
qWarning() << "Couldn't find a writable location for the screenshot! The screenshot is in /tmp.";
|
||||||
}
|
return;
|
||||||
|
|
||||||
filePath += QStringLiteral("/Screenshots/Screenshot_%1.png")
|
|
||||||
.arg(QDateTime::currentDateTime().toString(QStringLiteral("yyyyMMdd_hhmmss")));
|
|
||||||
|
|
||||||
const QString currentPath = reply.argumentAt<0>();
|
|
||||||
QtConcurrent::run(QThreadPool::globalInstance(), [=]() {
|
|
||||||
QFile screenshotFile(currentPath);
|
|
||||||
if (!screenshotFile.rename(filePath)) {
|
|
||||||
qWarning() << "Couldn't move screenshot into Pictures folder:"
|
|
||||||
<< screenshotFile.errorString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Successfully saved screenshot at" << filePath;
|
QDir picturesDir(filePath);
|
||||||
});
|
if (!picturesDir.mkpath(QStringLiteral("Screenshots"))) {
|
||||||
}
|
qWarning() << "Couldn't create folder at"
|
||||||
|
<< picturesDir.path() + QStringLiteral("/Screenshots")
|
||||||
|
<< "to take screenshot.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
watcher->deleteLater();
|
filePath += QStringLiteral("/Screenshots/Screenshot_%1.png")
|
||||||
interface->deleteLater();
|
.arg(QDateTime::currentDateTime().toString(QStringLiteral("yyyyMMdd_hhmmss")));
|
||||||
|
|
||||||
|
const QString currentPath = reply.argumentAt<0>();
|
||||||
|
QtConcurrent::run(QThreadPool::globalInstance(), [=]() {
|
||||||
|
QFile screenshotFile(currentPath);
|
||||||
|
if (!screenshotFile.rename(filePath)) {
|
||||||
|
qWarning() << "Couldn't move screenshot into Pictures folder:"
|
||||||
|
<< screenshotFile.errorString();
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "Successfully saved screenshot at" << filePath;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
watcher->deleteLater();
|
||||||
|
interface->deleteLater();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue