Skip to content

Commit

Permalink
Merge pull request #2070 from unxed/wayland_clipboard_workaround
Browse files Browse the repository at this point in the history
support data format default on wayland systems for text in utf-8
  • Loading branch information
elfmz authored Mar 16, 2024
2 parents 3a39598 + d2551e7 commit 1e7b2a7
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions WinPort/src/Backend/WX/wxClipboardBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,27 @@ void *wxClipboardBackend::OnClipboardSetData(UINT format, void *data)
if (!g_wx_data_to_clipboard) {
g_wx_data_to_clipboard = new wxDataObjectComposite;
}

if (format==CF_UNICODETEXT) {

wxCustomDataObject *dos = new wxCustomDataObject(wxT("text/plain;charset=utf-8"));
std::string tmp = wxString((const wchar_t *)data).ToStdString();
dos->SetData(tmp.length(), tmp.data());
g_wx_data_to_clipboard->Add(dos);

g_wx_data_to_clipboard->Add(new wxTextDataObjectTweaked(wxString((const wchar_t *)data)));

#if (CLIPBOARD_HACK)
CopyToPasteboard((const wchar_t *)data);
#endif

} else if (format==CF_TEXT) {

wxCustomDataObject *dos = new wxCustomDataObject(wxT("text/plain;charset=utf-8"));
std::string tmp = wxString::FromUTF8((const char *)data).ToStdString();
dos->SetData(tmp.length(), tmp.data());
g_wx_data_to_clipboard->Add(dos);

g_wx_data_to_clipboard->Add(new wxTextDataObjectTweaked(wxString::FromUTF8((const char *)data)));
#if (CLIPBOARD_HACK)
CopyToPasteboard((const char *)data);
Expand Down Expand Up @@ -239,11 +252,32 @@ void *wxClipboardBackend::OnClipboardGetData(UINT format)

PVOID p = nullptr;
if (format==CF_UNICODETEXT || format==CF_TEXT) {

wxString wx_str;
bool dataFound = false;

wxTextDataObject data;
if (!wxTheClipboard->GetData( data ))
return nullptr;
if (wxTheClipboard->GetData( data )) {
fprintf(stderr, "OnClipboardGetData(%u) - found wx-compatible text format\n", format);
wx_str = data.GetText();
dataFound = true;
}

const wxString &wx_str = data.GetText();
wxCustomDataObject customDataTextUtf8(wxT("text/plain;charset=utf-8"));
if (!dataFound && wxTheClipboard->GetData(customDataTextUtf8)) {
const void* data = customDataTextUtf8.GetData();
size_t dataSize = customDataTextUtf8.GetSize();
if (dataSize > 0) {
fprintf(stderr, "OnClipboardGetData(%u) - found MIME-compatible text format\n", format);
wx_str = wxString(static_cast<const char*>(data), dataSize);
dataFound = true;
}
}

if (!dataFound) {
fprintf(stderr, "OnClipboardGetData(%u) - no supported text format found\n", format);
return nullptr;
}

if (format == CF_UNICODETEXT) {
const auto &wc = wx_str.wc_str();
Expand Down

0 comments on commit 1e7b2a7

Please sign in to comment.