surface: Add coordinate translation

We maintain offsets for popups, so we can translate
coordinates between surfaces that are attached directly
or indirectly to the same toplevel. Add an api for that.
This commit is contained in:
Matthias Clasen 2019-05-28 23:41:56 -04:00
parent 5675d585f4
commit 902a49af9d
2 changed files with 44 additions and 0 deletions

View File

@ -4076,3 +4076,41 @@ gdk_surface_handle_event (GdkEvent *event)
return handled;
}
gboolean
gdk_surface_translate_coordinates (GdkSurface *from,
GdkSurface *to,
double *x,
double *y)
{
int x1, y1, x2, y2;
GdkSurface *f, *t;
x1 = 0;
y1 = 0;
f = from;
while (f->parent)
{
x1 += f->x;
y1 += f->y;
f = f->parent;
}
x2 = 0;
y2 = 0;
t = to;
while (t->parent)
{
x2 += t->x;
y2 += t->y;
t = t->parent;
}
if (f != t)
return FALSE;
*x += x1 - x2;
*y += y1 - y2;
return TRUE;
}

View File

@ -557,6 +557,12 @@ gint gdk_surface_get_origin (GdkSurface *surface,
gint *x,
gint *y);
GDK_AVAILABLE_IN_ALL
gboolean gdk_surface_translate_coordinates (GdkSurface *from,
GdkSurface *to,
double *x,
double *y);
GDK_AVAILABLE_IN_ALL
void gdk_surface_get_frame_extents (GdkSurface *surface,
GdkRectangle *rect);