From f453d84886fbcb89bd24b1f50c7526300605ce9b Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Fri, 31 Jan 2020 01:53:02 +0100 Subject: [PATCH] [GTK3] Clear sidebar in async input requests --- gtk3/main.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/gtk3/main.c b/gtk3/main.c index b033da3..b0cfafc 100644 --- a/gtk3/main.c +++ b/gtk3/main.c @@ -59,8 +59,8 @@ static gchar *vram_viewer_active_tab = ""; static gboolean vram_viewer_is_cgb = false; static uint8_t vram_viewer_palette_data[16][0x40]; -static bool running = false; -static bool stopping = false; +static volatile bool running = false; +static volatile bool stopping = false; #define tileset_buffer_length 256 * 192 * 4 static uint32_t tileset_buffer[tileset_buffer_length] = {0}; @@ -420,7 +420,16 @@ static char *sync_console_input(GB_gameboy_t *gb) { return input; } +static void clear_sidebar() { + GtkTextView *sidebar_output = builder_get(GTK_TEXT_VIEW, "console_sidebar_output"); + GtkTextBuffer *sidebar_output_text_buf = gtk_text_view_get_buffer(sidebar_output); + gtk_text_buffer_set_text(sidebar_output_text_buf, "", -1); +} + static char *async_console_input(GB_gameboy_t *gb) { + // TODO: This is rather ugly + g_idle_add((GSourceFunc) clear_sidebar, NULL); + if (debugger_input_queue->len == 0) return NULL; g_mutex_lock(&debugger_input_mutex); @@ -515,9 +524,7 @@ static void append_pending_output(void) { g_rec_mutex_lock(&console_output_lock); if (should_clear_sidebar) { - GtkTextView *sidebar_output = builder_get(GTK_TEXT_VIEW, "console_sidebar_output"); - GtkTextBuffer *sidebar_output_text_buf = gtk_text_view_get_buffer(sidebar_output); - gtk_text_buffer_set_text(sidebar_output_text_buf, "", -1); + clear_sidebar(); should_clear_sidebar = FALSE; }