[gtk/wip/matthiasc/popup: 15/18] testpopup: Use a GtkPopup



commit 63a32adbd49aaa3a65ec3a66c78a146339e3608d
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Feb 24 08:17:58 2019 -0500

    testpopup: Use a GtkPopup

 gtk/gtk.h         |  1 +
 gtk/meson.build   |  1 +
 tests/testpopup.c | 41 +++++++++++++----------------------------
 3 files changed, 15 insertions(+), 28 deletions(-)
---
diff --git a/gtk/gtk.h b/gtk/gtk.h
index 62a3bb3d7f..533c249f93 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -165,6 +165,7 @@
 #include <gtk/gtkpicture.h>
 #include <gtk/gtkpopover.h>
 #include <gtk/gtkpopovermenu.h>
+#include <gtk/gtkpopup.h>
 #include <gtk/gtkprintcontext.h>
 #include <gtk/gtkprintoperation.h>
 #include <gtk/gtkprintoperationpreview.h>
diff --git a/gtk/meson.build b/gtk/meson.build
index 2c705982a9..2c65aae0c9 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -296,6 +296,7 @@ gtk_public_sources = files([
   'gtkpicture.c',
   'gtkpopover.c',
   'gtkpopovermenu.c',
+  'gtkpopup.c',
   'gtkprintcontext.c',
   'gtkprintoperation.c',
   'gtkprintoperationpreview.c',
diff --git a/tests/testpopup.c b/tests/testpopup.c
index b496fe5eae..ba49c81036 100644
--- a/tests/testpopup.c
+++ b/tests/testpopup.c
@@ -11,41 +11,19 @@ draw_popup (GtkDrawingArea  *da,
   cairo_paint (cr);
 }
 
-static void
-place_popup (GtkEventControllerMotion *motion,
-             gdouble                   x,
-             gdouble                   y,
-             GtkWidget                *popup)
-{
-  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)
+create_popup (GtkWidget *parent,
+              GtkWidget *label)
 {
   GtkWidget *popup, *da;
-  GtkEventController *motion;
 
-  popup = gtk_window_new (GTK_WINDOW_POPUP);
+  popup = gtk_popup_new ();
+  gtk_popup_set_relative_to (GTK_POPUP (popup), label);
   da = gtk_drawing_area_new ();
   gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (da), draw_popup, NULL, NULL);
   gtk_container_add (GTK_CONTAINER (popup), da);
 
   gtk_widget_set_size_request (GTK_WIDGET (popup), 20, 20);
-  gtk_window_set_transient_for (GTK_WINDOW (popup), GTK_WINDOW (parent));
-
-  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);
 
@@ -56,13 +34,20 @@ int
 main (int argc, char *argv[])
 {
   GtkWidget *window;
+  GtkWidget *label;
 
   gtk_init ();
 
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+  gtk_window_set_default_size (GTK_WINDOW (window), 300, 200);
+
+  label = gtk_label_new ("x");
+  gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
+  gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+  gtk_container_add (GTK_CONTAINER (window), label);
 
-  g_signal_connect (window, "destroy", gtk_main_quit, NULL);
-  g_signal_connect (window, "map", G_CALLBACK (on_map), NULL);
+  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
+  g_signal_connect (window, "map", G_CALLBACK (create_popup), label);
 
   gtk_widget_show (window);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]