2012-06-10 16:50:54 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
|
|
|
|
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2012-06-10 16:50:54 +00:00
|
|
|
*/
|
|
|
|
|
|
2014-02-28 12:36:45 +00:00
|
|
|
#include "platform/XWindowsClipboardUTF8Converter.h"
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2022-04-28 14:59:58 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
//
|
2014-11-12 11:28:41 +00:00
|
|
|
// XWindowsClipboardUTF8Converter
|
2012-06-10 16:50:54 +00:00
|
|
|
//
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
XWindowsClipboardUTF8Converter::XWindowsClipboardUTF8Converter(Display *display, const char *name, bool normalize)
|
2024-07-16 13:36:44 +00:00
|
|
|
: m_atom(XInternAtom(display, name, False)),
|
2024-10-17 18:04:35 +00:00
|
|
|
m_normalize(normalize)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
// do nothing
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-07-30 12:19:15 +00:00
|
|
|
IClipboard::Format XWindowsClipboardUTF8Converter::getFormat() const
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2025-07-30 12:19:15 +00:00
|
|
|
return IClipboard::Format::Text;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
Atom XWindowsClipboardUTF8Converter::getAtom() const
|
|
|
|
|
{
|
|
|
|
|
return m_atom;
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
int XWindowsClipboardUTF8Converter::getDataSize() const
|
|
|
|
|
{
|
|
|
|
|
return 8;
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
static bool isCR(char ch)
|
|
|
|
|
{
|
|
|
|
|
return (ch == '\r');
|
|
|
|
|
}
|
2022-04-28 14:59:58 +00:00
|
|
|
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string XWindowsClipboardUTF8Converter::fromIClipboard(const std::string &data) const
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
return data;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string XWindowsClipboardUTF8Converter::toIClipboard(const std::string &data) const
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1547595
|
|
|
|
|
// GTK normalizes the clipboard's line endings to CRLF (\r\n) internally.
|
|
|
|
|
// When sending the raw data to other systems, like Windows, where \n is
|
|
|
|
|
// converted to \r\n we end up with \r\r\n, resulting in double lines when
|
|
|
|
|
// pasting.
|
|
|
|
|
//
|
|
|
|
|
// This seems to happen only when the clipboard format is
|
|
|
|
|
// text/plain;charset=utf8 and not when it's UTF8_STRING.
|
|
|
|
|
// When normalize clipboard is set, any \r present in the string is removed
|
2022-04-28 14:59:58 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
if (m_normalize) {
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string copy = data;
|
2022-04-28 14:59:58 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
copy.erase(std::remove_if(copy.begin(), copy.end(), isCR), copy.end());
|
|
|
|
|
return copy;
|
|
|
|
|
}
|
2022-04-28 14:59:58 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
return data;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|