[gtk/wip/matthiasc/popup4] popover: Track the parent position



commit 85670599f06e340f18b0f092744ab8cc0951050d
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Apr 22 19:06:39 2019 +0000

    popover: Track the parent position
    
    Use the new position-changed-callback functionality
    to move the popover whenever the parent changes its
    position in the window. This currently works for X11,
    but not for Wayland (due to restrictions in the
    move-to-rect implementation.

 gtk/gtkpopover.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
---
diff --git a/gtk/gtkpopover.c b/gtk/gtkpopover.c
index 13fd55f13f..0d8a884bc3 100644
--- a/gtk/gtkpopover.c
+++ b/gtk/gtkpopover.c
@@ -142,6 +142,7 @@ typedef struct {
   GtkWidget *relative_to;
   GdkRectangle pointing_to;
   gboolean has_pointing_to;
+  guint position_changed_cb;
   GtkPositionType position;
   gboolean modal;
   gboolean has_grab;
@@ -523,6 +524,24 @@ grab_prepare_func (GdkSeat    *seat,
   gdk_surface_show (surface);
 }
 
+static void
+unset_position_changed_cb (gpointer data)
+{
+  GtkPopover *popover = data;
+  GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
+
+  priv->position_changed_cb = 0;
+}
+
+static gboolean
+position_changed_cb (GtkWidget  *widget,
+                     gpointer    user_data)
+{
+  move_to_rect (GTK_POPOVER (user_data));
+
+  return G_SOURCE_CONTINUE;
+}
+
 static void
 gtk_popover_map (GtkWidget *widget)
 {
@@ -544,6 +563,8 @@ gtk_popover_map (GtkWidget *widget)
   gtk_widget_get_surface_allocation (priv->relative_to, &parent_rect);
   move_to_rect (popover);
 
+  priv->position_changed_cb = gtk_widget_add_position_changed_callback (priv->relative_to, 
position_changed_cb, popover, unset_position_changed_cb);
+
   GTK_WIDGET_CLASS (gtk_popover_parent_class)->map (widget);
 
   child = gtk_bin_get_child (GTK_BIN (widget));
@@ -558,6 +579,9 @@ gtk_popover_unmap (GtkWidget *widget)
   GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
   GtkWidget *child;
 
+  gtk_widget_remove_position_changed_callback (priv->relative_to, priv->position_changed_cb);
+  priv->position_changed_cb = 0;
+
   GTK_WIDGET_CLASS (gtk_popover_parent_class)->unmap (widget);
 
   gdk_surface_hide (priv->surface);


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