Clean up embedding api

we now use gdk_offscreen_window_set_embedder() instead of a signal
to get the parent. This also replaces set_has_offscreen_changes.

Rename "parent" in all embedding related names to "embedder" to make it
more obviously different than the normal parent.

Rename gdk_window_get_offscreen_pixmap to gdk_offscreen_window_get_pixmap
to match the other offscreen calls.

Rename gdk_window_offscreen_children_changed to gdk_window_geometry_changed
as this is more descriptive.
This commit is contained in:
Alexander Larsson 2009-07-01 14:36:36 +02:00
parent 681c3c288b
commit 10bf7ca744
7 changed files with 138 additions and 167 deletions

View File

@ -717,16 +717,16 @@ gdk_window_thaw_updates
gdk_window_set_composited
gdk_pointer_grab
gdk_window_beep
gdk_window_set_has_offscreen_children
gdk_window_get_has_offscreen_children
gdk_window_offscreen_children_changed
gdk_window_geometry_changed
gdk_window_ensure_native
#endif
#endif
#if IN_HEADER(__GDK_WINDOW_H__)
#if IN_FILE(__GDK_OFFSCREEN_WINDOW_C__)
gdk_window_get_offscreen_pixmap
gdk_offscreen_window_get_pixmap
gdk_offscreen_window_set_embedder
gdk_offscreen_window_get_embedder
#endif
#endif

View File

@ -1070,27 +1070,13 @@ _gdk_display_pointer_grab_update (GdkDisplay *display,
}
}
static GdkWindow *
gdk_window_get_offscreen_parent (GdkWindow *window)
{
GdkWindowObject *private = (GdkWindowObject *)window;
GdkWindow *res;
res = NULL;
g_signal_emit_by_name (private->impl_window,
"get-offscreen-parent",
&res);
return res;
}
/* Gets the toplevel for a window as used for events,
i.e. including offscreen parents */
static GdkWindowObject *
get_event_parent (GdkWindowObject *window)
{
if (window->window_type ==GDK_WINDOW_OFFSCREEN)
return (GdkWindowObject *)gdk_window_get_offscreen_parent ((GdkWindow *)window);
if (window->window_type == GDK_WINDOW_OFFSCREEN)
return (GdkWindowObject *)gdk_offscreen_window_get_embedder ((GdkWindow *)window);
else
return window->parent;
}

View File

@ -260,8 +260,8 @@ struct _GdkWindowObject
guint effective_visibility : 2;
guint visibility : 2; /* The visibility wrt the toplevel (i.e. based on clip_region) */
guint native_visibility : 2; /* the native visibility of a impl windows */
guint has_offscreen_children : 1;
guint num_offscreen_children;
GdkWindowPaint *implicit_paint;
GdkInputWindow *input_window; /* only set for impl windows */

View File

