diff --git a/gdk/gdkoffscreenwindow.c b/gdk/gdkoffscreenwindow.c index 5289d71e92..6e92f625cf 100644 --- a/gdk/gdkoffscreenwindow.c +++ b/gdk/gdkoffscreenwindow.c @@ -735,35 +735,37 @@ to_parent (GdkWindow *window, } static gint -gdk_offscreen_window_get_origin (GdkWindow *window, - gint *x, - gint *y) +gdk_offscreen_window_get_root_coords (GdkWindow *window, + gint x, + gint y, + gint *root_x, + gint *root_y) { GdkWindow *parent; int tmpx, tmpy; - tmpx = 0; - tmpy = 0; + tmpx = x; + tmpy = y; parent = get_offscreen_parent (window); if (parent) { double dx, dy; - gdk_window_get_origin (parent, - &tmpx, &tmpy); - to_parent (window, - 0, 0, + x, y, &dx, &dy); - tmpx = floor (tmpx + dx + 0.5); - tmpy = floor (tmpy + dy + 0.5); + tmpx = floor (dx + 0.5); + tmpy = floor (dy + 0.5); + gdk_window_get_root_coords (parent, + tmpx, tmpy, + &tmpx, &tmpy); + } - - if (x) - *x = tmpx; - if (y) - *y = tmpy; + if (root_x) + *root_x = tmpx; + if (root_y) + *root_y = tmpy; return TRUE; } @@ -1217,7 +1219,7 @@ gdk_offscreen_window_impl_iface_init (GdkWindowImplIface *iface) iface->set_static_gravities = gdk_offscreen_window_set_static_gravities; iface->queue_antiexpose = gdk_offscreen_window_queue_antiexpose; iface->queue_translation = gdk_offscreen_window_queue_translation; - iface->get_origin = gdk_offscreen_window_get_origin; + iface->get_root_coords = gdk_offscreen_window_get_root_coords; iface->get_deskrelative_origin = gdk_offscreen_window_get_deskrelative_origin; iface->get_pointer = gdk_offscreen_window_get_pointer; iface->destroy = gdk_offscreen_window_destroy; diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c index c8714d2b05..ca042e6f40 100644 --- a/gdk/gdkwindow.c +++ b/gdk/gdkwindow.c @@ -6952,12 +6952,46 @@ gdk_window_get_origin (GdkWindow *window, private = (GdkWindowObject *) window; - GDK_WINDOW_IMPL_GET_IFACE (private->impl)->get_origin (window, x, y); + GDK_WINDOW_IMPL_GET_IFACE (private->impl)->get_root_coords (window, + private->abs_x, + private->abs_y, + x, y); - if (x) - *x += private->abs_x; - if (y) - *y += private->abs_y; + return TRUE; +} + +/** + * gdk_window_get_root_coords: + * @window: a #GdkWindow + * @x: X coordinate in window + * @y: Y coordinate in window + * @root_x: return location for X coordinate + * @root_y: return location for Y coordinate + * + * Obtains the position of a window position in root + * window coordinates. This is similar to + * gdk_window_get_origin() but allows you go pass + * in any position in the window, not just the origin. + * + * Return value: not meaningful, ignore + */ +gint +gdk_window_get_root_coords (GdkWindow *window, + gint x, + gint y, + gint *root_x, + gint *root_y) +{ + GdkWindowObject *private; + + g_return_val_if_fail (GDK_IS_WINDOW (window), 0); + + private = (GdkWindowObject *) window; + + GDK_WINDOW_IMPL_GET_IFACE (private->impl)->get_root_coords (window, + x + private->abs_x, + y + private->abs_y, + root_x, root_y); return TRUE; } diff --git a/gdk/gdkwindow.h b/gdk/gdkwindow.h index 5fefc9233f..7885b1bf1a 100644 --- a/gdk/gdkwindow.h +++ b/gdk/gdkwindow.h @@ -531,6 +531,11 @@ void gdk_window_get_position (GdkWindow *window, gint gdk_window_get_origin (GdkWindow *window, gint *x, gint *y); +gint gdk_window_get_root_coords (GdkWindow *window, + gint x, + gint y, + gint *root_x, + gint *root_y); #if !defined (GDK_DISABLE_DEPRECATED) || defined (GTK_COMPILATION) /* Used by gtk_handle_box_button_changed () */ diff --git a/gdk/gdkwindowimpl.h b/gdk/gdkwindowimpl.h index 7babfea9c1..db1c2ac96f 100644 --- a/gdk/gdkwindowimpl.h +++ b/gdk/gdkwindowimpl.h @@ -80,9 +80,11 @@ struct _GdkWindowImplIface gint *width, gint *height, gint *depth); - gint (* get_origin) (GdkWindow *window, - gint *x, - gint *y); + gint (* get_root_coords) (GdkWindow *window, + gint x, + gint y, + gint *root_x, + gint *root_y); gint (* get_deskrelative_origin) (GdkWindow *window, gint *x, gint *y); diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c index 95138439ed..2d57c761e7 100644 --- a/gdk/x11/gdkwindow-x11.c +++ b/gdk/x11/gdkwindow-x11.c @@ -2759,9 +2759,11 @@ gdk_window_x11_get_geometry (GdkWindow *window, } static gint -gdk_window_x11_get_origin (GdkWindow *window, - gint *x, - gint *y) +gdk_window_x11_get_root_coords (GdkWindow *window, + gint x, + gint y, + gint *root_x, + gint *root_y) { gint return_val; Window child; @@ -2773,16 +2775,16 @@ gdk_window_x11_get_origin (GdkWindow *window, return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window), GDK_WINDOW_XROOTWIN (window), - 0, 0, &tx, &ty, + x, y, &tx, &ty, &child); } else return_val = 0; - if (x) - *x = tx; - if (y) - *y = ty; + if (root_x) + *root_x = tx; + if (root_y) + *root_y = ty; return return_val; } @@ -5575,7 +5577,7 @@ gdk_window_impl_iface_init (GdkWindowImplIface *iface) iface->reparent = gdk_window_x11_reparent; iface->set_cursor = gdk_window_x11_set_cursor; iface->get_geometry = gdk_window_x11_get_geometry; - iface->get_origin = gdk_window_x11_get_origin; + iface->get_root_coords = gdk_window_x11_get_root_coords; iface->get_pointer = gdk_window_x11_get_pointer; iface->get_deskrelative_origin = gdk_window_x11_get_deskrelative_origin; iface->shape_combine_region = gdk_window_x11_shape_combine_region;