[gtk/wip/carlosg/public-legacy-controller: 5/8] tests: Use GtkEventControllerMotion in testpopup
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/carlosg/public-legacy-controller: 5/8] tests: Use GtkEventControllerMotion in testpopup
- Date: Mon, 15 Oct 2018 15:41:03 +0000 (UTC)
commit 3c73f70daef6d25c33f90d58dfee5e4090913a45
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri Oct 12 19:52:58 2018 +0200
tests: Use GtkEventControllerMotion in testpopup
Track motion through it, instead of a GtkWidget::event handler.
tests/testpopup.c | 36 +++++++++++++++++++-----------------
1 file changed, 19 insertions(+), 17 deletions(-)
---
diff --git a/tests/testpopup.c b/tests/testpopup.c
index 504c67d1ce..085d08ca2f 100644
--- a/tests/testpopup.c
+++ b/tests/testpopup.c
@@ -12,29 +12,28 @@ draw_popup (GtkDrawingArea *da,
}
static gboolean
-place_popup (GtkWidget *parent,
- GdkEvent *event,
- GtkWidget *popup)
+place_popup (GtkEventControllerMotion *motion,
+ gdouble x,
+ gdouble y,
+ GtkWidget *popup)
{
- gint width, height;
- gdouble x, y;
-
- if (gdk_event_get_event_type (event) == GDK_MOTION_NOTIFY)
- {
- gtk_window_get_size (GTK_WINDOW (popup), &width, &height);
- gdk_event_get_root_coords (event, &x, &y);
- gtk_window_move (GTK_WINDOW (popup),
- (int) x - width / 2,
- (int) y - height / 2);
- }
-
- return GDK_EVENT_PROPAGATE;
+ gint width, height, win_x, win_y;
+ GtkWidget *widget;
+
+ widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (motion));
+
+ gtk_window_get_size (GTK_WINDOW (popup), &width, &height);
+ gtk_window_get_position (GTK_WINDOW (widget), &win_x, &win_y);
+ gtk_window_move (GTK_WINDOW (popup),
+ (int) win_x + x - width / 2,
+ (int) win_y + y - height / 2);
}
static gboolean
on_map (GtkWidget *parent)
{
GtkWidget *popup, *da;
+ GtkEventController *motion;
popup = gtk_window_new (GTK_WINDOW_POPUP);
da = gtk_drawing_area_new ();
@@ -43,7 +42,10 @@ on_map (GtkWidget *parent)
gtk_widget_set_size_request (GTK_WIDGET (popup), 20, 20);
gtk_window_set_transient_for (GTK_WINDOW (popup), GTK_WINDOW (parent));
- g_signal_connect (parent, "event", G_CALLBACK (place_popup), popup);
+
+ motion = gtk_event_controller_motion_new ();
+ gtk_widget_add_controller (parent, motion);
+ g_signal_connect (motion, "motion", G_CALLBACK (place_popup), popup);
gtk_widget_show (popup);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]