From fa1add2ee6d440020a6ef866b6ce2c310ef84239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Fri, 5 Oct 2018 14:42:24 +0200 Subject: [PATCH] window: Remember relative position after constraining with custom rule In order to allow a window with a custom rule placement to be moved together with its parent, the final rule used derived from the constraining were used for subsequent constraints. This was not enough as some constraining cannot be translated into a rule, such as sliding across some axis. Instead, make it a bit simpler and just remember the position relative to the parent window, and use that the next time. This is a rework of 5376c31a33020d7dc5a69b129f2dd4f42d0890a1 which caused the unwanted side effects. Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/332 --- src/core/constraints.c | 22 ++++++++++++++++------ src/core/window-private.h | 4 +++- src/core/window.c | 1 - 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/core/constraints.c b/src/core/constraints.c index 82e19ee29..a205ea0fd 100644 --- a/src/core/constraints.c +++ b/src/core/constraints.c @@ -788,6 +788,8 @@ constrain_custom_rule (MetaWindow *window, MetaRectangle intersection; gboolean constraint_satisfied; MetaPlacementRule *current_rule; + MetaWindow *parent; + MetaRectangle parent_rect; if (priority > PRIORITY_CUSTOM_RULE) return TRUE; @@ -796,11 +798,15 @@ constrain_custom_rule (MetaWindow *window, if (!placement_rule) return TRUE; - if (window->constrained_placement_rule) + if (window->placement_rule_constrained) { - meta_window_process_placement (window, - window->constrained_placement_rule, - &info->current.x, &info->current.y); + parent = meta_window_get_transient_for (window); + meta_window_get_frame_rect (parent, &parent_rect); + info->current.x = + parent_rect.x + window->constrained_placement_rule_offset_x; + info->current.y = + parent_rect.y + window->constrained_placement_rule_offset_y; + return TRUE; } @@ -886,8 +892,12 @@ constrain_custom_rule (MetaWindow *window, } done: - g_clear_pointer (&window->constrained_placement_rule, g_free); - window->constrained_placement_rule = current_rule; + window->placement_rule_constrained = TRUE; + + parent = meta_window_get_transient_for (window); + meta_window_get_frame_rect (parent, &parent_rect); + window->constrained_placement_rule_offset_x = info->current.x - parent_rect.x; + window->constrained_placement_rule_offset_y = info->current.y - parent_rect.y; return TRUE; } diff --git a/src/core/window-private.h b/src/core/window-private.h index 60f8f5e8e..23662ca6a 100644 --- a/src/core/window-private.h +++ b/src/core/window-private.h @@ -524,7 +524,9 @@ struct _MetaWindow guint bypass_compositor; MetaPlacementRule *placement_rule; - MetaPlacementRule *constrained_placement_rule; + gboolean placement_rule_constrained; + int constrained_placement_rule_offset_x; + int constrained_placement_rule_offset_y; }; struct _MetaWindowClass diff --git a/src/core/window.c b/src/core/window.c index 79f0b2e39..aa6c568f5 100644 --- a/src/core/window.c +++ b/src/core/window.c @@ -313,7 +313,6 @@ meta_window_finalize (GObject *object) g_free (window->gtk_app_menu_object_path); g_free (window->gtk_menubar_object_path); g_free (window->placement_rule); - g_free (window->constrained_placement_rule); G_OBJECT_CLASS (meta_window_parent_class)->finalize (object); }