From d149289e00c482f721c94fe9a2d14cb2f43cd8d5 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 2 May 2018 11:13:32 -0400 Subject: [PATCH] gui/audio: Close popover menu after 10 seconds And don't touch the pause count so we don't surprise the user later. Signed-off-by: Anna Schumaker --- gui/audio.c | 19 +++++++++++++++++-- include/gui/audio.h | 1 + tests/gui/audio.c | 5 +++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/gui/audio.c b/gui/audio.c index 04d90262..21767c9c 100644 --- a/gui/audio.c +++ b/gui/audio.c @@ -9,7 +9,8 @@ #include #include -static guint audio_timeout = 0; +static guint audio_timeout = 0; +static guint popover_timeout = 0; static inline void __gui_audio_set_label_markup(GtkLabel *label, const gchar *size, @@ -89,8 +90,11 @@ struct audio_callbacks audio_cb = { void __gui_audio_pause(GtkButton *button, gpointer data) { audio_pause(); - if (audio_get_pause_count() > -1) + if (audio_get_pause_count() > -1) { gtk_popover_popup(gui_pause_popover()); + popover_timeout = g_timeout_add_seconds(10, + gui_audio_popover_timeout, NULL); + } } void __gui_audio_pause_change_text(GtkEntry *entry, gpointer data) @@ -136,6 +140,9 @@ void __gui_audio_pause_popover_popdown(GtkButton *button, gpointer data) #ifdef CONFIG_TESTING gtk_widget_hide(GTK_WIDGET(gui_pause_popover())); #endif /* CONFIG_TESTING */ + + g_source_remove(popover_timeout); + popover_timeout = 0; } void __gui_audio_pause_popover_clear(GtkButton *button, gpointer data) @@ -175,6 +182,8 @@ void gui_audio_init() void gui_audio_deinit() { g_source_remove(audio_timeout); + if (popover_timeout > 0) + g_source_remove(popover_timeout); } int gui_audio_timeout(gpointer data) @@ -188,3 +197,9 @@ int gui_audio_timeout(gpointer data) g_free(position); return G_SOURCE_CONTINUE; } + +int gui_audio_popover_timeout(gpointer data) +{ + __gui_audio_pause_popover_popdown(NULL, data); + return G_SOURCE_REMOVE; +} diff --git a/include/gui/audio.h b/include/gui/audio.h index f00bb454..e44aff7d 100644 --- a/include/gui/audio.h +++ b/include/gui/audio.h @@ -17,6 +17,7 @@ void gui_audio_deinit(); /* Called to update the current track position. */ int gui_audio_timeout(); +int gui_audio_popover_timeout(); /* Called to get the label displaying the album tag. */ static inline GtkLabel *gui_album_tag(void) diff --git a/tests/gui/audio.c b/tests/gui/audio.c index 158dcd90..779da198 100644 --- a/tests/gui/audio.c +++ b/tests/gui/audio.c @@ -129,6 +129,11 @@ static void test_audio_buttons() g_assert_cmpstr(gtk_entry_get_text(gui_pause_entry()), ==, "Pause after next track"); g_assert_false(gtk_widget_is_visible(GTK_WIDGET(gui_pause_popover()))); + gtk_button_clicked(gui_pause_button()); + g_assert_true(gtk_widget_is_visible(GTK_WIDGET(gui_pause_popover()))); + g_assert_cmpint(gui_audio_popover_timeout(), ==, G_SOURCE_REMOVE); + g_assert_false(gtk_widget_is_visible(GTK_WIDGET(gui_pause_popover()))); + gtk_button_clicked(gui_play_button()); test_main_loop(); g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PLAYING);