mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-26 13:41:07 +00:00
Add gdk_window_get_root_coords
We want to be able to map any window coordinate to a root coordinate, not just the origin, because you can't rely anymore on a simple translation from window coordinates to parent with offscreen windows. This lets us e.g. pop up menus in the right place even if they are popped up from a no-window widget.
This commit is contained in:
parent
a8549898ab
commit
4d54de336b
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 () */
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user