refactor: WlClipbaord::add use QProcess to set the clipboard
This commit is contained in:
parent
21900ade68
commit
ab4feaa037
2 changed files with 25 additions and 12 deletions
|
|
@ -179,6 +179,11 @@ WlClipboard::WlClipboard(ClipboardID id) : m_id(id), m_useClipboard(id == kClipb
|
||||||
WlClipboard::~WlClipboard()
|
WlClipboard::~WlClipboard()
|
||||||
{
|
{
|
||||||
stopMonitoring();
|
stopMonitoring();
|
||||||
|
for (auto &cmd : m_runningWlCopies) {
|
||||||
|
cmd->kill();
|
||||||
|
cmd->waitForFinished(100);
|
||||||
|
}
|
||||||
|
m_runningWlCopies.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
ClipboardID WlClipboard::getID() const
|
ClipboardID WlClipboard::getID() const
|
||||||
|
|
@ -261,26 +266,29 @@ void WlClipboard::add(Format format, const std::string &data)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto mimeType = formatToMimeType(format).toStdString();
|
auto mimeType = formatToMimeType(format);
|
||||||
if (mimeType.empty()) {
|
if (mimeType.isEmpty()) {
|
||||||
LOG_WARN("unsupported clipboard format: %d", format);
|
LOG_WARN("unsupported clipboard format: %d", format);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<const char *> args;
|
auto cmd = new QProcess(this);
|
||||||
if (m_useClipboard) {
|
cmd->setProgram(s_copyApp);
|
||||||
args = {"wl-copy", "-t", mimeType.c_str(), nullptr};
|
|
||||||
} else {
|
|
||||||
args = {"wl-copy", "-t", mimeType.c_str(), "-p", nullptr};
|
|
||||||
}
|
|
||||||
|
|
||||||
bool success = executeCommandWithInput(args, data);
|
m_runningWlCopies.append(cmd);
|
||||||
if (success) {
|
connect(cmd, &QProcess::finished, this, [&] { m_runningWlCopies.removeAll(cmd); });
|
||||||
|
|
||||||
|
QStringList args = {s_noNewLine, s_readType.arg(mimeType), QString::fromStdString(data)};
|
||||||
|
if (!m_useClipboard)
|
||||||
|
args.prepend(s_isPrimary);
|
||||||
|
|
||||||
|
cmd->setArguments(args);
|
||||||
|
cmd->start();
|
||||||
|
|
||||||
|
if (cmd->waitForStarted(100)) {
|
||||||
std::scoped_lock<std::mutex> lock(m_cacheMutex);
|
std::scoped_lock<std::mutex> lock(m_cacheMutex);
|
||||||
updateOwnership(true);
|
updateOwnership(true);
|
||||||
invalidateCache();
|
invalidateCache();
|
||||||
} else {
|
|
||||||
LOG_WARN("failed to set clipboard data");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
class QProcess;
|
||||||
//! Wayland clipboard implementation using wl-copy/wl-paste
|
//! Wayland clipboard implementation using wl-copy/wl-paste
|
||||||
/*!
|
/*!
|
||||||
This class implements clipboard functionality for Wayland environments
|
This class implements clipboard functionality for Wayland environments
|
||||||
|
|
@ -115,4 +117,7 @@ private:
|
||||||
|
|
||||||
// Clipboard selection type (true = clipboard, false = primary)
|
// Clipboard selection type (true = clipboard, false = primary)
|
||||||
bool m_useClipboard;
|
bool m_useClipboard;
|
||||||
|
|
||||||
|
// Hold a ref to running wl-copy processes
|
||||||
|
QList<QProcess *> m_runningWlCopies;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue