[gtk+] API: Add gtk_test_widget_wait_for_draw ()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] API: Add gtk_test_widget_wait_for_draw ()
- Date: Fri, 17 May 2013 18:50:56 +0000 (UTC)
commit 8616dbbad39eb8484e981018c2fb6338f6064766
Author: Benjamin Otte <otte redhat com>
Date: Fri May 17 01:35:04 2013 +0200
API: Add gtk_test_widget_wait_for_draw ()
See docs and following commits for what it's supposed to do. Let's hope
it fixes the flakiness in tests.
gtk/gtktestutils.c | 39 +++++++++++++++++++++++++++++++++++++++
gtk/gtktestutils.h | 2 ++
2 files changed, 41 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtktestutils.c b/gtk/gtktestutils.c
index c41c892..0b3831d 100644
--- a/gtk/gtktestutils.c
+++ b/gtk/gtktestutils.c
@@ -116,6 +116,45 @@ test_find_widget_input_windows (GtkWidget *widget,
return g_slist_reverse (matches);
}
+static gboolean
+quit_main_loop_callback (GtkWidget *widget,
+ GdkFrameClock *frame_clock,
+ gpointer user_data)
+{
+ gtk_main_quit ();
+
+ return G_SOURCE_REMOVE;
+}
+
+/**
+ * gtk_test_widget_wait_for_draw:
+ * @widget: the widget to wait for
+ *
+ * Enters the main loop and waits for @widget to be "drawn". In this
+ * context that means it waits for the frame clock of @widget to have
+ * run a full styling, layout and drawing cycle.
+ *
+ * This function is intended to be used for syncing with actions that
+ * depend on @widget relayouting or on interaction with the display
+ * server.
+ **/
+void
+gtk_test_widget_wait_for_draw (GtkWidget *widget)
+{
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ /* We can do this here because the whole tick procedure does not
+ * reenter the main loop. Otherwise we'd need to manually get the
+ * frame clock and connect to the after-paint signal.
+ */
+ gtk_widget_add_tick_callback (widget,
+ quit_main_loop_callback,
+ NULL,
+ NULL);
+
+ gtk_main ();
+}
+
/**
* gtk_test_widget_send_key:
* @widget: Widget to generate a key press and release on.
diff --git a/gtk/gtktestutils.h b/gtk/gtktestutils.h
index d382dea..badbd1f 100644
--- a/gtk/gtktestutils.h
+++ b/gtk/gtktestutils.h
@@ -61,6 +61,8 @@ GDK_AVAILABLE_IN_ALL
gboolean gtk_test_spin_button_click (GtkSpinButton *spinner,
guint button,
gboolean upwards);
+GDK_AVAILABLE_IN_3_10
+void gtk_test_widget_wait_for_draw (GtkWidget *widget);
GDK_AVAILABLE_IN_ALL
gboolean gtk_test_widget_click (GtkWidget *widget,
guint button,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]