1
0
Fork 0

lua: Interact with clipboard on main gui thread

Fixes arch1t3cht/Aegisub#22 .
This commit is contained in:
arch1t3cht 2023-02-25 12:31:27 +01:00
parent 7f52346f06
commit 15d215f36d
1 changed files with 10 additions and 13 deletions

View File

@ -125,7 +125,8 @@ namespace {
const char *clipboard_get() const char *clipboard_get()
{ {
std::string data = GetClipboard(); std::string data;
agi::dispatch::Main().Sync([&] { data = GetClipboard(); });
if (data.empty()) if (data.empty())
return nullptr; return nullptr;
return strndup(data); return strndup(data);
@ -135,18 +136,14 @@ namespace {
{ {
bool succeeded = false; bool succeeded = false;
#if wxUSE_OLE agi::dispatch::Main().Sync([&] {
// OLE needs to be initialized on each thread that wants to write to wxClipboard &cb = *wxTheClipboard;
// the clipboard, which wx does not handle automatically if (cb.Open()) {
wxClipboard cb; succeeded = cb.SetData(new wxTextDataObject(wxString::FromUTF8(str)));
#else cb.Close();
wxClipboard &cb = *wxTheClipboard; cb.Flush();
#endif }
if (cb.Open()) { });
succeeded = cb.SetData(new wxTextDataObject(wxString::FromUTF8(str)));
cb.Close();
cb.Flush();
}
return succeeded; return succeeded;
} }