Merge branch 'kill-register-surface' into 'master'

Remove gdk_surface_set_user_data

See merge request GNOME/gtk!605
This commit is contained in:
Matthias Clasen 2019-02-24 03:46:04 +00:00
commit 0d39cb7379
16 changed files with 64 additions and 173 deletions

View File

@ -71,20 +71,12 @@ find_toplevel_at_pointer (GdkDisplay *display)
GdkSurface *pointer_window;
GtkWidget *widget = NULL;
pointer_window = gdk_device_get_surface_at_position (gtk_get_current_event_device (),
NULL, NULL);
pointer_window = gdk_device_get_surface_at_position (gtk_get_current_event_device (), NULL, NULL);
/* The user data field of a GdkSurface is used to store a pointer
* to the widget that created it.
*/
if (pointer_window)
{
gpointer widget_ptr;
gdk_surface_get_user_data (pointer_window, &widget_ptr);
widget = widget_ptr;
}
widget = GTK_WIDGET (gtk_root_get_for_surface (pointer_window));
return widget ? gtk_widget_get_toplevel (widget) : NULL;
return widget;
}
static void

View File

@ -240,7 +240,6 @@ gdk_surface_thaw_updates
gdk_surface_get_frame_clock
<SUBSECTION>
gdk_surface_set_user_data
gdk_surface_set_accept_focus
gdk_surface_get_accept_focus
gdk_surface_set_focus_on_map
@ -252,7 +251,6 @@ gdk_surface_set_title
GDK_PARENT_RELATIVE
gdk_surface_set_cursor
gdk_surface_get_cursor
gdk_surface_get_user_data
gdk_surface_get_geometry
gdk_surface_set_geometry_hints
gdk_surface_get_width
@ -278,7 +276,6 @@ GdkModifierIntent
gdk_surface_get_parent
gdk_surface_get_toplevel
gdk_surface_get_children
gdk_surface_get_children_with_user_data
gdk_surface_peek_children
gdk_surface_set_icon_name
gdk_surface_set_transient_for

View File

@ -40,4 +40,8 @@ PangoDirection gdk_unichar_direction (gunichar ch);
PangoDirection gdk_find_base_dir (const char *text,
int len);
void gdk_surface_set_widget (GdkSurface *surface,
gpointer widget);
gpointer gdk_surface_get_widget (GdkSurface *surface);
#endif /* __GDK__PRIVATE_H__ */

View File

@ -145,7 +145,7 @@ struct _GdkSurface
GdkSurface *parent;
GdkSurface *transient_for;
gpointer user_data;
gpointer widget;
gint x;
gint y;

View File

