diff options
author | Jonas Ã…dahl <jadahl@gmail.com> | 2016-08-04 13:56:15 +0800 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2016-08-18 04:51:57 -0400 |
commit | f6929cfef81171f1b59a3950e88e2ce5599d3286 (patch) | |
tree | 6d863fe01cc5cd9d01e68920afaf8efa6b5cfb61 /gdk/gdkwindowimpl.c | |
parent | 4e0ebd0cdf5eefcb19f35aa85e1d84c0ef1f2a7d (diff) | |
download | gtk+-f6929cfef81171f1b59a3950e88e2ce5599d3286.tar.gz |
gdkwindow: Use toplevel for getting root cords in move_to_rect()
The Wayland backend manages a set of fake root coordinate spaces, where
each non-relative positioned toplevel (i.e. not popups, popovers,
tooltips etc) make up the basis of separate fake root coordinate spaces.
This means that the Wayland backend doesn't have the abilitiy get a
proper root coordinate when querying on a non-toplevel GdkWindow. To
avoid this issue, first find the toplevel, while translating the anchor
rect coordinates so that they are in the toplevel window coordinate
space. Then use this toplevel to translate the coordinates to root
window coordinate space.
https://bugzilla.gnome.org/show_bug.cgi?id=769402
Diffstat (limited to 'gdk/gdkwindowimpl.c')
-rw-r--r-- | gdk/gdkwindowimpl.c | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/gdk/gdkwindowimpl.c b/gdk/gdkwindowimpl.c index 11e49d5bc7..c42c5aa218 100644 --- a/gdk/gdkwindowimpl.c +++ b/gdk/gdkwindowimpl.c @@ -173,6 +173,29 @@ maybe_flip_position (gint bounds_pos, return primary; } +static GdkWindow * +traverse_to_toplevel (GdkWindow *window, + gint x, + gint y, + gint *toplevel_x, + gint *toplevel_y) +{ + GdkWindow *parent; + gdouble xf = x; + gdouble yf = y; + + while ((parent = gdk_window_get_effective_parent (window)) != NULL && + (gdk_window_get_window_type (parent) != GDK_WINDOW_ROOT)) + { + gdk_window_coords_to_parent (window, xf, yf, &xf, &yf); + window = parent; + } + + *toplevel_x = (gint) xf; + *toplevel_y = (gint) yf; + return window; +} + static void gdk_window_impl_move_to_rect (GdkWindow *window, const GdkRectangle *rect, @@ -182,6 +205,7 @@ gdk_window_impl_move_to_rect (GdkWindow *window, gint rect_anchor_dx, gint rect_anchor_dy) { + GdkWindow *transient_for_toplevel; GdkDisplay *display; GdkMonitor *monitor; GdkRectangle bounds; @@ -191,7 +215,18 @@ gdk_window_impl_move_to_rect (GdkWindow *window, gboolean flipped_x; gboolean flipped_y; - gdk_window_get_root_coords (window->transient_for, + /* + * First translate the anchor rect to toplevel coordinates. This is needed + * because not all backends will be able to get root coordinates for + * non-toplevel windows. + */ + transient_for_toplevel = traverse_to_toplevel (window->transient_for, + root_rect.x, + root_rect.y, + &root_rect.x, + &root_rect.y); + + gdk_window_get_root_coords (transient_for_toplevel, root_rect.x, root_rect.y, &root_rect.x, |