From db6caa2c49e2c846f912f2f6d75036feee7e751b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 25 Mar 2015 14:39:30 +0800 Subject: [PATCH] wayland: Take scale into account when placing windows relatively When placing a popup and the legacy transient wl_shell_surface surfaces, take the current scale of the window into account. This commit doesn't fix relative positioning in case a window scale would change, but since the use case for relative positioning is mostly popups, which would be dismissed before the parent window would be moved, it should not be that much of a problem. https://bugzilla.gnome.org/show_bug.cgi?id=744934 --- src/wayland/meta-wayland-surface.c | 19 +++++++------------ src/wayland/meta-window-wayland.c | 21 +++++++++++++++++++++ src/wayland/meta-window-wayland.h | 5 +++++ 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c index 51bcf3817..e352e07ce 100644 --- a/src/wayland/meta-wayland-surface.c +++ b/src/wayland/meta-wayland-surface.c @@ -1401,11 +1401,8 @@ xdg_shell_get_xdg_popup (struct wl_client *client, &surface->popup.parent_destroy_listener); window = meta_window_wayland_new (display, surface); - meta_window_move_frame (window, FALSE, - parent_surf->window->buffer_rect.x + x, - parent_surf->window->buffer_rect.y + y); + meta_window_wayland_place_relative_to (window, parent_surf->window, x, y); window->showing_for_first_time = FALSE; - window->placed = TRUE; meta_wayland_surface_set_window (surface, window); @@ -1569,10 +1566,9 @@ wl_shell_surface_set_transient (struct wl_client *client, wl_shell_surface_set_state (surface, SURFACE_STATE_TOPLEVEL); meta_window_set_transient_for (surface->window, parent_surf->window); - meta_window_move_frame (surface->window, FALSE, - parent_surf->window->rect.x + x, - parent_surf->window->rect.y + y); - surface->window->placed = TRUE; + meta_window_wayland_place_relative_to (surface->window, + parent_surf->window, + x, y); } static void @@ -1621,10 +1617,9 @@ wl_shell_surface_set_popup (struct wl_client *client, } meta_window_set_transient_for (surface->window, parent_surf->window); - meta_window_move_frame (surface->window, FALSE, - parent_surf->window->rect.x + x, - parent_surf->window->rect.y + y); - surface->window->placed = TRUE; + meta_window_wayland_place_relative_to (surface->window, + parent_surf->window, + x, y); if (!surface->popup.parent) { diff --git a/src/wayland/meta-window-wayland.c b/src/wayland/meta-window-wayland.c index 10a006d52..e3323419d 100644 --- a/src/wayland/meta-window-wayland.c +++ b/src/wayland/meta-window-wayland.c @@ -595,3 +595,24 @@ meta_window_wayland_move_resize (MetaWindow *window, gravity = meta_resize_gravity_from_grab_op (window->display->grab_op); meta_window_move_resize_internal (window, flags, gravity, rect); } + +void +meta_window_wayland_place_relative_to (MetaWindow *window, + MetaWindow *other, + int x, + int y) +{ + int monitor_scale; + + /* If there is no monitor, we can't position the window reliably. */ + if (!other->monitor) + return; + + /* Scale the relative coordinate (x, y) from logical pixels to physical + * pixels. */ + monitor_scale = other->monitor->scale; + meta_window_move_frame (window, FALSE, + other->buffer_rect.x + (x * monitor_scale), + other->buffer_rect.y + (y * monitor_scale)); + window->placed = TRUE; +} diff --git a/src/wayland/meta-window-wayland.h b/src/wayland/meta-window-wayland.h index c57b45da6..9287db8de 100644 --- a/src/wayland/meta-window-wayland.h +++ b/src/wayland/meta-window-wayland.h @@ -52,4 +52,9 @@ void meta_window_wayland_move_resize (MetaWindow *window, int dy); int meta_window_wayland_get_main_monitor_scale (MetaWindow *window); +void meta_window_wayland_place_relative_to (MetaWindow *window, + MetaWindow *other, + int x, + int y); + #endif