@ -1042,43 +1042,17 @@ gdk_surface_destroy (GdkSurface *surface)
g_object_unref (surface);
}
/**
* gdk_surface_set_user_data:
* @surface: a #GdkSurface
* @user_data: (allow-none) (type GObject.Object): user data
*
* For most purposes this function is deprecated in favor of
* g_object_set_data(). However, for historical reasons GTK+ stores
* the #GtkWidget that owns a #GdkSurface as user data on the
* #GdkSurface. So, custom widget implementations should use
* this function for that. If GTK+ receives an event for a #GdkSurface,
* and the user data for the surface is non-%NULL, GTK+ will assume the
* user data is a #GtkWidget, and forward the event to that widget.
*
**/
void
gdk_surface_set_user_data (GdkSurface *surface,
gpointer user_data)
gdk_surface_set_widget (GdkSurface *surface,
gpointer widget)
{
g_return_if_fail (GDK_IS_SURFACE (surface));
surface->user_data = user_data;
surface->widget = widget;
}
/**
* gdk_surface_get_user_data:
* @surface: a #GdkSurface
* @data: (out): return location for user data
*
* Retrieves the user data for @surface, which is normally the widget
* that @surface belongs to. See gdk_surface_set_user_data().
*
**/
void
gdk_surface_get_user_data (GdkSurface *surface,
gpointer *data)
gpointer
gdk_surface_get_widget (GdkSurface *surface)
{
*data = surface->user_data;
return surface->widget;
}
/**
@ -1265,49 +1239,6 @@ gdk_surface_peek_children (GdkSurface *surface)
return surface->children;
}
/**
* gdk_surface_get_children_with_user_data:
* @surface: a #GdkSurface
* @user_data: user data to look for
*
* Gets the list of children of @surface known to GDK with a
* particular @user_data set on it.
*
* The returned list must be freed, but the elements in the
* list need not be.
*
* The list is returned in (relative) stacking order, i.e. the
* lowest surface is first.
*
* Returns: (transfer container) (element-type GdkSurface):
* list of child surfaces inside @surface
**/
GList *
gdk_surface_get_children_with_user_data (GdkSurface *surface,
gpointer user_data)
{
GdkSurface *child;
GList *res, *l;
g_return_val_if_fail (GDK_IS_SURFACE (surface), NULL);
if (GDK_SURFACE_DESTROYED (surface))
return NULL;
res = NULL;
for (l = surface->children; l != NULL; l = l->next)
{
child = l->data;
if (child->user_data == user_data)
res = g_list_prepend (res, child);
}
return res;
}
/**
* gdk_surface_is_visible:
* @surface: a #GdkSurface

View File

@ -491,9 +491,6 @@ GDK_AVAILABLE_IN_ALL
void gdk_surface_focus (GdkSurface *surface,
guint32 timestamp);
GDK_AVAILABLE_IN_ALL
void gdk_surface_set_user_data (GdkSurface *surface,
gpointer user_data);
GDK_AVAILABLE_IN_ALL
gboolean gdk_surface_get_accept_focus (GdkSurface *surface);
GDK_AVAILABLE_IN_ALL
void gdk_surface_set_accept_focus (GdkSurface *surface,
@ -595,9 +592,6 @@ GDK_AVAILABLE_IN_ALL
GdkCursor *gdk_surface_get_device_cursor (GdkSurface *surface,
GdkDevice *device);
GDK_AVAILABLE_IN_ALL
void gdk_surface_get_user_data (GdkSurface *surface,
gpointer *data);
GDK_AVAILABLE_IN_ALL
void gdk_surface_get_geometry (GdkSurface *surface,
gint *x,
gint *y,
@ -666,9 +660,6 @@ GDK_AVAILABLE_IN_ALL
GList * gdk_surface_get_children (GdkSurface *surface);
GDK_AVAILABLE_IN_ALL
GList * gdk_surface_peek_children (GdkSurface *surface);
GDK_AVAILABLE_IN_ALL
GList * gdk_surface_get_children_with_user_data (GdkSurface *surface,
gpointer user_data);
GDK_AVAILABLE_IN_ALL
void gdk_surface_set_icon_list (GdkSurface *surface,

View File

@ -29,6 +29,7 @@
#include "gtkimcontextime.h"
#include "gtkimmoduleprivate.h"
#include "gtkroot.h"
#include "imm-extra.h"
@ -878,9 +879,9 @@ gtk_im_context_ime_set_preedit_font (GtkIMContext *context)
if (!context_ime->client_surface)
return;
gdk_surface_get_user_data (context_ime->client_surface, (gpointer) &widget);
if (!GTK_IS_WIDGET (widget))
return;
widget = gtk_root_get_for_surface (context_ime->client_surface);
if (!widget)
return
hwnd = gdk_win32_surface_get_impl_hwnd (context_ime->client_surface);
himc = ImmGetContext (hwnd);

View File

@ -22,6 +22,7 @@
#include "gtkimcontextxim.h"
#include "gtkimmoduleprivate.h"
#include "gtkroot.h"
#include "gtk/gtkintl.h"
@ -1526,32 +1527,16 @@ on_client_widget_hierarchy_changed (GtkWidget *widget,
update_in_toplevel (context_xim);
}
/* Finds the GtkWidget that owns the window, or if none, the
* widget owning the nearest parent that has a widget.
*/
static GtkWidget *
widget_for_window (GdkSurface *window)
{
while (window)
{
gpointer user_data;
gdk_surface_get_user_data (window, &user_data);
if (user_data)
return user_data;
window = gdk_surface_get_parent (window);
}
return NULL;
}
/* Called when context_xim->client_surface changes; takes care of
* removing and/or setting up our watches for the toplevel
*/
static void
update_client_widget (GtkIMContextXIM *context_xim)
{
GtkWidget *new_client_widget = widget_for_window (context_xim->client_surface);
GtkWidget *new_client_widget = NULL;
if (context_xim->client_surface)
new_client_widget = gtk_root_get_for_surface (context_xim->client_surface);
if (new_client_widget != context_xim->client_widget)
{

View File

@ -131,6 +131,7 @@
#include "gtkwindowgroup.h"
#include "gtkprintbackend.h"
#include "gtkimmodule.h"
#include "gtkroot.h"
#include "a11y/gtkaccessibility.h"
@ -1293,7 +1294,6 @@ rewrite_event_for_grabs (GdkEvent *event)
{
GdkSurface *grab_surface;
GtkWidget *event_widget, *grab_widget;
gpointer grab_widget_ptr;
gboolean owner_events;
GdkDisplay *display;
GdkDevice *device;
@ -1326,8 +1326,7 @@ rewrite_event_for_grabs (GdkEvent *event)
}
event_widget = gtk_get_event_widget (event);
gdk_surface_get_user_data (grab_surface, &grab_widget_ptr);
grab_widget = grab_widget_ptr;
grab_widget = gtk_root_get_for_surface (grab_surface);
if (grab_widget &&
gtk_main_get_window_group (grab_widget) != gtk_main_get_window_group (event_widget))
@ -2373,15 +2372,11 @@ GtkWidget*
gtk_get_event_widget (const GdkEvent *event)
{
GtkWidget *widget;
gpointer widget_ptr;
widget = NULL;
if (event && event->any.surface &&
(event->any.type == GDK_DESTROY || !gdk_surface_is_destroyed (event->any.surface)))
{
gdk_surface_get_user_data (event->any.surface, &widget_ptr);
widget = widget_ptr;
}
widget = gtk_root_get_for_surface (event->any.surface);
return widget;
}

View File

@ -20,6 +20,7 @@
#include "config.h"
#include "gtkrootprivate.h"
#include "gdk/gdk-private.h"
/**
* SECTION:root
@ -102,3 +103,24 @@ gtk_root_get_surface_transform (GtkRoot *self,
iface = GTK_ROOT_GET_IFACE (self);
return iface->get_surface_transform (self, x, y);
}
/**
* gtk_root_get_for_surface:
* @surface: a #GdkSurface
*
* Finds the GtkRoot associated with the surface.
*
* Returns: (transfer none): the #GtkRoot that is associated with @surface
*/
GtkWidget *
gtk_root_get_for_surface (GdkSurface *surface)
{
GtkWidget *widget;
widget = (GtkWidget *)gdk_surface_get_widget (surface);
if (widget && GTK_IS_ROOT (widget))
return widget;
return NULL;
}

View File

@ -53,6 +53,8 @@ struct _GtkRootInterface
int *y);
};
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_root_get_for_surface (GdkSurface *surface);
G_END_DECLS

