macOS: Rename the window only on the main thread: macOS doesn't like non-main threads modifying the UI.

This commit is contained in:
C.W. Betts 2021-05-19 15:49:03 -06:00
commit 20d7014e4a

View file

@ -1,9 +1,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#if defined(__APPLE__) && defined(__aarch64__)
#ifdef __APPLE__
#include <string.h>
#include <dispatch/dispatch.h>
#ifdef __aarch64__
#include <pthread.h>
#endif
#endif
#include "ibm.h"
#include "device.h"
@ -519,6 +523,14 @@ int serial_fifo_read, serial_fifo_write;
int emu_fps = 0;
#ifdef __APPLE__
static void _set_window_title(void *s)
{
set_window_title((const char *)s);
free(s);
}
#endif
void runpc()
{
char s[200];
@ -594,7 +606,12 @@ void runpc()
{
win_title_update=0;
sprintf(s, "PCem v17 - %i%% - %s - %s - %s", fps, model_getname(), models[model].cpu[cpu_manufacturer].cpus[cpu].name, (!mousecapture) ? "Click to capture mouse" : ((mouse_get_type(mouse_type) & MOUSE_TYPE_3BUTTON) ? "Press CTRL-END to release mouse" : "Press CTRL-END or middle button to release mouse"));
#ifdef __APPLE__
// Needed due to modifying the UI on the non-main thread is a big no-no.
dispatch_async_f(dispatch_get_main_queue(), strdup(s), _set_window_title);
#else
set_window_title(s);
#endif
}
done++;
}