libui/unix/main.c

80 lines
1.4 KiB
C
Raw Normal View History

2019-04-21 11:24:19 -05:00
// 6 april 2015
#include "uipriv_unix.h"
const char **uiprivSysInitErrors(void)
2019-04-21 11:24:19 -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
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) {
// 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;
}
void uiMain(void)
{
2019-05-28 23:54:22 -05:00
if (!uiprivCheckInitializedAndThread())
return;
gtk_main();
}
void uiQuit(void)
{
2019-05-28 23:54:22 -05:00
if (!uiprivCheckInitializedAndThread())
return;
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;
}
q = g_new0(struct queued, 1);
q->f = f;
q->data = data;
gdk_threads_add_idle(doqueued, q);
}
2019-05-28 23:54:22 -05:00
bool uiprivSysCheckThread(void)
{
return pthread_equal(pthread_self(), mainThread);
}
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
}