chore: rename src/lib/platform/WaylandClipboard -> src/lib/platform/WlClipboard
This commit is contained in:
parent
e55c67fa2f
commit
bbabb91d42
8 changed files with 108 additions and 112 deletions
|
|
@ -139,8 +139,8 @@ elseif(UNIX)
|
||||||
EiKeyState.h
|
EiKeyState.h
|
||||||
EiScreen.cpp
|
EiScreen.cpp
|
||||||
EiScreen.h
|
EiScreen.h
|
||||||
WaylandClipboard.cpp
|
WlClipboard.cpp
|
||||||
WaylandClipboard.h
|
WlClipboard.h
|
||||||
)
|
)
|
||||||
# The Portal sources also require EI.
|
# The Portal sources also require EI.
|
||||||
if(LIBPORTAL_FOUND)
|
if(LIBPORTAL_FOUND)
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ void EiClipboard::resetChanged()
|
||||||
void EiClipboard::initialize()
|
void EiClipboard::initialize()
|
||||||
{
|
{
|
||||||
// Check if Wayland clipboard is available
|
// Check if Wayland clipboard is available
|
||||||
if (!WaylandClipboard::isAvailable()) {
|
if (!WlClipboard::isAvailable()) {
|
||||||
LOG_WARN("wl-clipboard tools not found, clipboard functionality disabled");
|
LOG_WARN("wl-clipboard tools not found, clipboard functionality disabled");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -106,10 +106,10 @@ void EiClipboard::initialize()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Primary clipboard (selection)
|
// Primary clipboard (selection)
|
||||||
m_clipboards[kClipboardSelection] = std::make_unique<WaylandClipboard>(kClipboardSelection);
|
m_clipboards[kClipboardSelection] = std::make_unique<WlClipboard>(kClipboardSelection);
|
||||||
|
|
||||||
// Standard clipboard
|
// Standard clipboard
|
||||||
m_clipboards[kClipboardClipboard] = std::make_unique<WaylandClipboard>(kClipboardClipboard);
|
m_clipboards[kClipboardClipboard] = std::make_unique<WlClipboard>(kClipboardClipboard);
|
||||||
|
|
||||||
m_available = true;
|
m_available = true;
|
||||||
LOG_DEBUG1("initialized Wayland clipboard support");
|
LOG_DEBUG1("initialized Wayland clipboard support");
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
#include "deskflow/ClipboardTypes.h"
|
#include "deskflow/ClipboardTypes.h"
|
||||||
#include "deskflow/IClipboard.h"
|
#include "deskflow/IClipboard.h"
|
||||||
#include "platform/WaylandClipboard.h"
|
#include "platform/WlClipboard.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
@ -53,7 +53,7 @@ private:
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::unique_ptr<WaylandClipboard>> m_clipboards;
|
std::vector<std::unique_ptr<WlClipboard>> m_clipboards;
|
||||||
bool m_available = false;
|
bool m_available = false;
|
||||||
bool m_monitoring = false;
|
bool m_monitoring = false;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "platform/WaylandClipboard.h"
|
#include "platform/WlClipboard.h"
|
||||||
|
|
||||||
#include "base/Log.h"
|
#include "base/Log.h"
|
||||||
|
|
||||||
|
|
@ -154,7 +154,7 @@ public:
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
WaylandClipboard::WaylandClipboard(ClipboardID id) : m_id(id), m_useClipboard(id == kClipboardClipboard)
|
WlClipboard::WlClipboard(ClipboardID id) : m_id(id), m_useClipboard(id == kClipboardClipboard)
|
||||||
{
|
{
|
||||||
// Initialize cached data
|
// Initialize cached data
|
||||||
for (int i = 0; i < static_cast<int>(Format::TotalFormats); ++i) {
|
for (int i = 0; i < static_cast<int>(Format::TotalFormats); ++i) {
|
||||||
|
|
@ -162,22 +162,22 @@ WaylandClipboard::WaylandClipboard(ClipboardID id) : m_id(id), m_useClipboard(id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WaylandClipboard::~WaylandClipboard()
|
WlClipboard::~WlClipboard()
|
||||||
{
|
{
|
||||||
stopMonitoring();
|
stopMonitoring();
|
||||||
}
|
}
|
||||||
|
|
||||||
ClipboardID WaylandClipboard::getID() const
|
ClipboardID WlClipboard::getID() const
|
||||||
{
|
{
|
||||||
return m_id;
|
return m_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WaylandClipboard::isAvailable()
|
bool WlClipboard::isAvailable()
|
||||||
{
|
{
|
||||||
return checkCommandExists("wl-paste") && checkCommandExists("wl-copy");
|
return checkCommandExists("wl-paste") && checkCommandExists("wl-copy");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WaylandClipboard::checkCommandExists(const char *command)
|
bool WlClipboard::checkCommandExists(const char *command)
|
||||||
{
|
{
|
||||||
std::vector<const char *> args = {command, "--help", nullptr};
|
std::vector<const char *> args = {command, "--help", nullptr};
|
||||||
|
|
||||||
|
|
@ -211,17 +211,17 @@ bool WaylandClipboard::checkCommandExists(const char *command)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandClipboard::startMonitoring()
|
void WlClipboard::startMonitoring()
|
||||||
{
|
{
|
||||||
if (m_monitoring) {
|
if (m_monitoring) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_stopMonitoring = false;
|
m_stopMonitoring = false;
|
||||||
m_monitoring = true;
|
m_monitoring = true;
|
||||||
m_monitorThread = std::make_unique<std::thread>(&WaylandClipboard::monitorClipboard, this);
|
m_monitorThread = std::make_unique<std::thread>(&WlClipboard::monitorClipboard, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandClipboard::stopMonitoring()
|
void WlClipboard::stopMonitoring()
|
||||||
{
|
{
|
||||||
if (!m_monitoring) {
|
if (!m_monitoring) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -236,12 +236,12 @@ void WaylandClipboard::stopMonitoring()
|
||||||
m_monitorThread.reset();
|
m_monitorThread.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WaylandClipboard::hasChanged() const
|
bool WlClipboard::hasChanged() const
|
||||||
{
|
{
|
||||||
return m_hasChanged.load();
|
return m_hasChanged.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WaylandClipboard::empty()
|
bool WlClipboard::empty()
|
||||||
{
|
{
|
||||||
if (!m_open) {
|
if (!m_open) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -266,7 +266,7 @@ bool WaylandClipboard::empty()
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandClipboard::add(Format format, const std::string &data)
|
void WlClipboard::add(Format format, const std::string &data)
|
||||||
{
|
{
|
||||||
if (!m_open) {
|
if (!m_open) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -299,7 +299,7 @@ void WaylandClipboard::add(Format format, const std::string &data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WaylandClipboard::open(Time time) const
|
bool WlClipboard::open(Time time) const
|
||||||
{
|
{
|
||||||
if (m_open) {
|
if (m_open) {
|
||||||
LOG_DEBUG("failed to open clipboard: already opened");
|
LOG_DEBUG("failed to open clipboard: already opened");
|
||||||
|
|
@ -312,7 +312,7 @@ bool WaylandClipboard::open(Time time) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandClipboard::close() const
|
void WlClipboard::close() const
|
||||||
{
|
{
|
||||||
if (!m_open) {
|
if (!m_open) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -321,15 +321,15 @@ void WaylandClipboard::close() const
|
||||||
LOG_DEBUG("close clipboard");
|
LOG_DEBUG("close clipboard");
|
||||||
|
|
||||||
m_open = false;
|
m_open = false;
|
||||||
const_cast<WaylandClipboard *>(this)->invalidateCache();
|
const_cast<WlClipboard *>(this)->invalidateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
IClipboard::Time WaylandClipboard::getTime() const
|
IClipboard::Time WlClipboard::getTime() const
|
||||||
{
|
{
|
||||||
return m_time;
|
return m_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WaylandClipboard::has(Format format) const
|
bool WlClipboard::has(Format format) const
|
||||||
{
|
{
|
||||||
if (!m_open) {
|
if (!m_open) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -344,7 +344,7 @@ bool WaylandClipboard::has(Format format) const
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update cache by checking available MIME types
|
// Update cache by checking available MIME types
|
||||||
std::vector<std::string> availableTypes = const_cast<WaylandClipboard *>(this)->getAvailableMimeTypes();
|
std::vector<std::string> availableTypes = const_cast<WlClipboard *>(this)->getAvailableMimeTypes();
|
||||||
|
|
||||||
if (availableTypes.empty()) {
|
if (availableTypes.empty()) {
|
||||||
// No types available - mark all formats as unavailable
|
// No types available - mark all formats as unavailable
|
||||||
|
|
@ -377,7 +377,7 @@ bool WaylandClipboard::has(Format format) const
|
||||||
return m_cachedAvailable[static_cast<int>(format)];
|
return m_cachedAvailable[static_cast<int>(format)];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string WaylandClipboard::get(Format format) const
|
std::string WlClipboard::get(Format format) const
|
||||||
{
|
{
|
||||||
if (!m_open) {
|
if (!m_open) {
|
||||||
return std::string();
|
return std::string();
|
||||||
|
|
@ -402,7 +402,7 @@ std::string WaylandClipboard::get(Format format) const
|
||||||
args = {"wl-paste", "-t", mimeType.c_str(), "-p", nullptr};
|
args = {"wl-paste", "-t", mimeType.c_str(), "-p", nullptr};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string data = const_cast<WaylandClipboard *>(this)->executeCommand(args);
|
std::string data = const_cast<WlClipboard *>(this)->executeCommand(args);
|
||||||
|
|
||||||
// Update cache
|
// Update cache
|
||||||
m_cachedData[static_cast<int>(format)] = data;
|
m_cachedData[static_cast<int>(format)] = data;
|
||||||
|
|
@ -413,7 +413,7 @@ std::string WaylandClipboard::get(Format format) const
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string WaylandClipboard::executeCommand(const std::vector<const char *> &args) const
|
std::string WlClipboard::executeCommand(const std::vector<const char *> &args) const
|
||||||
{
|
{
|
||||||
int pipefd[2];
|
int pipefd[2];
|
||||||
if (pipe(pipefd) == -1) {
|
if (pipe(pipefd) == -1) {
|
||||||
|
|
@ -525,7 +525,7 @@ std::string WaylandClipboard::executeCommand(const std::vector<const char *> &ar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WaylandClipboard::executeCommandWithInput(const std::vector<const char *> &args, const std::string &input) const
|
bool WlClipboard::executeCommandWithInput(const std::vector<const char *> &args, const std::string &input) const
|
||||||
{
|
{
|
||||||
int pipefd[2];
|
int pipefd[2];
|
||||||
if (pipe(pipefd) == -1) {
|
if (pipe(pipefd) == -1) {
|
||||||
|
|
@ -640,7 +640,7 @@ bool WaylandClipboard::executeCommandWithInput(const std::vector<const char *> &
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string WaylandClipboard::formatToMimeType(Format format) const
|
std::string WlClipboard::formatToMimeType(Format format) const
|
||||||
{
|
{
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case Format::Text:
|
case Format::Text:
|
||||||
|
|
@ -654,7 +654,7 @@ std::string WaylandClipboard::formatToMimeType(Format format) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IClipboard::Format WaylandClipboard::mimeTypeToFormat(const std::string &mimeType) const
|
IClipboard::Format WlClipboard::mimeTypeToFormat(const std::string &mimeType) const
|
||||||
{
|
{
|
||||||
if (mimeType == kMimeTypeText || mimeType == "text/plain") {
|
if (mimeType == kMimeTypeText || mimeType == "text/plain") {
|
||||||
return Format::Text;
|
return Format::Text;
|
||||||
|
|
@ -669,7 +669,7 @@ IClipboard::Format WaylandClipboard::mimeTypeToFormat(const std::string &mimeTyp
|
||||||
return Format::Text; // Default fallback
|
return Format::Text; // Default fallback
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> WaylandClipboard::getAvailableMimeTypes() const
|
std::vector<std::string> WlClipboard::getAvailableMimeTypes() const
|
||||||
{
|
{
|
||||||
std::vector<const char *> args;
|
std::vector<const char *> args;
|
||||||
if (m_useClipboard) {
|
if (m_useClipboard) {
|
||||||
|
|
@ -694,7 +694,7 @@ std::vector<std::string> WaylandClipboard::getAvailableMimeTypes() const
|
||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string WaylandClipboard::getClipboardData(const std::string &mimeType) const
|
std::string WlClipboard::getClipboardData(const std::string &mimeType) const
|
||||||
{
|
{
|
||||||
std::vector<const char *> args;
|
std::vector<const char *> args;
|
||||||
if (m_useClipboard) {
|
if (m_useClipboard) {
|
||||||
|
|
@ -705,7 +705,7 @@ std::string WaylandClipboard::getClipboardData(const std::string &mimeType) cons
|
||||||
return executeCommand(args);
|
return executeCommand(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WaylandClipboard::setClipboardData(const std::string &mimeType, const std::string &data) const
|
bool WlClipboard::setClipboardData(const std::string &mimeType, const std::string &data) const
|
||||||
{
|
{
|
||||||
std::vector<const char *> args;
|
std::vector<const char *> args;
|
||||||
if (m_useClipboard) {
|
if (m_useClipboard) {
|
||||||
|
|
@ -716,7 +716,7 @@ bool WaylandClipboard::setClipboardData(const std::string &mimeType, const std::
|
||||||
return executeCommandWithInput(args, data);
|
return executeCommandWithInput(args, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandClipboard::monitorClipboard()
|
void WlClipboard::monitorClipboard()
|
||||||
{
|
{
|
||||||
std::vector<std::string> lastTypes;
|
std::vector<std::string> lastTypes;
|
||||||
int consecutiveErrors = 0;
|
int consecutiveErrors = 0;
|
||||||
|
|
@ -737,7 +737,7 @@ void WaylandClipboard::monitorClipboard()
|
||||||
// Clear cache when clipboard changes
|
// Clear cache when clipboard changes
|
||||||
std::lock_guard<std::mutex> lock(m_cacheMutex);
|
std::lock_guard<std::mutex> lock(m_cacheMutex);
|
||||||
invalidateCache();
|
invalidateCache();
|
||||||
const_cast<WaylandClipboard *>(this)->updateOwnership(false);
|
const_cast<WlClipboard *>(this)->updateOwnership(false);
|
||||||
}
|
}
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
LOG_WARN("clipboard monitoring error: %s", e.what());
|
LOG_WARN("clipboard monitoring error: %s", e.what());
|
||||||
|
|
@ -755,19 +755,19 @@ void WaylandClipboard::monitorClipboard()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IClipboard::Time WaylandClipboard::getCurrentTime() const
|
IClipboard::Time WlClipboard::getCurrentTime() const
|
||||||
{
|
{
|
||||||
auto now = std::chrono::steady_clock::now();
|
auto now = std::chrono::steady_clock::now();
|
||||||
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch());
|
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch());
|
||||||
return static_cast<Time>(ms.count());
|
return static_cast<Time>(ms.count());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WaylandClipboard::isOwned() const
|
bool WlClipboard::isOwned() const
|
||||||
{
|
{
|
||||||
return m_owned;
|
return m_owned;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandClipboard::resetChanged()
|
void WlClipboard::resetChanged()
|
||||||
{
|
{
|
||||||
m_hasChanged = false;
|
m_hasChanged = false;
|
||||||
|
|
||||||
|
|
@ -776,12 +776,12 @@ void WaylandClipboard::resetChanged()
|
||||||
invalidateCache();
|
invalidateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandClipboard::updateOwnership(bool owned)
|
void WlClipboard::updateOwnership(bool owned)
|
||||||
{
|
{
|
||||||
m_owned = owned;
|
m_owned = owned;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandClipboard::invalidateCache()
|
void WlClipboard::invalidateCache()
|
||||||
{
|
{
|
||||||
m_cached = false;
|
m_cached = false;
|
||||||
m_cachedTime = 0;
|
m_cachedTime = 0;
|
||||||
|
|
@ -22,16 +22,16 @@
|
||||||
This class implements clipboard functionality for Wayland environments
|
This class implements clipboard functionality for Wayland environments
|
||||||
by using the wl-clipboard utilities (wl-copy and wl-paste).
|
by using the wl-clipboard utilities (wl-copy and wl-paste).
|
||||||
*/
|
*/
|
||||||
class WaylandClipboard : public IClipboard
|
class WlClipboard : public IClipboard
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WaylandClipboard(ClipboardID id);
|
WlClipboard(ClipboardID id);
|
||||||
WaylandClipboard(WaylandClipboard const &) = delete;
|
WlClipboard(WlClipboard const &) = delete;
|
||||||
WaylandClipboard(WaylandClipboard &&) = delete;
|
WlClipboard(WlClipboard &&) = delete;
|
||||||
~WaylandClipboard() override;
|
~WlClipboard() override;
|
||||||
|
|
||||||
WaylandClipboard &operator=(WaylandClipboard const &) = delete;
|
WlClipboard &operator=(WlClipboard const &) = delete;
|
||||||
WaylandClipboard &operator=(WaylandClipboard &&) = delete;
|
WlClipboard &operator=(WlClipboard &&) = delete;
|
||||||
|
|
||||||
//! Get clipboard ID
|
//! Get clipboard ID
|
||||||
ClipboardID getID() const;
|
ClipboardID getID() const;
|
||||||
|
|
@ -38,10 +38,10 @@ elseif(UNIX)
|
||||||
# Add Wayland clipboard tests when Wayland support is available
|
# Add Wayland clipboard tests when Wayland support is available
|
||||||
if(LIBEI_FOUND AND LIBPORTAL_FOUND)
|
if(LIBEI_FOUND AND LIBPORTAL_FOUND)
|
||||||
create_test(
|
create_test(
|
||||||
NAME WaylandClipboardTests
|
NAME WlClipboardTests
|
||||||
DEPENDS platform
|
DEPENDS platform
|
||||||
LIBS base arch
|
LIBS base arch
|
||||||
SOURCE WaylandClipboardTests.cpp
|
SOURCE WlClipboardTests.cpp
|
||||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/platform"
|
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/platform"
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@
|
||||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "WaylandClipboardTests.h"
|
#include "WlClipboardTests.h"
|
||||||
|
|
||||||
#include "base/LogLevel.h"
|
#include "base/LogLevel.h"
|
||||||
#include "deskflow/ClipboardTypes.h"
|
#include "deskflow/ClipboardTypes.h"
|
||||||
#include "platform/WaylandClipboard.h"
|
#include "platform/WlClipboard.h"
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
@ -16,38 +16,38 @@
|
||||||
|
|
||||||
#include <QTest>
|
#include <QTest>
|
||||||
|
|
||||||
void WaylandClipboardTests::defaultCtor()
|
void WlClipboardTests::defaultCtor()
|
||||||
{
|
{
|
||||||
WaylandClipboard clipboard(kClipboardClipboard);
|
WlClipboard clipboard(kClipboardClipboard);
|
||||||
QCOMPARE(kClipboardClipboard, clipboard.getID());
|
QCOMPARE(kClipboardClipboard, clipboard.getID());
|
||||||
|
|
||||||
WaylandClipboard primaryClipboard(kClipboardSelection);
|
WlClipboard primaryClipboard(kClipboardSelection);
|
||||||
QCOMPARE(kClipboardSelection, primaryClipboard.getID());
|
QCOMPARE(kClipboardSelection, primaryClipboard.getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandClipboardTests::isAvailable()
|
void WlClipboardTests::isAvailable()
|
||||||
{
|
{
|
||||||
// This test may fail on systems without wl-clipboard installed
|
// This test may fail on systems without wl-clipboard installed
|
||||||
// In CI environments, we might need to skip this test or mock the commands
|
// In CI environments, we might need to skip this test or mock the commands
|
||||||
bool available = WaylandClipboard::isAvailable();
|
bool available = WlClipboard::isAvailable();
|
||||||
|
|
||||||
// We don't assert true/false here because it depends on system setup
|
// We don't assert true/false here because it depends on system setup
|
||||||
// Just verify the method doesn't crash and returns a boolean
|
// Just verify the method doesn't crash and returns a boolean
|
||||||
QVERIFY(available == true || available == false);
|
QVERIFY(available == true || available == false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandClipboardTests::initTestCase()
|
void WlClipboardTests::initTestCase()
|
||||||
{
|
{
|
||||||
m_arch.init();
|
m_arch.init();
|
||||||
m_log.setFilter(LogLevel::Debug2);
|
m_log.setFilter(LogLevel::Debug2);
|
||||||
|
|
||||||
// Only run tests if Wayland clipboard tools are available
|
// Only run tests if Wayland clipboard tools are available
|
||||||
if (!WaylandClipboard::isAvailable()) {
|
if (!WlClipboard::isAvailable()) {
|
||||||
QSKIP("wl-clipboard tools not available, skipping Wayland clipboard tests");
|
QSKIP("wl-clipboard tools not available, skipping Wayland clipboard tests");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test if Wayland commands actually work (not just exist)
|
// Test if Wayland commands actually work (not just exist)
|
||||||
WaylandClipboard testClipboard(kClipboardClipboard);
|
WlClipboard testClipboard(kClipboardClipboard);
|
||||||
if (!testClipboard.open(0)) {
|
if (!testClipboard.open(0)) {
|
||||||
QSKIP("Failed to open Wayland clipboard, likely no Wayland session");
|
QSKIP("Failed to open Wayland clipboard, likely no Wayland session");
|
||||||
}
|
}
|
||||||
|
|
@ -61,11 +61,11 @@ void WaylandClipboardTests::initTestCase()
|
||||||
testClipboard.close();
|
testClipboard.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandClipboardTests::cleanupTestCase()
|
void WlClipboardTests::cleanupTestCase()
|
||||||
{
|
{
|
||||||
// Clean up by emptying clipboards
|
// Clean up by emptying clipboards
|
||||||
try {
|
try {
|
||||||
WaylandClipboard clipboard(kClipboardClipboard);
|
WlClipboard clipboard(kClipboardClipboard);
|
||||||
if (clipboard.open(0)) {
|
if (clipboard.open(0)) {
|
||||||
clipboard.empty();
|
clipboard.empty();
|
||||||
clipboard.close();
|
clipboard.close();
|
||||||
|
|
@ -75,9 +75,9 @@ void WaylandClipboardTests::cleanupTestCase()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandClipboardTests::open()
|
void WlClipboardTests::open()
|
||||||
{
|
{
|
||||||
WaylandClipboard clipboard(kClipboardClipboard);
|
WlClipboard clipboard(kClipboardClipboard);
|
||||||
QVERIFY(clipboard.open(0));
|
QVERIFY(clipboard.open(0));
|
||||||
|
|
||||||
// Opening again should return false
|
// Opening again should return false
|
||||||
|
|
@ -90,9 +90,9 @@ void WaylandClipboardTests::open()
|
||||||
clipboard.close();
|
clipboard.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandClipboardTests::empty()
|
void WlClipboardTests::empty()
|
||||||
{
|
{
|
||||||
WaylandClipboard clipboard(kClipboardClipboard);
|
WlClipboard clipboard(kClipboardClipboard);
|
||||||
QVERIFY(clipboard.open(0));
|
QVERIFY(clipboard.open(0));
|
||||||
|
|
||||||
// First add some known content
|
// First add some known content
|
||||||
|
|
@ -109,9 +109,9 @@ void WaylandClipboardTests::empty()
|
||||||
clipboard.close();
|
clipboard.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandClipboardTests::singleFormat()
|
void WlClipboardTests::singleFormat()
|
||||||
{
|
{
|
||||||
WaylandClipboard clipboard(kClipboardClipboard);
|
WlClipboard clipboard(kClipboardClipboard);
|
||||||
QVERIFY(clipboard.open(0));
|
QVERIFY(clipboard.open(0));
|
||||||
|
|
||||||
// Clear clipboard first - if this fails, skip test
|
// Clear clipboard first - if this fails, skip test
|
||||||
|
|
@ -141,9 +141,9 @@ void WaylandClipboardTests::singleFormat()
|
||||||
clipboard.close();
|
clipboard.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandClipboardTests::multipleFormats()
|
void WlClipboardTests::multipleFormats()
|
||||||
{
|
{
|
||||||
WaylandClipboard clipboard(kClipboardClipboard);
|
WlClipboard clipboard(kClipboardClipboard);
|
||||||
QVERIFY(clipboard.open(0));
|
QVERIFY(clipboard.open(0));
|
||||||
|
|
||||||
// Clear clipboard first
|
// Clear clipboard first
|
||||||
|
|
@ -156,7 +156,7 @@ void WaylandClipboardTests::multipleFormats()
|
||||||
// So we test formats separately rather than simultaneously
|
// So we test formats separately rather than simultaneously
|
||||||
QVERIFY(waitForClipboardContent(clipboard, IClipboard::Format::Text, m_testString));
|
QVERIFY(waitForClipboardContent(clipboard, IClipboard::Format::Text, m_testString));
|
||||||
|
|
||||||
// HTML format is currently not supported in WaylandClipboard implementation
|
// HTML format is currently not supported in WlClipboard implementation
|
||||||
// So we skip HTML testing and just verify text format works
|
// So we skip HTML testing and just verify text format works
|
||||||
|
|
||||||
// Clear and add different text data to test format replacement
|
// Clear and add different text data to test format replacement
|
||||||
|
|
@ -169,9 +169,9 @@ void WaylandClipboardTests::multipleFormats()
|
||||||
clipboard.close();
|
clipboard.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandClipboardTests::hasFormat()
|
void WlClipboardTests::hasFormat()
|
||||||
{
|
{
|
||||||
WaylandClipboard clipboard(kClipboardClipboard);
|
WlClipboard clipboard(kClipboardClipboard);
|
||||||
QVERIFY(clipboard.open(0));
|
QVERIFY(clipboard.open(0));
|
||||||
|
|
||||||
// Clear clipboard first
|
// Clear clipboard first
|
||||||
|
|
@ -195,9 +195,9 @@ void WaylandClipboardTests::hasFormat()
|
||||||
clipboard.close();
|
clipboard.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandClipboardTests::getTime()
|
void WlClipboardTests::getTime()
|
||||||
{
|
{
|
||||||
WaylandClipboard clipboard(kClipboardClipboard);
|
WlClipboard clipboard(kClipboardClipboard);
|
||||||
QVERIFY(clipboard.open(100));
|
QVERIFY(clipboard.open(100));
|
||||||
|
|
||||||
// Should return the time passed to open()
|
// Should return the time passed to open()
|
||||||
|
|
@ -209,9 +209,9 @@ void WaylandClipboardTests::getTime()
|
||||||
clipboard.close();
|
clipboard.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandClipboardTests::monitoring()
|
void WlClipboardTests::monitoring()
|
||||||
{
|
{
|
||||||
WaylandClipboard clipboard(kClipboardClipboard);
|
WlClipboard clipboard(kClipboardClipboard);
|
||||||
QVERIFY(clipboard.open(0));
|
QVERIFY(clipboard.open(0));
|
||||||
|
|
||||||
// Clear clipboard first
|
// Clear clipboard first
|
||||||
|
|
@ -225,7 +225,7 @@ void WaylandClipboardTests::monitoring()
|
||||||
|
|
||||||
// Make a change to the clipboard using a separate clipboard instance
|
// Make a change to the clipboard using a separate clipboard instance
|
||||||
// to simulate external changes
|
// to simulate external changes
|
||||||
WaylandClipboard externalClipboard(kClipboardClipboard);
|
WlClipboard externalClipboard(kClipboardClipboard);
|
||||||
if (externalClipboard.open(1)) {
|
if (externalClipboard.open(1)) {
|
||||||
externalClipboard.empty();
|
externalClipboard.empty();
|
||||||
externalClipboard.add(IClipboard::Format::Text, m_testString);
|
externalClipboard.add(IClipboard::Format::Text, m_testString);
|
||||||
|
|
@ -244,27 +244,27 @@ void WaylandClipboardTests::monitoring()
|
||||||
// This test mainly verifies that monitoring doesn't crash
|
// This test mainly verifies that monitoring doesn't crash
|
||||||
}
|
}
|
||||||
|
|
||||||
WaylandClipboard &WaylandClipboardTests::getClipboard()
|
WlClipboard &WlClipboardTests::getClipboard()
|
||||||
{
|
{
|
||||||
if (!m_clipboard) {
|
if (!m_clipboard) {
|
||||||
m_clipboard = std::make_unique<WaylandClipboard>(kClipboardClipboard);
|
m_clipboard = std::make_unique<WlClipboard>(kClipboardClipboard);
|
||||||
}
|
}
|
||||||
return *m_clipboard;
|
return *m_clipboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
WaylandClipboard &WaylandClipboardTests::getPrimaryClipboard()
|
WlClipboard &WlClipboardTests::getPrimaryClipboard()
|
||||||
{
|
{
|
||||||
if (!m_primaryClipboard) {
|
if (!m_primaryClipboard) {
|
||||||
m_primaryClipboard = std::make_unique<WaylandClipboard>(kClipboardSelection);
|
m_primaryClipboard = std::make_unique<WlClipboard>(kClipboardSelection);
|
||||||
}
|
}
|
||||||
return *m_primaryClipboard;
|
return *m_primaryClipboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandClipboardTests::primaryClipboard()
|
void WlClipboardTests::primaryClipboard()
|
||||||
{
|
{
|
||||||
// Test that primary clipboard works independently from regular clipboard
|
// Test that primary clipboard works independently from regular clipboard
|
||||||
WaylandClipboard clipboard(kClipboardClipboard);
|
WlClipboard clipboard(kClipboardClipboard);
|
||||||
WaylandClipboard primaryClipboard(kClipboardSelection);
|
WlClipboard primaryClipboard(kClipboardSelection);
|
||||||
|
|
||||||
QVERIFY(clipboard.open(0));
|
QVERIFY(clipboard.open(0));
|
||||||
QVERIFY(primaryClipboard.open(1));
|
QVERIFY(primaryClipboard.open(1));
|
||||||
|
|
@ -285,9 +285,9 @@ void WaylandClipboardTests::primaryClipboard()
|
||||||
primaryClipboard.close();
|
primaryClipboard.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandClipboardTests::closeWithoutOpen()
|
void WlClipboardTests::closeWithoutOpen()
|
||||||
{
|
{
|
||||||
WaylandClipboard clipboard(kClipboardClipboard);
|
WlClipboard clipboard(kClipboardClipboard);
|
||||||
|
|
||||||
// Should be safe to call close without open
|
// Should be safe to call close without open
|
||||||
clipboard.close();
|
clipboard.close();
|
||||||
|
|
@ -297,9 +297,9 @@ void WaylandClipboardTests::closeWithoutOpen()
|
||||||
clipboard.close();
|
clipboard.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandClipboardTests::addWithoutOpen()
|
void WlClipboardTests::addWithoutOpen()
|
||||||
{
|
{
|
||||||
WaylandClipboard clipboard(kClipboardClipboard);
|
WlClipboard clipboard(kClipboardClipboard);
|
||||||
|
|
||||||
// Should not crash when adding without open
|
// Should not crash when adding without open
|
||||||
clipboard.add(IClipboard::Format::Text, m_testString);
|
clipboard.add(IClipboard::Format::Text, m_testString);
|
||||||
|
|
@ -309,9 +309,9 @@ void WaylandClipboardTests::addWithoutOpen()
|
||||||
clipboard.close();
|
clipboard.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandClipboardTests::getWithoutOpen()
|
void WlClipboardTests::getWithoutOpen()
|
||||||
{
|
{
|
||||||
WaylandClipboard clipboard(kClipboardClipboard);
|
WlClipboard clipboard(kClipboardClipboard);
|
||||||
|
|
||||||
// Should return empty string when getting without open
|
// Should return empty string when getting without open
|
||||||
std::string result = clipboard.get(IClipboard::Format::Text);
|
std::string result = clipboard.get(IClipboard::Format::Text);
|
||||||
|
|
@ -325,9 +325,7 @@ void WaylandClipboardTests::getWithoutOpen()
|
||||||
clipboard.close();
|
clipboard.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WaylandClipboardTests::waitForClipboardCondition(
|
bool WlClipboardTests::waitForClipboardCondition(WlClipboard &clipboard, std::function<bool()> condition, int timeoutMs)
|
||||||
WaylandClipboard &clipboard, std::function<bool()> condition, int timeoutMs
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
auto startTime = std::chrono::steady_clock::now();
|
auto startTime = std::chrono::steady_clock::now();
|
||||||
auto timeout = std::chrono::milliseconds(timeoutMs);
|
auto timeout = std::chrono::milliseconds(timeoutMs);
|
||||||
|
|
@ -342,9 +340,7 @@ bool WaylandClipboardTests::waitForClipboardCondition(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WaylandClipboardTests::waitForClipboardEmpty(
|
bool WlClipboardTests::waitForClipboardEmpty(WlClipboard &clipboard, const std::string &previousContent, int timeoutMs)
|
||||||
WaylandClipboard &clipboard, const std::string &previousContent, int timeoutMs
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
auto condition = [&clipboard, &previousContent]() {
|
auto condition = [&clipboard, &previousContent]() {
|
||||||
// Check if clipboard is empty or no longer contains our previous content
|
// Check if clipboard is empty or no longer contains our previous content
|
||||||
|
|
@ -359,8 +355,8 @@ bool WaylandClipboardTests::waitForClipboardEmpty(
|
||||||
return waitForClipboardCondition(clipboard, condition, timeoutMs);
|
return waitForClipboardCondition(clipboard, condition, timeoutMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WaylandClipboardTests::waitForClipboardContent(
|
bool WlClipboardTests::waitForClipboardContent(
|
||||||
WaylandClipboard &clipboard, IClipboard::Format format, const std::string &expectedContent, int timeoutMs
|
WlClipboard &clipboard, IClipboard::Format format, const std::string &expectedContent, int timeoutMs
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
auto condition = [&clipboard, format, &expectedContent]() {
|
auto condition = [&clipboard, format, &expectedContent]() {
|
||||||
|
|
@ -373,4 +369,4 @@ bool WaylandClipboardTests::waitForClipboardContent(
|
||||||
return waitForClipboardCondition(clipboard, condition, timeoutMs);
|
return waitForClipboardCondition(clipboard, condition, timeoutMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_MAIN(WaylandClipboardTests)
|
QTEST_MAIN(WlClipboardTests)
|
||||||
|
|
@ -11,13 +11,13 @@
|
||||||
#include "deskflow/ClipboardTypes.h"
|
#include "deskflow/ClipboardTypes.h"
|
||||||
|
|
||||||
#if WINAPI_LIBEI || WINAPI_PORTAL
|
#if WINAPI_LIBEI || WINAPI_PORTAL
|
||||||
#include "platform/WaylandClipboard.h"
|
#include "platform/WlClipboard.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <QTest>
|
#include <QTest>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
//! Unit tests for WaylandClipboard class
|
//! Unit tests for WlClipboard class
|
||||||
/*!
|
/*!
|
||||||
Tests the Wayland clipboard implementation that uses wl-copy and wl-paste
|
Tests the Wayland clipboard implementation that uses wl-copy and wl-paste
|
||||||
utilities for clipboard operations. These tests verify basic functionality
|
utilities for clipboard operations. These tests verify basic functionality
|
||||||
|
|
@ -27,7 +27,7 @@ and monitoring clipboard changes.
|
||||||
Note: These tests require wl-clipboard tools to be installed and will be
|
Note: These tests require wl-clipboard tools to be installed and will be
|
||||||
skipped if they are not available or if Wayland support is not compiled in.
|
skipped if they are not available or if Wayland support is not compiled in.
|
||||||
*/
|
*/
|
||||||
class WaylandClipboardTests : public QObject
|
class WlClipboardTests : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
|
|
@ -61,17 +61,17 @@ private:
|
||||||
const std::string m_testString2 = "Another test string";
|
const std::string m_testString2 = "Another test string";
|
||||||
const std::string m_testHtml = "<html><body>Test HTML</body></html>";
|
const std::string m_testHtml = "<html><body>Test HTML</body></html>";
|
||||||
|
|
||||||
std::unique_ptr<WaylandClipboard> m_clipboard;
|
std::unique_ptr<WlClipboard> m_clipboard;
|
||||||
std::unique_ptr<WaylandClipboard> m_primaryClipboard;
|
std::unique_ptr<WlClipboard> m_primaryClipboard;
|
||||||
|
|
||||||
WaylandClipboard &getClipboard();
|
WlClipboard &getClipboard();
|
||||||
WaylandClipboard &getPrimaryClipboard();
|
WlClipboard &getPrimaryClipboard();
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
// Helper methods for robust testing
|
// Helper methods for robust testing
|
||||||
bool waitForClipboardCondition(WaylandClipboard &clipboard, std::function<bool()> condition, int timeoutMs = 2000);
|
bool waitForClipboardCondition(WlClipboard &clipboard, std::function<bool()> condition, int timeoutMs = 2000);
|
||||||
bool waitForClipboardEmpty(WaylandClipboard &clipboard, const std::string &previousContent, int timeoutMs = 2000);
|
bool waitForClipboardEmpty(WlClipboard &clipboard, const std::string &previousContent, int timeoutMs = 2000);
|
||||||
bool waitForClipboardContent(
|
bool waitForClipboardContent(WlClipboard &clipboard, IClipboard::Format format, const std::string &expectedContent, int timeoutMs = 2000);
|
||||||
WaylandClipboard &clipboard, IClipboard::Format format, const std::string &expectedContent, int timeoutMs = 2000
|
// clang-format on
|
||||||
);
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
Loading…
Reference in a new issue