diff --git a/src/compositor/meta-surface-actor-wayland.c b/src/compositor/meta-surface-actor-wayland.c index 2786a5ab6..7c354d64a 100644 --- a/src/compositor/meta-surface-actor-wayland.c +++ b/src/compositor/meta-surface-actor-wayland.c @@ -31,6 +31,7 @@ #include "meta-shaped-texture-private.h" #include "wayland/meta-wayland-private.h" +#include "wayland/meta-window-wayland.h" #include "compositor/region-utils.h" @@ -81,52 +82,22 @@ meta_surface_actor_wayland_is_unredirected (MetaSurfaceActor *actor) return FALSE; } -static int -get_output_scale (int winsys_id) -{ - MetaMonitorManager *monitor_manager = meta_monitor_manager_get (); - MetaOutput *outputs; - guint n_outputs, i; - int output_scale = 1; - - outputs = meta_monitor_manager_get_outputs (monitor_manager, &n_outputs); - - for (i = 0; i < n_outputs; i++) - { - if (outputs[i].winsys_id == winsys_id) - { - output_scale = outputs[i].scale; - break; - } - } - - return output_scale; -} - double meta_surface_actor_wayland_get_scale (MetaSurfaceActorWayland *actor) { MetaSurfaceActorWaylandPrivate *priv = meta_surface_actor_wayland_get_instance_private (actor); MetaWaylandSurface *surface = priv->surface; - MetaWindow *window = NULL; + MetaWindow *window; int output_scale = 1; if (!surface) return 1; - while (surface) - { - if (surface->window) - { - window = surface->window; - break; - } - surface = surface->sub.parent; - } + window = meta_wayland_surface_get_toplevel_window (surface); /* XXX: We do not handle x11 clients yet */ if (window && window->client_type != META_WINDOW_CLIENT_TYPE_X11) - output_scale = get_output_scale (window->monitor->winsys_id); + output_scale = meta_window_wayland_get_main_monitor_scale (window); return (double)output_scale / (double)priv->surface->scale; } diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c index 2817ba6a7..8f0ae9504 100644 --- a/src/wayland/meta-wayland-surface.c +++ b/src/wayland/meta-wayland-surface.c @@ -2229,3 +2229,17 @@ meta_wayland_surface_drag_dest_drop (MetaWaylandSurface *surface) surface->dnd.funcs->drop (data_device, surface); } + +MetaWindow * +meta_wayland_surface_get_toplevel_window (MetaWaylandSurface *surface) +{ + while (surface) + { + if (surface->window) + return surface->window; + + surface = surface->sub.parent; + } + + return NULL; +} diff --git a/src/wayland/meta-wayland-surface.h b/src/wayland/meta-wayland-surface.h index e29cf930b..a1d4c7eab 100644 --- a/src/wayland/meta-wayland-surface.h +++ b/src/wayland/meta-wayland-surface.h @@ -190,4 +190,6 @@ void meta_wayland_surface_drag_dest_drop (MetaWaylandSurface void meta_wayland_surface_update_outputs (MetaWaylandSurface *surface); +MetaWindow * meta_wayland_surface_get_toplevel_window (MetaWaylandSurface *surface); + #endif diff --git a/src/wayland/meta-window-wayland.c b/src/wayland/meta-window-wayland.c index 8c6ca581f..248cb92db 100644 --- a/src/wayland/meta-window-wayland.c +++ b/src/wayland/meta-window-wayland.c @@ -412,6 +412,28 @@ should_do_pending_move (MetaWindowWayland *wl_window, return TRUE; } +int +meta_window_wayland_get_main_monitor_scale (MetaWindow *window) +{ + MetaMonitorManager *monitor_manager = meta_monitor_manager_get (); + MetaOutput *outputs; + guint n_outputs, i; + int output_scale = 1; + + outputs = meta_monitor_manager_get_outputs (monitor_manager, &n_outputs); + + for (i = 0; i < n_outputs; i++) + { + if (outputs[i].winsys_id == window->monitor->winsys_id) + { + output_scale = outputs[i].scale; + break; + } + } + + return output_scale; +} + /** * meta_window_move_resize_wayland: * diff --git a/src/wayland/meta-window-wayland.h b/src/wayland/meta-window-wayland.h index eb2e8deb5..c57b45da6 100644 --- a/src/wayland/meta-window-wayland.h +++ b/src/wayland/meta-window-wayland.h @@ -50,5 +50,6 @@ void meta_window_wayland_move_resize (MetaWindow *window, MetaRectangle new_geom, int dx, int dy); +int meta_window_wayland_get_main_monitor_scale (MetaWindow *window); #endif