From 3183f86aea4e3c1005995cfd928b7d42c16ff39f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Fri, 23 Sep 2016 14:01:34 +0800 Subject: [PATCH] wayland/xdg-shell: Scale positioner coordinates When the monitor is scaled (i.e. HiDPI scaling) the placement coordinates are still in unscaled xdg_surface window geometry coordinate space. Fix this by simply scaling the coordinates by the monitor scale of the parent toplevel window. This is inherently racy, but since we won't move the toplevel window before the popup is placed, and we won't move the window without unmapping the popup, there is little point in introducing more complex adaptive scaling, especially when the end goal is to get rid of all these types of scaling hacks. https://bugzilla.gnome.org/show_bug.cgi?id=771841 --- src/wayland/meta-wayland-xdg-shell.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/wayland/meta-wayland-xdg-shell.c b/src/wayland/meta-wayland-xdg-shell.c index e9223a9..84bf40d 100644 --- a/src/wayland/meta-wayland-xdg-shell.c +++ b/src/wayland/meta-wayland-xdg-shell.c @@ -126,7 +126,8 @@ G_DEFINE_TYPE_WITH_CODE (MetaWaylandXdgPopup, popup_surface_iface_init)); static MetaPlacementRule -meta_wayland_xdg_positioner_to_placement (MetaWaylandXdgPositioner *xdg_positioner); +meta_wayland_xdg_positioner_to_placement (MetaWaylandXdgPositioner *xdg_positioner, + MetaWaylandSurface *parent_surface); static struct wl_resource * meta_wayland_xdg_surface_get_shell_resource (MetaWaylandXdgSurface *xdg_surface); @@ -1511,7 +1512,7 @@ xdg_surface_constructor_get_popup (struct wl_client *client, xdg_positioner = wl_resource_get_user_data (positioner_resource); xdg_popup->setup.placement_rule = - meta_wayland_xdg_positioner_to_placement (xdg_positioner); + meta_wayland_xdg_positioner_to_placement (xdg_positioner, parent_surface); xdg_popup->setup.parent_surface = parent_surface; } @@ -1560,17 +1561,29 @@ xdg_surface_constructor_destructor (struct wl_resource *resource) } static MetaPlacementRule -meta_wayland_xdg_positioner_to_placement (MetaWaylandXdgPositioner *xdg_positioner) +meta_wayland_xdg_positioner_to_placement (MetaWaylandXdgPositioner *xdg_positioner, + MetaWaylandSurface *parent_surface) { + MetaWindow *parent_window; + int monitor_scale; + + parent_window = meta_wayland_surface_get_toplevel_window (parent_surface); + monitor_scale = meta_window_wayland_get_main_monitor_scale (parent_window); + return (MetaPlacementRule) { - .anchor_rect = xdg_positioner->anchor_rect, + .anchor_rect = (MetaRectangle) { + .x = xdg_positioner->anchor_rect.x * monitor_scale, + .y = xdg_positioner->anchor_rect.y * monitor_scale, + .width = xdg_positioner->anchor_rect.width * monitor_scale, + .height = xdg_positioner->anchor_rect.height * monitor_scale, + }, .gravity = xdg_positioner->gravity, .anchor = xdg_positioner->anchor, .constraint_adjustment = xdg_positioner->constraint_adjustment, - .offset_x = xdg_positioner->offset_x, - .offset_y = xdg_positioner->offset_y, - .width = xdg_positioner->width, - .height = xdg_positioner->height, + .offset_x = xdg_positioner->offset_x * monitor_scale, + .offset_y = xdg_positioner->offset_y * monitor_scale, + .width = xdg_positioner->width * monitor_scale, + .height = xdg_positioner->height * monitor_scale, }; } -- 2.7.4 From 60315f5a72741d0b6cdbe0ba19d771a922406bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Fri, 23 Sep 2016 17:15:56 +0800 Subject: [PATCH] wayland/xdg-popup: Always use monitor of toplevel Always use the monitor of the toplevel surface's window, so that the popup menu and the parent will always have the same scale. This fixes the dimensions sent in the xdg_popup configure event. https://bugzilla.gnome.org/show_bug.cgi?id=771841 --- src/wayland/meta-wayland-xdg-shell.c | 1 + src/wayland/meta-window-wayland.c | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/wayland/meta-wayland-xdg-shell.c b/src/wayland/meta-wayland-xdg-shell.c index 84bf40d..ac40504 100644 --- a/src/wayland/meta-wayland-xdg-shell.c +++ b/src/wayland/meta-wayland-xdg-shell.c @@ -1464,6 +1464,7 @@ xdg_surface_constructor_get_toplevel (struct wl_client *client, window = meta_window_wayland_new (meta_get_display (), surface); meta_wayland_surface_set_window (surface, window); + meta_window_update_monitor (window, FALSE); } static void diff --git a/src/wayland/meta-window-wayland.c b/src/wayland/meta-window-wayland.c index 7dd6f42..aa89066 100644 --- a/src/wayland/meta-window-wayland.c +++ b/src/wayland/meta-window-wayland.c @@ -352,19 +352,31 @@ scale_rect_size (MetaRectangle *rect, static void meta_window_wayland_update_main_monitor (MetaWindow *window) { + MetaWindow *toplevel_window; const MetaMonitorInfo *from; const MetaMonitorInfo *to; const MetaMonitorInfo *scaled_new; float scale; MetaRectangle rect; - /* Require both the current and the new monitor would be the new main monitor, - * even given the resulting scale the window would end up having. This is - * needed to avoid jumping back and forth between the new and the old, since - * changing main monitor may cause the window to be resized so that it no - * longer have that same new main monitor. */ from = window->monitor; - to = meta_screen_calculate_monitor_for_window (window->screen, window); + + /* If the window is not a toplevel window (i.e. it's a popup window) just use + * the monitor of the toplevel. */ + toplevel_window = meta_wayland_surface_get_toplevel_window (window->surface); + if (toplevel_window != window) + { + to = toplevel_window->monitor; + } + else + { + /* Require both the current and the new monitor would be the new main monitor, + * even given the resulting scale the window would end up having. This is + * needed to avoid jumping back and forth between the new and the old, since + * changing main monitor may cause the window to be resized so that it no + * longer have that same new main monitor. */ + to = meta_screen_calculate_monitor_for_window (window->screen, window); + } if (from == to) return; -- 2.7.4 From 74274edbd5cdf36d90012fcff9199ccf64cb146f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Fri, 23 Sep 2016 17:18:21 +0800 Subject: [PATCH] wayland/xdg-shell: Scale configure relative popup coordinate The parent local popup coordinate needs to be scaled according to the monitor scale it is assigned. https://bugzilla.gnome.org/show_bug.cgi?id=771841 --- src/wayland/meta-wayland-xdg-shell.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wayland/meta-wayland-xdg-shell.c b/src/wayland/meta-wayland-xdg-shell.c index ac40504..70d8ee4 100644 --- a/src/wayland/meta-wayland-xdg-shell.c +++ b/src/wayland/meta-wayland-xdg-shell.c @@ -874,6 +874,7 @@ xdg_popup_role_configure (MetaWaylandSurfaceRoleShellSurface *shell_surface_role MetaWaylandXdgPopup *xdg_popup = META_WAYLAND_XDG_POPUP (shell_surface_role); MetaWaylandXdgSurface *xdg_surface = META_WAYLAND_XDG_SURFACE (xdg_popup); MetaWindow *parent_window = xdg_popup->parent_surface->window; + int monitor_scale; int x, y; /* If the parent surface was destroyed, its window will be destroyed @@ -887,8 +888,9 @@ xdg_popup_role_configure (MetaWaylandSurfaceRoleShellSurface *shell_surface_role if (!parent_window) return; - x = new_x - parent_window->rect.x; - y = new_y - parent_window->rect.y; + monitor_scale = meta_window_wayland_get_main_monitor_scale (parent_window); + x = (new_x - parent_window->rect.x) / monitor_scale; + y = (new_y - parent_window->rect.y) / monitor_scale; zxdg_popup_v6_send_configure (xdg_popup->resource, x, y, new_width, new_height); meta_wayland_xdg_surface_send_configure (xdg_surface); -- 2.7.4 From c5ef7eb1a8b255dfbad7c32ebde6241dc411fb7d Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Fri, 23 Sep 2016 23:09:39 +0200 Subject: [PATCH] wayland/xdg-popup: Force monitor of the top-level Directly set the monitor of the toplevel window for the popup to avoid the change not being applied due to later constraints calculation. Signed-off-by: Sjoerd Simons https://bugzilla.gnome.org/show_bug.cgi?id=771841 --- src/wayland/meta-window-wayland.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/wayland/meta-window-wayland.c b/src/wayland/meta-window-wayland.c index aa89066..d85e935 100644 --- a/src/wayland/meta-window-wayland.c +++ b/src/wayland/meta-window-wayland.c @@ -366,18 +366,17 @@ meta_window_wayland_update_main_monitor (MetaWindow *window) toplevel_window = meta_wayland_surface_get_toplevel_window (window->surface); if (toplevel_window != window) { - to = toplevel_window->monitor; - } - else - { - /* Require both the current and the new monitor would be the new main monitor, - * even given the resulting scale the window would end up having. This is - * needed to avoid jumping back and forth between the new and the old, since - * changing main monitor may cause the window to be resized so that it no - * longer have that same new main monitor. */ - to = meta_screen_calculate_monitor_for_window (window->screen, window); + window->monitor = toplevel_window->monitor; + return; } + /* Require both the current and the new monitor would be the new main monitor, + * even given the resulting scale the window would end up having. This is + * needed to avoid jumping back and forth between the new and the old, since + * changing main monitor may cause the window to be resized so that it no + * longer have that same new main monitor. */ + to = meta_screen_calculate_monitor_for_window (window->screen, window); + if (from == to) return; -- 2.9.3 From b7d5bac26acbaee954e4db5fc9032cc8bc899285 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Fri, 23 Sep 2016 23:12:56 +0200 Subject: [PATCH] wayland/xdg-shell: update popup window monitor early As meta_window_place_with_placement_rule will trigger a configure event being sent ensure that the popup is placed on the correct monitor first to ensure the right scale factor is applied. Signed-off-by: Sjoerd Simons https://bugzilla.gnome.org/show_bug.cgi?id=771841 --- src/wayland/meta-wayland-xdg-shell.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wayland/meta-wayland-xdg-shell.c b/src/wayland/meta-wayland-xdg-shell.c index 70d8ee4..b8e7f83 100644 --- a/src/wayland/meta-wayland-xdg-shell.c +++ b/src/wayland/meta-wayland-xdg-shell.c @@ -794,8 +794,9 @@ finish_popup_setup (MetaWaylandXdgPopup *xdg_popup) &xdg_popup->parent_destroy_listener); window = meta_window_wayland_new (display, surface); - meta_window_place_with_placement_rule (window, &placement_rule); meta_wayland_surface_set_window (surface, window); + meta_window_update_monitor (window, FALSE); + meta_window_place_with_placement_rule (window, &placement_rule); if (seat) { -- 2.9.3