From 83e213d7701455cb34a1d986eff0c048a146cc56 Mon Sep 17 00:00:00 2001 From: Jehan Date: Mon, 5 May 2025 19:05:47 +0200 Subject: [PATCH] app: initial monitor information is only needed at display shell construction. Making sure that it's private then NULLified at end of construction so that none tries to use this again later on during the life of the display shell (it may have become invalid since then, cf. #12542). Also NULLifying a similar variable stored in GimpImageWindow (though it was already a private variable not used outside in this case). --- app/display/gimpdisplayshell.c | 18 +++++++++++++++--- app/display/gimpdisplayshell.h | 6 ++++-- app/display/gimpimagewindow.c | 3 +++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c index dfb17b9233..198c31d1b1 100644 --- a/app/display/gimpdisplayshell.c +++ b/app/display/gimpdisplayshell.c @@ -118,6 +118,11 @@ enum LAST_SIGNAL }; +struct _GimpDisplayShellPrivate +{ + GdkMonitor *initial_monitor; +}; + typedef struct _GimpDisplayShellOverlay GimpDisplayShellOverlay; @@ -194,6 +199,7 @@ static gboolean gimp_display_shell_draw (GimpDisplayShell *shell, G_DEFINE_TYPE_WITH_CODE (GimpDisplayShell, gimp_display_shell, GTK_TYPE_EVENT_BOX, + G_ADD_PRIVATE (GimpDisplayShell) G_IMPLEMENT_INTERFACE (GIMP_TYPE_PROGRESS, gimp_display_shell_progress_iface_init) G_IMPLEMENT_INTERFACE (GIMP_TYPE_COLOR_MANAGED, @@ -336,6 +342,9 @@ gimp_display_shell_init (GimpDisplayShell *shell) { const gchar *env; + shell->priv = gimp_display_shell_get_instance_private (shell); + shell->priv->initial_monitor = NULL; + shell->options = g_object_new (GIMP_TYPE_DISPLAY_OPTIONS, NULL); shell->fullscreen_options = g_object_new (GIMP_TYPE_DISPLAY_OPTIONS_FULLSCREEN, NULL); shell->no_image_options = g_object_new (GIMP_TYPE_DISPLAY_OPTIONS_NO_IMAGE, NULL); @@ -492,7 +501,7 @@ gimp_display_shell_constructed (GObject *object) if (config->monitor_res_from_gdk) { - gimp_get_monitor_resolution (shell->initial_monitor, + gimp_get_monitor_resolution (shell->priv->initial_monitor, &shell->monitor_xres, &shell->monitor_yres); } else @@ -817,6 +826,9 @@ gimp_display_shell_constructed (GObject *object) gimp_display_shell_scale_update (shell); gimp_display_shell_set_show_all (shell, config->default_show_all); + + /* This was only useful during construction and should not be further used. */ + shell->priv->initial_monitor = NULL; } static void @@ -926,7 +938,7 @@ gimp_display_shell_set_property (GObject *object, shell->popup_manager = g_value_get_object (value); break; case PROP_INITIAL_MONITOR: - shell->initial_monitor = g_value_get_object (value); + shell->priv->initial_monitor = g_value_get_object (value); break; case PROP_DISPLAY: shell->display = g_value_get_object (value); @@ -966,7 +978,7 @@ gimp_display_shell_get_property (GObject *object, g_value_set_object (value, shell->popup_manager); break; case PROP_INITIAL_MONITOR: - g_value_set_object (value, shell->initial_monitor); + g_value_set_object (value, shell->priv->initial_monitor); break; case PROP_DISPLAY: g_value_set_object (value, shell->display); diff --git a/app/display/gimpdisplayshell.h b/app/display/gimpdisplayshell.h index f58334af93..b4a4e4f15b 100644 --- a/app/display/gimpdisplayshell.h +++ b/app/display/gimpdisplayshell.h @@ -43,7 +43,8 @@ #define GIMP_DISPLAY_SHELL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_DISPLAY_SHELL, GimpDisplayShellClass)) -typedef struct _GimpDisplayShellClass GimpDisplayShellClass; +typedef struct _GimpDisplayShellClass GimpDisplayShellClass; +typedef struct _GimpDisplayShellPrivate GimpDisplayShellPrivate; struct _GimpDisplayShell { @@ -54,7 +55,6 @@ struct _GimpDisplayShell GBytes *window_handle; GimpUIManager *popup_manager; - GdkMonitor *initial_monitor; GimpDisplayOptions *options; GimpDisplayOptions *fullscreen_options; @@ -255,6 +255,8 @@ struct _GimpDisplayShell GimpLayer *near_layer_vertical2; gboolean drawn; + + GimpDisplayShellPrivate *priv; }; struct _GimpDisplayShellClass diff --git a/app/display/gimpimagewindow.c b/app/display/gimpimagewindow.c index c0a08344a5..05b9574623 100644 --- a/app/display/gimpimagewindow.c +++ b/app/display/gimpimagewindow.c @@ -569,6 +569,9 @@ gimp_image_window_constructed (GObject *object) gimp_container_foreach (GIMP_CONTAINER (device_manager), (GFunc) gimp_image_window_init_pad_foreach, window); + + /* This was only useful during construction and should not be further used. */ + private->initial_monitor = NULL; } static void