Skip to content

Commit

Permalink
Merge pull request #14179 from unknownbrackets/windows-osk
Browse files Browse the repository at this point in the history
Windows: Run OSK/chat input box asynchronously
  • Loading branch information
hrydgard committed Feb 18, 2021
2 parents 9f68a34 + e97a0ec commit 1197795
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions Windows/main.cpp
Expand Up @@ -104,6 +104,9 @@ static std::string restartArgs;
HMENU g_hPopupMenus;
int g_activeWindow = 0;

static std::thread inputBoxThread;
static bool inputBoxRunning = false;

void OpenDirectory(const char *path) {
PIDLIST_ABSOLUTE pidl = ILCreateFromPath(ConvertUTF8ToWString(ReplaceAll(path, "/", "\\")).c_str());
if (pidl) {
Expand Down Expand Up @@ -386,12 +389,19 @@ void EnableCrashingOnCrashes() {
}

void System_InputBoxGetString(const std::string &title, const std::string &defaultValue, std::function<void(bool, const std::string &)> cb) {
std::string out;
if (InputBox_GetString(MainWindow::GetHInstance(), MainWindow::GetHWND(), ConvertUTF8ToWString(title).c_str(), defaultValue, out)) {
NativeInputBoxReceived(cb, true, out);
} else {
NativeInputBoxReceived(cb, false, "");
if (inputBoxRunning) {
inputBoxThread.join();
}

inputBoxRunning = true;
inputBoxThread = std::thread([=] {
std::string out;
if (InputBox_GetString(MainWindow::GetHInstance(), MainWindow::GetHWND(), ConvertUTF8ToWString(title).c_str(), defaultValue, out)) {
NativeInputBoxReceived(cb, true, out);
} else {
NativeInputBoxReceived(cb, false, "");
}
});
}

static std::string GetDefaultLangRegion() {
Expand Down Expand Up @@ -492,6 +502,10 @@ static void WinMainInit() {
}

static void WinMainCleanup() {
if (inputBoxRunning) {
inputBoxThread.join();
inputBoxRunning = false;
}
net::Shutdown();
CoUninitialize();

Expand Down

0 comments on commit 1197795

Please sign in to comment.