Use image/png on Wayland to improve copy support (#1601)
* wayland clipboard testing * typo * cleanup
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/utils/filenamehandler.h"
|
||||
#include "src/utils/systemnotification.h"
|
||||
#include "utils/desktopinfo.h"
|
||||
#include <QApplication>
|
||||
#include <QBuffer>
|
||||
#include <QClipboard>
|
||||
@@ -25,6 +26,31 @@ ScreenshotSaver::ScreenshotSaver(const unsigned id)
|
||||
: m_id(id)
|
||||
{}
|
||||
|
||||
void ScreenshotSaver::saveToClipboardPng(const QPixmap& capture)
|
||||
{
|
||||
QByteArray array;
|
||||
QBuffer buffer{ &array };
|
||||
QImageWriter imageWriter{ &buffer, "PNG" };
|
||||
imageWriter.write(capture.toImage());
|
||||
|
||||
QPixmap pngPixmap;
|
||||
bool isLoaded = pngPixmap.loadFromData(
|
||||
reinterpret_cast<uchar*>(array.data()), array.size(), "PNG");
|
||||
if (isLoaded) {
|
||||
// Need to send message before copying to clipboard
|
||||
SystemNotification().sendMessage(
|
||||
QObject::tr("Capture saved to clipboard"));
|
||||
|
||||
QMimeData* mimeData = new QMimeData;
|
||||
mimeData->setData("image/png", array);
|
||||
QApplication::clipboard()->setMimeData(mimeData);
|
||||
} else {
|
||||
SystemNotification().sendMessage(
|
||||
QObject::tr("Error while saving to clipboard"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: If data is saved to the clipboard before the notification is sent via
|
||||
// dbus, the application freezes.
|
||||
void ScreenshotSaver::saveToClipboard(const QPixmap& capture)
|
||||
@@ -36,7 +62,16 @@ void ScreenshotSaver::saveToClipboard(const QPixmap& capture)
|
||||
saveToFilesystem(capture,
|
||||
ConfigHandler().savePath(),
|
||||
QObject::tr("Capture saved to clipboard."));
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
|
||||
if (DesktopInfo().waylandDectected()) {
|
||||
saveToClipboardPng(capture);
|
||||
} else {
|
||||
QApplication::clipboard()->setPixmap(capture);
|
||||
}
|
||||
#else
|
||||
QApplication::clipboard()->setPixmap(capture);
|
||||
#endif
|
||||
|
||||
}
|
||||
// Otherwise only save to clipboard
|
||||
else {
|
||||
@@ -67,7 +102,15 @@ void ScreenshotSaver::saveToClipboard(const QPixmap& capture)
|
||||
// Need to send message before copying to clipboard
|
||||
SystemNotification().sendMessage(
|
||||
QObject::tr("Capture saved to clipboard"));
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
|
||||
if (DesktopInfo().waylandDectected()) {
|
||||
saveToClipboardPng(capture);
|
||||
} else {
|
||||
QApplication::clipboard()->setPixmap(capture);
|
||||
}
|
||||
#else
|
||||
QApplication::clipboard()->setPixmap(capture);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ public:
|
||||
ScreenshotSaver(const unsigned id);
|
||||
|
||||
void saveToClipboard(const QPixmap& capture);
|
||||
void saveToClipboardPng(const QPixmap& capture);
|
||||
bool saveToFilesystem(const QPixmap& capture,
|
||||
const QString& path,
|
||||
const QString& messagePrefix);
|
||||
|
||||
Reference in New Issue
Block a user