testgtk: Redo the event watcher case

Make this watch for emissions of ::event, since we
want to get rid of individual signals first.
This commit is contained in:
Matthias Clasen 2018-01-01 11:08:44 -05:00
parent 6ac33215a5
commit 96b2b1b2f3

View File

@ -4516,8 +4516,7 @@ create_display_screen (GtkWidget *widget)
/* Event Watcher /* Event Watcher
*/ */
static gulong event_watcher_enter_id = 0; static gulong event_watcher_id = 0;
static gulong event_watcher_leave_id = 0;
static gboolean static gboolean
event_watcher (GSignalInvocationHint *ihint, event_watcher (GSignalInvocationHint *ihint,
@ -4525,9 +4524,16 @@ event_watcher (GSignalInvocationHint *ihint,
const GValue *param_values, const GValue *param_values,
gpointer data) gpointer data)
{ {
g_print ("Watch: \"%s\" emitted for %s\n", GObject *object;
g_signal_name (ihint->signal_id), GdkEvent *event;
G_OBJECT_TYPE_NAME (g_value_get_object (param_values + 0)));
object = g_value_get_object (param_values + 0);
event = g_value_get_object (param_values + 1);
if (gdk_event_get_event_type (event) == GDK_ENTER_NOTIFY ||
gdk_event_get_event_type (event) == GDK_LEAVE_NOTIFY)
g_print ("Watch: \"%s\" emitted for %s\n",
g_enum_to_string (GDK_TYPE_EVENT_TYPE, gdk_event_get_event_type (event)),
G_OBJECT_TYPE_NAME (object));
return TRUE; return TRUE;
} }
@ -4535,32 +4541,27 @@ event_watcher (GSignalInvocationHint *ihint,
static void static void
event_watcher_down (void) event_watcher_down (void)
{ {
if (event_watcher_enter_id) if (event_watcher_id)
{ {
guint signal_id; guint signal_id;
signal_id = g_signal_lookup ("enter_notify_event", GTK_TYPE_WIDGET); signal_id = g_signal_lookup ("event", GTK_TYPE_WIDGET);
g_signal_remove_emission_hook (signal_id, event_watcher_enter_id); g_signal_remove_emission_hook (signal_id, event_watcher_id);
event_watcher_enter_id = 0; event_watcher_id = 0;
signal_id = g_signal_lookup ("leave_notify_event", GTK_TYPE_WIDGET);
g_signal_remove_emission_hook (signal_id, event_watcher_leave_id);
event_watcher_leave_id = 0;
} }
} }
static void static void
event_watcher_toggle (void) event_watcher_toggle (void)
{ {
if (event_watcher_enter_id) if (event_watcher_id)
event_watcher_down (); event_watcher_down ();
else else
{ {
guint signal_id; guint signal_id;
signal_id = g_signal_lookup ("enter_notify_event", GTK_TYPE_WIDGET); signal_id = g_signal_lookup ("event", GTK_TYPE_WIDGET);
event_watcher_enter_id = g_signal_add_emission_hook (signal_id, 0, event_watcher, NULL, NULL); event_watcher_id = g_signal_add_emission_hook (signal_id, 0, event_watcher, NULL, NULL);
signal_id = g_signal_lookup ("leave_notify_event", GTK_TYPE_WIDGET);
event_watcher_leave_id = g_signal_add_emission_hook (signal_id, 0, event_watcher, NULL, NULL);
} }
} }