From 05e9d6ab9e6ea2d4679328a69af1b40e120bd690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Thu, 13 Feb 2020 22:40:15 +0100 Subject: [PATCH] window: Put placement related fields in a anynomous struct To organize things a bit better, put the fields related to the placement rule state in its own anonymous struct inside MetaWindow. While at it, rename the somewhat oddly named variable that in practice means the current relative window position. https://gitlab.gnome.org/GNOME/mutter/merge_requests/705 --- src/core/constraints.c | 18 +++++++++--------- src/core/place.c | 2 +- src/core/window-private.h | 13 +++++++++---- src/core/window.c | 4 ++-- src/wayland/meta-window-wayland.c | 8 ++++---- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/core/constraints.c b/src/core/constraints.c index a66fe6e20..fa70ec1bf 100644 --- a/src/core/constraints.c +++ b/src/core/constraints.c @@ -490,14 +490,14 @@ place_window_if_needed(MetaWindow *window, orig_rect = info->orig; - if (window->placement_rule) + if (window->placement.rule) { MetaWindow *parent = meta_window_get_transient_for (window); MetaRectangle parent_rect; int rel_x, rel_y; meta_window_process_placement (window, - window->placement_rule, + window->placement.rule, &rel_x, &rel_y); meta_window_get_frame_rect (parent, &parent_rect); @@ -831,15 +831,15 @@ constrain_custom_rule (MetaWindow *window, parent = meta_window_get_transient_for (window); meta_window_get_frame_rect (parent, &parent_rect); - switch (window->placement_state) + switch (window->placement.state) { case META_PLACEMENT_STATE_UNCONSTRAINED: break; case META_PLACEMENT_STATE_CONSTRAINED: adjusted_unconstrained.x = - parent_rect.x + window->constrained_placement_rule_offset_x; + parent->rect.x + window->placement.current.rel_x; adjusted_unconstrained.y = - parent_rect.y + window->constrained_placement_rule_offset_y; + parent->rect.y + window->placement.current.rel_y; break; } @@ -857,7 +857,7 @@ constrain_custom_rule (MetaWindow *window, current_rule = *placement_rule; - switch (window->placement_state) + switch (window->placement.state) { case META_PLACEMENT_STATE_CONSTRAINED: info->current = adjusted_unconstrained; @@ -965,10 +965,10 @@ constrain_custom_rule (MetaWindow *window, } done: - window->placement_state = META_PLACEMENT_STATE_CONSTRAINED; + window->placement.state = META_PLACEMENT_STATE_CONSTRAINED; - window->constrained_placement_rule_offset_x = info->current.x - parent_rect.x; - window->constrained_placement_rule_offset_y = info->current.y - parent_rect.y; + window->placement.current.rel_x = info->current.x - parent_rect.x; + window->placement.current.rel_y = info->current.y - parent_rect.y; return TRUE; } diff --git a/src/core/place.c b/src/core/place.c index 6d0a159a3..237f7590b 100644 --- a/src/core/place.c +++ b/src/core/place.c @@ -671,7 +671,7 @@ meta_window_place (MetaWindow *window, meta_topic (META_DEBUG_PLACEMENT, "Placing window %s\n", window->desc); - g_return_if_fail (!window->placement_rule); + g_return_if_fail (!window->placement.rule); switch (window->type) { diff --git a/src/core/window-private.h b/src/core/window-private.h index b32f47bc7..f1daa9da6 100644 --- a/src/core/window-private.h +++ b/src/core/window-private.h @@ -534,10 +534,15 @@ struct _MetaWindow /* Bypass compositor hints */ guint bypass_compositor; - MetaPlacementRule *placement_rule; - MetaPlacementState placement_state; - int constrained_placement_rule_offset_x; - int constrained_placement_rule_offset_y; + struct { + MetaPlacementRule *rule; + MetaPlacementState state; + + struct { + int rel_x; + int rel_y; + } current; + } placement; guint unmanage_idle_id; }; diff --git a/src/core/window.c b/src/core/window.c index 349574388..4a7e2b756 100644 --- a/src/core/window.c +++ b/src/core/window.c @@ -344,7 +344,7 @@ meta_window_finalize (GObject *object) g_free (window->gtk_window_object_path); g_free (window->gtk_app_menu_object_path); g_free (window->gtk_menubar_object_path); - g_free (window->placement_rule); + g_free (window->placement.rule); G_OBJECT_CLASS (meta_window_parent_class)->finalize (object); } @@ -8523,7 +8523,7 @@ meta_window_emit_size_changed (MetaWindow *window) MetaPlacementRule * meta_window_get_placement_rule (MetaWindow *window) { - return window->placement_rule; + return window->placement.rule; } void diff --git a/src/wayland/meta-window-wayland.c b/src/wayland/meta-window-wayland.c index 910dd0e48..9b113a6c9 100644 --- a/src/wayland/meta-window-wayland.c +++ b/src/wayland/meta-window-wayland.c @@ -324,7 +324,7 @@ meta_window_wayland_move_resize_internal (MetaWindow *window, constrained_rect.height == 1) return; - if (window->placement_rule) + if (window->placement.rule) { MetaWindow *parent = meta_window_get_transient_for (window); int rel_x, rel_y; @@ -913,9 +913,9 @@ void meta_window_place_with_placement_rule (MetaWindow *window, MetaPlacementRule *placement_rule) { - g_clear_pointer (&window->placement_rule, g_free); - window->placement_rule = g_new0 (MetaPlacementRule, 1); - *window->placement_rule = *placement_rule; + g_clear_pointer (&window->placement.rule, g_free); + window->placement.rule = g_new0 (MetaPlacementRule, 1); + *window->placement.rule = *placement_rule; window->unconstrained_rect.width = placement_rule->width; window->unconstrained_rect.height = placement_rule->height;