@ -59,6 +59,7 @@ struct _GdkOffscreenWindow
GdkScreen *screen;
GdkPixmap *pixmap;
GdkWindow *embedder;
};
struct _GdkOffscreenWindowClass
@ -113,6 +114,8 @@ gdk_offscreen_window_destroy (GdkWindow *window,
offscreen = GDK_OFFSCREEN_WINDOW (private->impl);
gdk_offscreen_window_set_embedder (window, NULL);
if (!recursing)
gdk_offscreen_window_hide (window);
@ -685,52 +688,35 @@ gdk_offscreen_window_reparent (GdkWindow *window,
return was_mapped;
}
static GdkWindow *
get_offscreen_parent (GdkWindow *window)
{
GdkWindowObject *private;
GdkWindow *res;
private = (GdkWindowObject *)window;
res = NULL;
g_signal_emit_by_name (private->impl_window,
"get-offscreen-parent",
&res);
return res;
}
static void
from_parent (GdkWindow *window,
double parent_x, double parent_y,
double *offscreen_x, double *offscreen_y)
from_embedder (GdkWindow *window,
double embedder_x, double embedder_y,
double *offscreen_x, double *offscreen_y)
{
GdkWindowObject *private;
private = (GdkWindowObject *)window;
g_signal_emit_by_name (private->impl_window,
"from_parent",
parent_x, parent_y,
"from-embedder",
embedder_x, embedder_y,
offscreen_x, offscreen_y,
NULL);
}
static void
to_parent (GdkWindow *window,
double offscreen_x, double offscreen_y,
double *parent_x, double *parent_y)
to_embedder (GdkWindow *window,
double offscreen_x, double offscreen_y,
double *embedder_x, double *embedder_y)
{
GdkWindowObject *private;
private = (GdkWindowObject *)window;
g_signal_emit_by_name (private->impl_window,
"to_parent",
"to-embedder",
offscreen_x, offscreen_y,
parent_x, parent_y,
embedder_x, embedder_y,
NULL);
}
@ -741,22 +727,23 @@ gdk_offscreen_window_get_root_coords (GdkWindow *window,
gint *root_x,
gint *root_y)
{
GdkWindow *parent;
GdkWindowObject *private = GDK_WINDOW_OBJECT (window);
GdkOffscreenWindow *offscreen;
int tmpx, tmpy;
tmpx = x;
tmpy = y;
parent = get_offscreen_parent (window);
if (parent)
offscreen = GDK_OFFSCREEN_WINDOW (private->impl);
if (offscreen->embedder)
{
double dx, dy;
to_parent (window,
x, y,
&dx, &dy);
to_embedder (window,
x, y,
&dx, &dy);
tmpx = floor (dx + 0.5);
tmpy = floor (dy + 0.5);
gdk_window_get_root_coords (parent,
gdk_window_get_root_coords (offscreen->embedder,
tmpx, tmpy,
&tmpx, &tmpy);
@ -775,22 +762,23 @@ gdk_offscreen_window_get_deskrelative_origin (GdkWindow *window,
gint *x,
gint *y)
{
GdkWindow *parent;
GdkWindowObject *private = GDK_WINDOW_OBJECT (window);
GdkOffscreenWindow *offscreen;
int tmpx, tmpy;
tmpx = 0;
tmpy = 0;
parent = get_offscreen_parent (window);
if (parent)
offscreen = GDK_OFFSCREEN_WINDOW (private->impl);
if (offscreen->embedder)
{
double dx, dy;
gdk_window_get_deskrelative_origin (parent,
gdk_window_get_deskrelative_origin (offscreen->embedder,
&tmpx, &tmpy);
to_parent (window,
0, 0,
&dx, &dy);
to_embedder (window,
0, 0,
&dx, &dy);
tmpx = floor (tmpx + dx + 0.5);
tmpy = floor (tmpy + dy + 0.5);
}
@ -810,22 +798,23 @@ gdk_offscreen_window_get_pointer (GdkWindow *window,
gint *y,
GdkModifierType *mask)
{
GdkWindowObject *private = GDK_WINDOW_OBJECT (window);
GdkOffscreenWindow *offscreen;
int tmpx, tmpy;
double dtmpx, dtmpy;
GdkModifierType tmpmask;
GdkWindow *parent;
tmpx = 0;
tmpy = 0;
tmpmask = 0;
parent = get_offscreen_parent (window);
if (parent != NULL)
offscreen = GDK_OFFSCREEN_WINDOW (private->impl);
if (offscreen->embedder != NULL)
{
gdk_window_get_pointer (parent, &tmpx, &tmpy, &tmpmask);
from_parent (window,
tmpx, tmpy,
&dtmpx, &dtmpy);
gdk_window_get_pointer (offscreen->embedder, &tmpx, &tmpy, &tmpmask);
from_embedder (window,
tmpx, tmpy,
&dtmpx, &dtmpy);
tmpx = floor (dtmpx + 0.5);
tmpy = floor (dtmpy + 0.5);
}
@ -840,7 +829,7 @@ gdk_offscreen_window_get_pointer (GdkWindow *window,
}
/**
* gdk_window_get_offscreen_pixmap:
* gdk_offscreen_window_get_pixmap:
* @window: a #GdkWindow
*
* Gets the offscreen pixmap that an offscreen window renders into. If
@ -850,7 +839,7 @@ gdk_offscreen_window_get_pointer (GdkWindow *window,
* Returns: The offscreen pixmap, or NULL if not offscreen
**/
GdkPixmap *
gdk_window_get_offscreen_pixmap (GdkWindow *window)
gdk_offscreen_window_get_pixmap (GdkWindow *window)
{
GdkWindowObject *private = (GdkWindowObject *)window;
GdkOffscreenWindow *offscreen;
@ -970,7 +959,8 @@ gdk_offscreen_window_move_resize (GdkWindow *window,
}
static void
gdk_offscreen_window_show (GdkWindow *window)
gdk_offscreen_window_show (GdkWindow *window,
gboolean already_mapped)
{
GdkWindowObject *private = (GdkWindowObject *)window;
@ -1165,6 +1155,50 @@ gdk_offscreen_window_queue_translation (GdkWindow *window,
{
}
void
gdk_offscreen_window_set_embedder (GdkWindow *window,
GdkWindow *embedder)
{
GdkWindowObject *private = (GdkWindowObject *)window;
GdkOffscreenWindow *offscreen;
g_return_if_fail (GDK_IS_WINDOW (window));
if (!GDK_IS_OFFSCREEN_WINDOW (private->impl))
return;
offscreen = GDK_OFFSCREEN_WINDOW (private->impl);
if (embedder)
{
g_object_ref (embedder);
GDK_WINDOW_OBJECT (embedder)->num_offscreen_children++;
}
if (offscreen->embedder)
{
g_object_unref (offscreen->embedder);
GDK_WINDOW_OBJECT (offscreen->embedder)->num_offscreen_children--;
}
offscreen->embedder = embedder;
}
GdkWindow *
gdk_offscreen_window_get_embedder (GdkWindow *window)
{
GdkWindowObject *private = (GdkWindowObject *)window;
GdkOffscreenWindow *offscreen;
g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
if (!GDK_IS_OFFSCREEN_WINDOW (private->impl))
return NULL;
offscreen = GDK_OFFSCREEN_WINDOW (private->impl);
return offscreen->embedder;
}
static void
gdk_offscreen_window_class_init (GdkOffscreenWindowClass *klass)

View File

@ -122,10 +122,9 @@
#define GDK_VISIBILITY_NOT_VIEWABLE 3
enum {
GET_OFFSCREEN_PARENT,
PICK_OFFSCREEN_CHILD, /* only called if has_offscreen_children */
TO_PARENT,
FROM_PARENT,
PICK_EMBEDDED_CHILD, /* only called if children are embedded */
TO_EMBEDDER,
FROM_EMBEDDER,
LAST_SIGNAL
};
@ -312,7 +311,6 @@ static void do_move_region_bits_on_impl (GdkWindowObject *private,
GdkRegion *region, /* In impl window coords */
int dx, int dy);
static void gdk_window_invalidate_in_parent (GdkWindowObject *private);
static GdkWindow *gdk_window_get_offscreen_parent (GdkWindow *window);
static void move_native_children (GdkWindowObject *private);
static void update_cursor (GdkDisplay *display);
static gboolean is_event_parent_of (GdkWindow *parent,
@ -448,17 +446,8 @@ gdk_window_class_init (GdkWindowObjectClass *klass)
quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
signals[GET_OFFSCREEN_PARENT] =
g_signal_new (g_intern_static_string ("get-offscreen-parent"),
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
0,
accumulate_get_window, NULL,
gdk_marshal_OBJECT__VOID,
GDK_TYPE_WINDOW,
0);
signals[PICK_OFFSCREEN_CHILD] =
g_signal_new (g_intern_static_string ("pick-offscreen-child"),
signals[PICK_EMBEDDED_CHILD] =
g_signal_new (g_intern_static_string ("pick-embedded-child"),
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
0,
@ -468,8 +457,8 @@ gdk_window_class_init (GdkWindowObjectClass *klass)
2,
G_TYPE_DOUBLE,
G_TYPE_DOUBLE);
signals[TO_PARENT] =
g_signal_new (g_intern_static_string ("to-parent"),
signals[TO_EMBEDDER] =
g_signal_new (g_intern_static_string ("to-embedder"),
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
0,
@ -481,8 +470,8 @@ gdk_window_class_init (GdkWindowObjectClass *klass)
G_TYPE_DOUBLE,
G_TYPE_POINTER,
G_TYPE_POINTER);
signals[FROM_PARENT] =
g_signal_new (g_intern_static_string ("from-parent"),
signals[FROM_EMBEDDER] =
g_signal_new (g_intern_static_string ("from-embedder"),
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
0,
@ -7854,8 +7843,8 @@ gdk_window_redirect_free (GdkWindowRedirect *redirect)
static GdkWindowObject *
get_event_parent (GdkWindowObject *window)
{
if (window->window_type ==GDK_WINDOW_OFFSCREEN)
return (GdkWindowObject *)gdk_window_get_offscreen_parent ((GdkWindow *)window);
if (window->window_type == GDK_WINDOW_OFFSCREEN)
return (GdkWindowObject *)gdk_offscreen_window_get_embedder ((GdkWindow *)window);
else
return window->parent;
}
@ -7923,13 +7912,13 @@ update_cursor (GdkDisplay *display)
}
static void
from_parent (GdkWindowObject *window,
double parent_x, double parent_y,
double *offscreen_x, double *offscreen_y)
from_embedder (GdkWindowObject *window,
double embedder_x, double embedder_y,
double *offscreen_x, double *offscreen_y)
{
g_signal_emit (window,
signals[FROM_PARENT], 0,
parent_x, parent_y,
signals[FROM_EMBEDDER], 0,
embedder_x, embedder_y,
offscreen_x, offscreen_y,
NULL);
}
@ -7941,8 +7930,8 @@ convert_coords_to_child (GdkWindowObject *child,
{
if (gdk_window_is_offscreen (child))
{
from_parent (child, x, y,
child_x, child_y);
from_embedder (child, x, y,
child_x, child_y);
}
else
{
@ -8026,14 +8015,14 @@ convert_toplevel_coords_to_window (GdkWindow *window,
}
static GdkWindowObject *
pick_offscreen_child (GdkWindowObject *window,
pick_embedded_child (GdkWindowObject *window,
double x, double y)
{
GdkWindowObject *res;
res = NULL;
g_signal_emit (window,
signals[PICK_OFFSCREEN_CHILD], 0,
signals[PICK_EMBEDDED_CHILD], 0,
x, y, &res);
return res;
@ -8066,10 +8055,10 @@ _gdk_window_find_child_at (GdkWindow *window,
return (GdkWindow *)sub;
}
if (private->has_offscreen_children)
if (private->num_offscreen_children > 0)
{
sub = pick_offscreen_child (private,
x, y);
sub = pick_embedded_child (private,
x, y);
if (sub)
return (GdkWindow *)sub;
}
@ -8117,15 +8106,15 @@ _gdk_window_find_descendant_at (GdkWindow *toplevel,
}
}
if (!found &&
private->has_offscreen_children)
private->num_offscreen_children > 0)
{
sub = pick_offscreen_child (private,
x, y);
sub = pick_embedded_child (private,
x, y);
if (sub)
{
found = TRUE;
private = sub;
from_parent (sub, x, y, &x, &y);
from_embedder (sub, x, y, &x, &y);
}
}
}
@ -8648,20 +8637,6 @@ _gdk_display_set_window_under_pointer (GdkDisplay *display,
_gdk_display_enable_motion_hints (display);
}
static GdkWindow *
gdk_window_get_offscreen_parent (GdkWindow *window)
{
GdkWindowObject *private = (GdkWindowObject *)window;
GdkWindow *res;
res = NULL;
g_signal_emit (private->impl_window,
signals[GET_OFFSCREEN_PARENT], 0,
&res);
return res;
}
/*
*--------------------------------------------------------------
* gdk_pointer_grab
@ -8719,7 +8694,7 @@ gdk_pointer_grab (GdkWindow * window,
native = gdk_window_get_toplevel (window);
while (gdk_window_is_offscreen ((GdkWindowObject *)native))
{
native = gdk_window_get_offscreen_parent (native);
native = gdk_offscreen_window_get_embedder (native);
if (native == NULL ||
(!_gdk_window_has_impl (native) &&
@ -8755,24 +8730,7 @@ gdk_pointer_grab (GdkWindow * window,
}
void
gdk_window_set_has_offscreen_children (GdkWindow *window,
gboolean has_offscreen_children)
{
GdkWindowObject *private = (GdkWindowObject *)window;
private->has_offscreen_children = !!has_offscreen_children;
}
gboolean
gdk_window_get_has_offscreen_children (GdkWindow *window)
{
GdkWindowObject *private = (GdkWindowObject *)window;
return private->has_offscreen_children;
}
void
gdk_window_offscreen_children_changed (GdkWindow *window)
gdk_window_geometry_changed (GdkWindow *window)
{
_gdk_synthesize_crossing_events_for_geometry_change (window);
}

View File

@ -660,11 +660,11 @@ GdkPointerHooks *gdk_set_pointer_hooks (const GdkPointerHooks *new_hooks);
GdkWindow *gdk_get_default_root_window (void);
/* Offscreen redirection */
GdkPixmap *gdk_window_get_offscreen_pixmap (GdkWindow *window);
void gdk_window_set_has_offscreen_children (GdkWindow *window,
gboolean has_offscreen_children);
gboolean gdk_window_get_has_offscreen_children (GdkWindow *window);
void gdk_window_offscreen_children_changed (GdkWindow *window);
GdkPixmap *gdk_offscreen_window_get_pixmap (GdkWindow *window);
void gdk_offscreen_window_set_embedder (GdkWindow *window,
GdkWindow *embedder);
GdkWindow *gdk_offscreen_window_get_embedder (GdkWindow *window);
void gdk_window_geometry_changed (GdkWindow *window);
void gdk_window_redirect_to_drawable (GdkWindow *window,
GdkDrawable *drawable,

View File

@ -140,13 +140,6 @@ gtk_offscreen_box_new (void)
return g_object_new (GTK_TYPE_OFFSCREEN_BOX, NULL);
}
static GdkWindow *
get_offscreen_parent (GdkWindow *offscreen_window,
GtkOffscreenBox *offscreen_box)
{
return GTK_WIDGET (offscreen_box)->window;
}
static GdkWindow *
pick_offscreen_child (GdkWindow *offscreen_window,
double widget_x, double widget_y,
@ -273,8 +266,7 @@ gtk_offscreen_box_realize (GtkWidget *widget)
&attributes, attributes_mask);
gdk_window_set_user_data (widget->window, widget);
gdk_window_set_has_offscreen_children (widget->window, TRUE);
g_signal_connect (widget->window, "pick-offscreen-child",
g_signal_connect (widget->window, "pick-embedded-child",
G_CALLBACK (pick_offscreen_child), offscreen_box);
attributes.window_type = GDK_WINDOW_OFFSCREEN;
@ -293,11 +285,12 @@ gtk_offscreen_box_realize (GtkWidget *widget)
if (offscreen_box->child1)
gtk_widget_set_parent_window (offscreen_box->child1, offscreen_box->offscreen_window1);
g_signal_connect (offscreen_box->offscreen_window1, "get-offscreen-parent",
G_CALLBACK (get_offscreen_parent), offscreen_box);
g_signal_connect (offscreen_box->offscreen_window1, "to_parent",
gdk_offscreen_window_set_embedder (offscreen_box->offscreen_window1,
widget->window);
g_signal_connect (offscreen_box->offscreen_window1, "to-embedder",
G_CALLBACK (offscreen_window_to_parent1), offscreen_box);
g_signal_connect (offscreen_box->offscreen_window1, "from_parent",
g_signal_connect (offscreen_box->offscreen_window1, "from-embedder",
G_CALLBACK (offscreen_window_from_parent1), offscreen_box);
/* Child 2 */
@ -313,11 +306,11 @@ gtk_offscreen_box_realize (GtkWidget *widget)
gdk_window_set_user_data (offscreen_box->offscreen_window2, widget);
if (offscreen_box->child2)
gtk_widget_set_parent_window (offscreen_box->child2, offscreen_box->offscreen_window2);
g_signal_connect (offscreen_box->offscreen_window2, "get-offscreen-parent",
G_CALLBACK (get_offscreen_parent), offscreen_box);
g_signal_connect (offscreen_box->offscreen_window2, "to_parent",
gdk_offscreen_window_set_embedder (offscreen_box->offscreen_window2,
widget->window);
g_signal_connect (offscreen_box->offscreen_window2, "to-embedder",
G_CALLBACK (offscreen_window_to_parent2), offscreen_box);
g_signal_connect (offscreen_box->offscreen_window2, "from_parent",
g_signal_connect (offscreen_box->offscreen_window2, "from-embedder",
G_CALLBACK (offscreen_window_from_parent2), offscreen_box);
widget->style = gtk_style_attach (widget->style, widget->window);
@ -590,7 +583,7 @@ gtk_offscreen_box_expose (GtkWidget *widget,
if (offscreen_box->child1 && GTK_WIDGET_VISIBLE (offscreen_box->child1))
{
pixmap = gdk_window_get_offscreen_pixmap (offscreen_box->offscreen_window1);
pixmap = gdk_offscreen_window_get_pixmap (offscreen_box->offscreen_window1);
child_area = offscreen_box->child1->allocation;
cr = gdk_cairo_create (widget->window);
@ -607,7 +600,7 @@ gtk_offscreen_box_expose (GtkWidget *widget,
{
gint w, h;
pixmap = gdk_window_get_offscreen_pixmap (offscreen_box->offscreen_window2);
pixmap = gdk_offscreen_window_get_pixmap (offscreen_box->offscreen_window2);
child_area = offscreen_box->child2->allocation;
cr = gdk_cairo_create (widget->window);