From fc29825f356e21cf84bffc1096bb7ccd05291a24 Mon Sep 17 00:00:00 2001
From: Dino <macwiz23@comcast.net>
Date: Fri, 11 Apr 2025 16:46:57 -0400
Subject: [PATCH 10/10] gtk: Fix saving and restoring city dlog size

Minor style corrections by Marko Lindqvist

See RM #1289
---
 client/gui-gtk-3.22/citydlg.c | 18 ++++++++++++------
 client/gui-gtk-4.0/citydlg.c  | 16 +++++++++-------
 2 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/client/gui-gtk-3.22/citydlg.c b/client/gui-gtk-3.22/citydlg.c
index f8a5be0107..10c627b3bd 100644
--- a/client/gui-gtk-3.22/citydlg.c
+++ b/client/gui-gtk-3.22/citydlg.c
@@ -3350,7 +3350,7 @@ static void set_cityopt_values(struct city_dialog *pdialog)
 
 /******************** Callbacks for: Close, Prev, Next. ******************/
 /**********************************************************************//**
-  User has clicked rename city-button
+  User has closed city dialog
 **************************************************************************/
 static void close_callback(GtkWidget *w, gpointer data)
 {
@@ -3358,14 +3358,20 @@ static void close_callback(GtkWidget *w, gpointer data)
 }
 
 /**********************************************************************//**
-  User has closed rename city dialog
+  User has closed city dialog
 **************************************************************************/
 static void city_destroy_callback(GtkWidget *w, gpointer data)
 {
   struct city_dialog *pdialog;
+  int width, height;
+  GtkWidget *cont_area;
 
   pdialog = (struct city_dialog *) data;
 
+  cont_area = gtk_dialog_get_content_area(GTK_DIALOG(pdialog->shell));
+  width = gtk_widget_get_allocated_width(GTK_WIDGET(cont_area));
+  height = gtk_widget_get_allocated_height(GTK_WIDGET(cont_area));
+
   gtk_widget_hide(pdialog->shell);
 
   if (game.info.citizen_nationality) {
@@ -3377,12 +3383,12 @@ static void city_destroy_callback(GtkWidget *w, gpointer data)
   /* Save size of the city dialog. */
   GUI_GTK_OPTION(citydlg_xsize)
     = CLIP(GUI_GTK3_22_CITYDLG_MIN_XSIZE,
-           gtk_widget_get_allocated_width(pdialog->shell),
+           width,
            GUI_GTK3_22_CITYDLG_MAX_XSIZE);
   GUI_GTK_OPTION(citydlg_ysize)
-    = CLIP(GUI_GTK3_22_CITYDLG_MIN_XSIZE,
-           gtk_widget_get_allocated_height(pdialog->shell),
-           GUI_GTK3_22_CITYDLG_MAX_XSIZE);
+    = CLIP(GUI_GTK3_22_CITYDLG_MIN_YSIZE,
+           height,
+           GUI_GTK3_22_CITYDLG_MAX_YSIZE);
 
   last_page
     = gtk_notebook_get_current_page(GTK_NOTEBOOK(pdialog->notebook));
diff --git a/client/gui-gtk-4.0/citydlg.c b/client/gui-gtk-4.0/citydlg.c
index ad34dd16dd..0bc894746e 100644
--- a/client/gui-gtk-4.0/citydlg.c
+++ b/client/gui-gtk-4.0/citydlg.c
@@ -3481,7 +3481,7 @@ static void set_cityopt_values(struct city_dialog *pdialog)
 /******************** Callbacks for: Close, Prev, Next. *******************/
 
 /***********************************************************************//**
-  User has clicked rename city-button
+  User has closed city dialog
 ***************************************************************************/
 static void close_callback(GtkWidget *w, gpointer data)
 {
@@ -3489,14 +3489,16 @@ static void close_callback(GtkWidget *w, gpointer data)
 }
 
 /***********************************************************************//**
-  User has closed rename city dialog
+  User has closed city dialog
 ***************************************************************************/
 static void city_destroy_callback(GtkWidget *w, gpointer data)
 {
   struct city_dialog *pdialog;
+  int width, height;
 
-  pdialog = (struct city_dialog *) data;
+  gtk_window_get_default_size (GTK_WINDOW(w), &width, &height);
 
+  pdialog = (struct city_dialog *) data;
   gtk_widget_hide(pdialog->shell);
 
   if (game.info.citizen_nationality) {
@@ -3508,12 +3510,12 @@ static void city_destroy_callback(GtkWidget *w, gpointer data)
   /* Save size of the city dialog. */
   GUI_GTK_OPTION(citydlg_xsize)
     = CLIP(GUI_GTK4_CITYDLG_MIN_XSIZE,
-           gtk_widget_get_allocated_width(pdialog->shell),
+           width,
            GUI_GTK4_CITYDLG_MAX_XSIZE);
   GUI_GTK_OPTION(citydlg_ysize)
-    = CLIP(GUI_GTK4_CITYDLG_MIN_XSIZE,
-           gtk_widget_get_allocated_height(pdialog->shell),
-           GUI_GTK4_CITYDLG_MAX_XSIZE);
+    = CLIP(GUI_GTK4_CITYDLG_MIN_YSIZE,
+           height,
+           GUI_GTK4_CITYDLG_MAX_YSIZE);
 
   last_page
     = gtk_notebook_get_current_page(GTK_NOTEBOOK(pdialog->notebook));
-- 
2.47.2

