2019-04-21 11:24:19 -05:00
|
|
|
// 6 april 2015
|
|
|
|
#include "uipriv_unix.h"
|
|
|
|
|
2019-05-09 11:07:28 -05:00
|
|
|
const char **uiprivSysInitErrors(void)
|
2019-04-21 11:24:19 -05:00
|
|
|
{
|
2019-05-09 11:07:28 -05:00
|
|
|
return NULL;
|
|
|
|
}
|
2019-04-21 11:24:19 -05:00
|
|
|
|
2019-05-28 23:54:22 -05:00
|
|
|
static pthread_t mainThread;
|
|
|
|
static gboolean initialized = FALSE; // TODO deduplicate this from common/init.c
|
|
|
|
|
2019-05-09 11:07:28 -05:00
|
|
|
int uiprivSysInit(void *options, uiInitError *err)
|
|
|
|
{
|
|
|
|
GError *gerr = NULL;
|
2019-04-21 11:24:19 -05:00
|
|
|
|
|
|
|
if (gtk_init_with_args(NULL, NULL, NULL, NULL, NULL, &gerr) == FALSE) {
|
2019-05-09 11:07:28 -05:00
|
|
|
// TODO make sure this is safe
|
2019-04-21 11:24:19 -05:00
|
|
|
strncpy(err->Message, gerr->message, 255);
|
|
|
|
g_error_free(gerr);
|
|
|
|
return 0;
|
|
|
|
}
|
2019-05-28 23:54:22 -05:00
|
|
|
mainThread = pthread_self();
|
|
|
|
initialized = TRUE;
|
2019-04-21 11:24:19 -05:00
|
|
|
return 1;
|
|
|
|
}
|
2019-04-28 13:52:39 -05:00
|
|
|
|
|
|
|
void uiMain(void)
|
|
|
|
{
|
2019-05-28 23:54:22 -05:00
|
|
|
if (!uiprivCheckInitializedAndThread())
|
|
|
|
return;
|
2019-04-28 13:52:39 -05:00
|
|
|
gtk_main();
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiQuit(void)
|
|
|
|
{
|
2019-05-28 23:54:22 -05:00
|
|
|
if (!uiprivCheckInitializedAndThread())
|
|
|
|
return;
|
2019-04-28 13:52:39 -05:00
|
|
|
gtk_main_quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
struct queued {
|
|
|
|
void (*f)(void *);
|
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean doqueued(gpointer data)
|
|
|
|
{
|
|
|
|
struct queued *q = (struct queued *) data;
|
|
|
|
|
|
|
|
(*(q->f))(q->data);
|
|
|
|
g_free(q);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiQueueMain(void (*f)(void *data), void *data)
|
|
|
|
{
|
|
|
|
struct queued *q;
|
|
|
|
|
2019-05-28 23:54:22 -05:00
|
|
|
if (!initialized) {
|
|
|
|
uiprivProgrammerError(uiprivProgrammerErrorNotInitialized, uiprivFunc);
|
|
|
|
return;
|
|
|
|
}
|
2019-04-28 13:52:39 -05:00
|
|
|
q = g_new0(struct queued, 1);
|
|
|
|
q->f = f;
|
|
|
|
q->data = data;
|
|
|
|
gdk_threads_add_idle(doqueued, q);
|
|
|
|
}
|
2019-05-26 22:25:08 -05:00
|
|
|
|
2019-05-28 23:54:22 -05:00
|
|
|
bool uiprivSysCheckThread(void)
|
|
|
|
{
|
|
|
|
return pthread_equal(pthread_self(), mainThread);
|
|
|
|
}
|
|
|
|
|
2019-05-26 22:25:08 -05:00
|
|
|
void uiprivReportError(const char *prefix, const char *msg, const char *suffix, bool internal)
|
|
|
|
{
|
|
|
|
g_critical("%s: %s. %s", prefix, msg, suffix);
|
|
|
|
G_BREAKPOINT();
|
|
|
|
abort(); // we shouldn't reach here
|
|
|
|
}
|