[gtk/kill-register-surface: 8/10] Stop using gdk_surface_set_user_data for widget



commit 1a3dae496a6fd216dad77a5d2f1c7140e7966ff1
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Feb 23 18:44:40 2019 -0500

    Stop using gdk_surface_set_user_data for widget
    
    Keep this private to GTK, by using g_object_set_data.

 gtk/gtkroot.c          |  8 ++++----
 gtk/gtkwidget.c        | 31 +++++++++++++++++++------------
 gtk/gtkwidgetprivate.h |  2 ++
 3 files changed, 25 insertions(+), 16 deletions(-)
---
diff --git a/gtk/gtkroot.c b/gtk/gtkroot.c
index 0a32288ba9..158e7cb1df 100644
--- a/gtk/gtkroot.c
+++ b/gtk/gtkroot.c
@@ -114,12 +114,12 @@ gtk_root_get_surface_transform (GtkRoot *self,
 GtkWidget *
 gtk_root_get_for_surface (GdkSurface *surface)
 {
-  gpointer user_data;
+  GtkWidget *widget;
 
-  gdk_surface_get_user_data (surface, &user_data);
+  widget = gtk_widget_for_surface (surface);
 
-  if (user_data && GTK_IS_ROOT (user_data))
-    return GTK_WIDGET (user_data);
+  if (widget && GTK_IS_ROOT (widget))
+    return widget;
 
   return NULL;
 }
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 531fb3da29..51fed0c135 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -703,6 +703,7 @@ static GQuark           quark_widget_path = 0;
 static GQuark           quark_action_muxer = 0;
 static GQuark           quark_font_options = 0;
 static GQuark           quark_font_map = 0;
+static GQuark           quark_surface_widget = 0;
 
 GParamSpecPool         *_gtk_widget_child_property_pool = NULL;
 GObjectNotifyContext   *_gtk_widget_child_property_notify_context = NULL;
@@ -898,6 +899,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
   quark_action_muxer = g_quark_from_static_string ("gtk-widget-action-muxer");
   quark_font_options = g_quark_from_static_string ("gtk-widget-font-options");
   quark_font_map = g_quark_from_static_string ("gtk-widget-font-map");
+  quark_surface_widget = g_quark_from_static_string ("gtk-widget-surface-widget");
 
   _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
   cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
@@ -8598,13 +8600,10 @@ static gboolean
 is_my_surface (GtkWidget *widget,
               GdkSurface *surface)
 {
-  gpointer user_data;
-
   if (!surface)
     return FALSE;
 
-  gdk_surface_get_user_data (surface, &user_data);
-  return (user_data == widget);
+  return gtk_widget_for_surface (surface) == widget;
 }
 
 /*
@@ -11428,6 +11427,18 @@ surface_event (GdkSurface *surface,
   return TRUE;
 }
 
+GtkWidget *
+gtk_widget_for_surface (GdkSurface *surface)
+{
+  gpointer user_data;
+
+  user_data = g_object_get_qdata (surface, quark_surface_widget);
+  if (user_data)
+    return GTK_WIDGET (user_data);
+
+  return NULL;
+}
+
 /**
  * gtk_widget_register_surface:
  * @widget: a #GtkWidget
@@ -11446,15 +11457,11 @@ void
 gtk_widget_register_surface (GtkWidget    *widget,
                             GdkSurface    *surface)
 {
-  gpointer user_data;
-
   g_return_if_fail (GTK_IS_WIDGET (widget));
   g_return_if_fail (GDK_IS_SURFACE (surface));
 
-  gdk_surface_get_user_data (surface, &user_data);
-  g_assert (user_data == NULL);
-
-  gdk_surface_set_user_data (surface, widget);
+  g_assert (gtk_widget_for_surface (surface) == NULL);
+  g_object_set_qdata (surface, quark_surface_widget, widget);
 
   g_signal_connect (surface, "render", G_CALLBACK (surface_expose), widget);
   g_signal_connect (surface, "event", G_CALLBACK (surface_event), widget);
@@ -11478,9 +11485,9 @@ gtk_widget_unregister_surface (GtkWidget    *widget,
   g_return_if_fail (GTK_IS_WIDGET (widget));
   g_return_if_fail (GDK_IS_SURFACE (surface));
 
-  gdk_surface_get_user_data (surface, &user_data);
+  user_data = g_object_get_qdata (surface, quark_surface_widget);
   g_assert (user_data == widget);
-  gdk_surface_set_user_data (surface, NULL);
+  g_object_set_qdata (surface, quark_surface_widget, NULL);
 
   g_signal_handlers_disconnect_by_func (surface, surface_expose, widget);
   g_signal_handlers_disconnect_by_func (surface, surface_event, widget);
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index d0f3016364..af9709a814 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -337,6 +337,8 @@ gboolean          gtk_widget_run_controllers               (GtkWidget
                                                             const GdkEvent      *event,
                                                             GtkPropagationPhase  phase);
 
+gpointer          gtk_widget_for_surface                   (GdkSurface *surface);
+
 /* inline getters */
 
 static inline GtkWidget *


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