ocarina: Force callbacks onto the main thread
Gstreamer uses multiple threads, and doing gtk calls outside the main thread can lead to X11 errors. I get around this by creating a new signal to respond to by the main loop. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
747ba85fbb
commit
1f02fa3d9c
|
@ -9,24 +9,13 @@
|
|||
#include <ocarina/settings.h>
|
||||
#include <ocarina/footer.h>
|
||||
|
||||
static void conditional_lock(callback_t type)
|
||||
{
|
||||
if (type == IDLE_TASK_QUEUED)
|
||||
return;
|
||||
gdk_threads_enter();
|
||||
}
|
||||
static guint signalid;
|
||||
static gpointer object;
|
||||
|
||||
static void conditional_unlock(callback_t type)
|
||||
{
|
||||
if (type == IDLE_TASK_QUEUED)
|
||||
return;
|
||||
gdk_threads_leave();
|
||||
}
|
||||
|
||||
static void cb_handler(callback_t type)
|
||||
static void handle_callback(gpointer obj, callback_t type, gpointer data)
|
||||
{
|
||||
libsaria::Track *current;
|
||||
conditional_lock(type);
|
||||
println("type? %d", type);
|
||||
|
||||
switch (type) {
|
||||
case PLAY:
|
||||
|
@ -58,12 +47,52 @@ static void cb_handler(callback_t type)
|
|||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
conditional_unlock(type);
|
||||
static void cb_lock(callback_t type)
|
||||
{
|
||||
switch(type) {
|
||||
case TRACK_LOADED:
|
||||
gdk_threads_enter();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void cb_unlock(callback_t type)
|
||||
{
|
||||
switch(type) {
|
||||
case TRACK_LOADED:
|
||||
gdk_threads_leave();
|
||||
default:
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
static void cb_handler(callback_t type)
|
||||
{
|
||||
cb_lock(type);
|
||||
g_signal_emit_by_name(G_OBJECT(object), "ocarina-callback", type);
|
||||
cb_unlock(type);
|
||||
}
|
||||
|
||||
void setup_callbacks()
|
||||
{
|
||||
println("Ocarina setting up callbacks");
|
||||
object = g_object_new(G_TYPE_OBJECT, NULL);
|
||||
signalid = g_signal_new("ocarina-callback",
|
||||
G_TYPE_OBJECT,
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
G_TYPE_NONE,
|
||||
1,
|
||||
G_TYPE_UINT);
|
||||
g_signal_connect(G_OBJECT(object),
|
||||
"ocarina-callback",
|
||||
G_CALLBACK(handle_callback),
|
||||
NULL);
|
||||
set_cb_handler(cb_handler);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue