gui/idle: Add a function to disable processing idle tasks

This is needed during ocarina shutdown to prevent a segfault.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-02-26 10:43:07 -05:00
parent fff2da5439
commit bc513532c1
3 changed files with 15 additions and 3 deletions

View File

@ -5,6 +5,8 @@
#include <gui/builder.h>
#include <gtk/gtk.h>
static guint idle_id = 0;
static gboolean __on_idle(gpointer data)
{
GtkProgressBar *progress = GTK_PROGRESS_BAR(data);
@ -14,6 +16,7 @@ static gboolean __on_idle(gpointer data)
return gtk_widget_is_visible(gui_builder_widget("o_window"));
} else {
gtk_widget_hide(GTK_WIDGET(progress));
idle_id = 0;
return G_SOURCE_REMOVE;
}
}
@ -23,5 +26,12 @@ void gui_idle_enable()
GtkWidget *progress = gui_builder_widget("o_idle_progress");
gtk_widget_show(progress);
g_idle_add(__on_idle, progress);
idle_id = g_idle_add(__on_idle, progress);
}
void gui_idle_disable()
{
if (idle_id)
g_source_remove(idle_id);
idle_cancel();
}

View File

@ -2,7 +2,6 @@
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/core.h>
#include <core/idle.h>
#include <gui/audio.h>
#include <gui/builder.h>
#include <gui/collection.h>
@ -75,7 +74,7 @@ static void __ocarina_startup(GApplication *application, gpointer data)
static void __ocarina_shutdown(GApplication *application, gpointer data)
{
idle_cancel();
gui_idle_disable();
core_deinit();
gui_window_deinit();

View File

@ -7,4 +7,7 @@
/* Called to enable processing idle queue tasks. */
void gui_idle_enable();
/* Called to disable processing idle queue tasks. */
void gui_idle_disable();
#endif /* OCARINA_GUI_IDLE_H */