Dispatch popup dialogues to main thread

This commit is contained in:
Vinyl Darkscratch 2018-10-03 05:51:37 -07:00
parent 1513d7b285
commit f9f13bf022
1 changed files with 18 additions and 4 deletions

View File

@ -31,6 +31,7 @@
#ifdef __APPLE__ #ifdef __APPLE__
#define OS_OSX #define OS_OSX
#include <dispatch/dispatch.h>
#else #else
#define OS_LINUX #define OS_LINUX
#include <gtk/gtk.h> #include <gtk/gtk.h>
@ -503,7 +504,7 @@ bool Oneshot::msgbox(int type, const char *body, const char *title)
// Messagebox data // Messagebox data
SDL_MessageBoxData data; SDL_MessageBoxData data;
data.window = NULL;//p->window; data.window = NULL; //p->window;
data.colorScheme = 0; data.colorScheme = 0;
data.title = title; data.title = title;
data.message = body; data.message = body;
@ -556,9 +557,22 @@ bool Oneshot::msgbox(int type, const char *body, const char *title)
#ifdef OS_W32 #ifdef OS_W32
PlaySoundW((LPCWSTR)sound, NULL, SND_ALIAS_ID | SND_ASYNC); PlaySoundW((LPCWSTR)sound, NULL, SND_ALIAS_ID | SND_ASYNC);
#endif #endif
int button; int *button;
SDL_ShowMessageBox(&data, &button);
return button ? true : false; #ifdef OS_OSX
// Message boxes and UI changes must be performed from the main thread on macOS Mojave and above.
// This block ensures the message box will show from the main thread.
dispatch_sync(dispatch_get_main_queue(),
^{ SDL_ShowMessageBox(&data, button); }
);
// dispatch_block_wait(dispatch_get_main_queue(), DISPATCH_TIME_FOREVER);
*button = 1; // XXX Setting the button's value doesn't seem to work.
#else
SDL_ShowMessageBox(&data, button);
#endif
return (*button) ? true : false;
} }
std::string Oneshot::textinput(const char* prompt, int char_limit, const char* fontName) { std::string Oneshot::textinput(const char* prompt, int char_limit, const char* fontName) {