View File

@ -35,6 +35,7 @@
#include "gtkwindowprivate.h"
#include "gtkwidgetprivate.h"
#include "gtkaccessible.h"
#include "gtkroot.h"
#ifdef GDK_WINDOWING_WAYLAND
#include "wayland/gdkwayland.h"
@ -428,7 +429,7 @@ _gtk_widget_find_at_coords (GdkSurface *surface,
g_return_val_if_fail (GDK_IS_SURFACE (surface), NULL);
gdk_surface_get_user_data (surface, (void **)&event_widget);
event_widget = gtk_root_get_for_surface (surface);
if (!event_widget)
return NULL;
@ -499,7 +500,7 @@ gtk_tooltip_set_last_surface (GtkTooltip *tooltip,
(gpointer *) &tooltip->last_surface);
if (surface)
gdk_surface_get_user_data (surface, (gpointer *) &window_widget);
window_widget = gtk_root_get_for_surface (surface);
if (window_widget)
window_widget = gtk_widget_get_toplevel (window_widget);

View File

@ -8598,13 +8598,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 gdk_surface_get_widget (surface) == widget;
}
/*
@ -11446,15 +11443,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 (gdk_surface_get_widget (surface) == NULL);
gdk_surface_set_widget (surface, widget);
g_signal_connect (surface, "render", G_CALLBACK (surface_expose), widget);
g_signal_connect (surface, "event", G_CALLBACK (surface_event), widget);
@ -11473,14 +11466,11 @@ void
gtk_widget_unregister_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 == widget);
gdk_surface_set_user_data (surface, NULL);
g_assert (gdk_surface_get_widget (surface) == widget);
gdk_surface_set_widget (surface, NULL);
g_signal_handlers_disconnect_by_func (surface, surface_expose, widget);
g_signal_handlers_disconnect_by_func (surface, surface_event, widget);

View File

@ -36,6 +36,7 @@
#include "gtkgesturemultipress.h"
#include "gtkeventcontrollermotion.h"
#include "gtkeventcontrollerkey.h"
#include "gtkroot.h"
static GtkWidget *
find_widget_at_pointer (GdkDevice *device)
@ -46,31 +47,7 @@ find_widget_at_pointer (GdkDevice *device)
pointer_surface = gdk_device_get_surface_at_position (device, NULL, NULL);
if (pointer_surface)
{
gpointer widget_ptr;
gdk_surface_get_user_data (pointer_surface, &widget_ptr);
widget = widget_ptr;
if (!GTK_IS_WINDOW (widget))
{
while (TRUE)
{
GdkSurface *parent = gdk_surface_get_parent (pointer_surface);
if (!parent)
break;
pointer_surface = parent;
gdk_surface_get_user_data (pointer_surface, &widget_ptr);
widget = widget_ptr;
if (GTK_IS_WINDOW (widget))
break;
}
}
}
widget = gtk_root_get_for_surface (pointer_surface);
if (widget)
{

View File

@ -184,7 +184,7 @@ window1
action 0 description: Activates the entry
action 0 keybinding: <Alt>e
entry2
"password text"
"text"
parent: box1
index: 4
labelled-by: label2

View File

@ -22,6 +22,7 @@ window1
index: 0
state: editable enabled focusable sensitive showing single-line visible
toolkit: gtk
placeholder-text: Subject or Addresses contain
<AtkComponent>
layer: widget
alpha: 1
@ -63,6 +64,7 @@ window1
index: 1
state: editable enabled focusable sensitive showing single-line visible
toolkit: gtk
placeholder-text: Message contains
<AtkComponent>
layer: widget
alpha: 1
@ -104,6 +106,7 @@ window1
index: 2
state: editable enabled focusable sensitive showing single-line visible
toolkit: gtk
placeholder-text: Body contains
<AtkComponent>
layer: widget
alpha: 1