Commit 877744df authored by Méven Car's avatar Méven Car Committed by Méven Car
Browse files

Wayland: Allow to copy to clipboard img while in dbus or background mode

BUG: 429390
parent d9444ac8
Pipeline #109111 passed with stage
in 48 seconds
......@@ -12,7 +12,7 @@ cmake_minimum_required (VERSION 3.16 FATAL_ERROR)
project(Spectacle VERSION ${SPECTACLE_VERSION})
set(QT_MIN_VERSION "5.15.0")
set(KF5_MIN_VERSION "5.73.0")
set(KF5_MIN_VERSION "5.89.0")
find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
......@@ -66,6 +66,7 @@ find_package(
GlobalAccel
XmlGui
Wayland
GuiAddons
)
# optional components
......
......@@ -94,6 +94,7 @@ target_link_libraries(
KF5::GlobalAccel
KF5::XmlGui
KF5::WaylandClient
KF5::GuiAddons
)
install(TARGETS spectacle ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
......@@ -23,6 +23,7 @@
#include <QString>
#include <QTemporaryDir>
#include <QTemporaryFile>
#include <QWindow>
#include <KIO/FileCopyJob>
#include <KIO/ListJob>
......@@ -30,8 +31,8 @@
#include <KIO/StatJob>
#include <KRecentDocument>
#include <KSharedConfig>
#include <KSystemClipboard>
#include <KWindowSystem>
#include <QWindow>
ExportManager::ExportManager(QObject *parent)
: QObject(parent)
......@@ -51,6 +52,8 @@ ExportManager::~ExportManager()
ExportManager *ExportManager::instance()
{
static ExportManager instance;
// Ensure the SystemClipboard is instantiated early enough
KSystemClipboard::instance();
return &instance;
}
......@@ -536,29 +539,13 @@ void ExportManager::doSaveAndCopy(const QUrl &url)
// misc helpers
void ExportManager::doCopyToClipboard(bool notify)
{
const auto copyToClipboard = [this, notify]() {
auto data = new QMimeData();
data->setImageData(mSavePixmap.toImage());
data->setData(QStringLiteral("x-kde-force-image-copy"), QByteArray());
QApplication::clipboard()->setMimeData(data, QClipboard::Clipboard);
Q_EMIT imageCopied();
if (notify) {
Q_EMIT forceNotify(QUrl());
}
};
if (KWindowSystem::isPlatformWayland() && !QGuiApplication::focusWindow()) {
// under wayland you can copy to clipboard only from a focused window
// delay the copy until after a window has focus
QMetaObject::Connection *connection = new QMetaObject::Connection;
*connection = connect(qApp, &QGuiApplication::focusWindowChanged, this, [copyToClipboard, connection](const QWindow *) {
disconnect(*connection);
delete connection;
copyToClipboard();
});
} else {
copyToClipboard();
auto data = new QMimeData();
data->setImageData(mSavePixmap.toImage());
data->setData(QStringLiteral("x-kde-force-image-copy"), QByteArray());
KSystemClipboard::instance()->setMimeData(data, QClipboard::Clipboard);
Q_EMIT imageCopied();
if (notify) {
Q_EMIT forceNotify(QUrl());
}
}
......
......@@ -13,5 +13,5 @@ ecm_add_test(
${FILENAME_TEST_SRCS}
TEST_NAME "filename_test"
LINK_LIBRARIES Qt::Test
Qt::PrintSupport KF5::I18n KF5::ConfigCore KF5::GlobalAccel KF5::KIOCore KF5::WindowSystem KF5::XmlGui
Qt::PrintSupport KF5::I18n KF5::ConfigCore KF5::GlobalAccel KF5::KIOCore KF5::WindowSystem KF5::XmlGui KF5::GuiAddons
)
Markdown is supported
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