Skip to content

Commit

Permalink
lua: Interact with clipboard on main gui thread
Browse files Browse the repository at this point in the history
Fixes #22 .
  • Loading branch information
arch1t3cht committed Feb 25, 2023
1 parent 7f52346 commit 15d215f
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/auto4_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ namespace {

const char *clipboard_get()
{
std::string data = GetClipboard();
std::string data;
agi::dispatch::Main().Sync([&] { data = GetClipboard(); });
if (data.empty())
return nullptr;
return strndup(data);
Expand All @@ -135,18 +136,14 @@ namespace {
{
bool succeeded = false;

#if wxUSE_OLE
// OLE needs to be initialized on each thread that wants to write to
// the clipboard, which wx does not handle automatically
wxClipboard cb;
#else
wxClipboard &cb = *wxTheClipboard;
#endif
if (cb.Open()) {
succeeded = cb.SetData(new wxTextDataObject(wxString::FromUTF8(str)));
cb.Close();
cb.Flush();
}
agi::dispatch::Main().Sync([&] {
wxClipboard &cb = *wxTheClipboard;
if (cb.Open()) {
succeeded = cb.SetData(new wxTextDataObject(wxString::FromUTF8(str)));
cb.Close();
cb.Flush();
}
});

return succeeded;
}
Expand Down

0 comments on commit 15d215f

Please # to comment.