Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-terminal/ChangeLog,v
retrieving revision 1.445
diff -u -p -r1.445 ChangeLog
--- ChangeLog	1 Jun 2005 15:01:55 -0000	1.445
+++ ChangeLog	15 Jun 2005 13:18:41 -0000
@@ -1,3 +1,15 @@
+2005-06-15  Martin Ejdestig  <mejde@dtek.chalmers.se>
+
+	* src/gnome-terminal.schemas.in: Added default_width, default_height and
+	default_maximize.
+
+	* src/terminal-window.c (default_geometry_load, default_geometry_save):
+	new functions.
+
+	* src/terminal-window.c (terminal_window_add_screen,
+	terminal_window_remove_screen, terminal_window_delete_event,
+	close_window_callback): call functions to save/load default geometry.
+
 2005-05-31  Rodrigo Moya <rodrigo@novell.com>
 
 	* src/gnome-terminal.server: added name attribute.
Index: src/gnome-terminal.schemas.in
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/gnome-terminal.schemas.in,v
retrieving revision 1.39
diff -u -p -r1.39 gnome-terminal.schemas.in
--- src/gnome-terminal.schemas.in	17 Aug 2004 14:41:35 -0000	1.39
+++ src/gnome-terminal.schemas.in	15 Jun 2005 13:18:42 -0000
@@ -40,6 +40,49 @@
     </schema>
 
     <schema>
+      <key>/schemas/apps/gnome-terminal/global/default_width</key>
+      <applyto>/apps/gnome-terminal/global/default_width</applyto>
+      <owner>gnome-terminal</owner>
+      <type>int</type>
+      <default>80</default>
+      <locale name="C">
+         <short>Default width to use for new terminal windows</short>
+         <long>
+          Width in characters to use in terminal when opening a new window.
+         </long>
+      </locale>
+    </schema>
+
+    <schema>
+      <key>/schemas/apps/gnome-terminal/global/default_height</key>
+      <applyto>/apps/gnome-terminal/global/default_height</applyto>
+      <owner>gnome-terminal</owner>
+      <type>int</type>
+      <default>24</default>
+      <locale name="C">
+         <short>Default height to use for new terminal windows</short>
+         <long>
+          Height in characters to use in terminal when opening a new window.
+         </long>
+      </locale>
+    </schema>
+
+    <schema>
+      <key>/schemas/apps/gnome-terminal/global/default_maximize</key>
+      <applyto>/apps/gnome-terminal/global/default_maximize</applyto>
+      <owner>gnome-terminal</owner>
+      <type>bool</type>
+      <default>false</default>
+      <locale name="C">
+         <short>Whether to maximize new windows</short>
+         <long>
+          Whether to maximize new terminal windows. This overrides default_width
+          and default_height if set to true.
+         </long>
+      </locale>
+    </schema>
+
+    <schema>
       <key>/schemas/apps/gnome-terminal/global/use_mnemonics</key>
       <applyto>/apps/gnome-terminal/global/use_mnemonics</applyto>
       <owner>gnome-terminal</owner>
Index: src/terminal-window.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-window.c,v
retrieving revision 1.106
diff -u -p -r1.106 terminal-window.c
--- src/terminal-window.c	28 Feb 2005 23:27:11 -0000	1.106
+++ src/terminal-window.c	15 Jun 2005 13:18:43 -0000
@@ -76,6 +76,7 @@ struct _TerminalWindowPrivate
   guint use_default_menubar_visibility : 1;
   guint use_mnemonics : 1;   /* config key value */
   guint using_mnemonics : 1; /* current menubar state */
+  guint geometry_saved : 1;
 
   /* FIXME we brokenly maintain this flag here instead of
    * being event-driven, because it's too annoying to be
@@ -209,6 +210,9 @@ static gboolean find_smaller_zoom_factor
 
 static void terminal_window_show (GtkWidget *widget);
 
+static void default_geometry_load (TerminalWindow *window);
+static void default_geometry_save (TerminalWindow *window);
+
 static gboolean confirm_close_window (TerminalWindow *window);
 
 static gpointer parent_class;
@@ -798,6 +802,7 @@ terminal_window_init (TerminalWindow *wi
   
   window->priv->use_mnemonics = TRUE;
   window->priv->using_mnemonics = FALSE;
+  window->priv->geometry_saved = FALSE;
 
   /* force gtk to construct its GtkClipboard; otherwise our UI is very slow the first time we need it */
   window->priv->clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (GTK_WIDGET (window)), GDK_NONE);
@@ -1125,7 +1130,14 @@ terminal_window_delete_event (GtkWidget 
                               GdkEvent *event,
                               gpointer data)
 {
-   return !confirm_close_window (TERMINAL_WINDOW (widget));
+  gboolean close;
+
+  close = confirm_close_window (TERMINAL_WINDOW (widget));
+
+  if (close)
+    default_geometry_save (TERMINAL_WINDOW (widget));
+
+  return !close;
 }
 
 static void
@@ -1472,9 +1484,12 @@ terminal_window_add_screen (TerminalWind
     terminal_widget_set_size (term, current_width, current_height);
   }
   
-  /* Make the first-added screen the active one */
-  if (window->priv->terms == NULL)
-    terminal_window_set_active (window, screen);
+  /* Make the first-added screen the active one and load geometry */
+  if (terminal_window_get_screen_count (window) == 1)
+    {
+      terminal_window_set_active (window, screen);
+      default_geometry_load (window);
+    }
 }
 
 void
@@ -1486,6 +1501,12 @@ terminal_window_remove_screen (TerminalW
   
   g_return_if_fail (terminal_screen_get_window (screen) == window);
 
+  if (terminal_window_get_screen_count (window) == 1)
+    {
+      /* Save here to catch the case when the child dies (e.g. by CTRL-D) */
+      default_geometry_save (window);
+    }
+
   old_grid_width = -1;
   old_grid_height = -1;
   
@@ -2347,11 +2368,125 @@ confirm_close_window (TerminalWindow *wi
 }
 
 static void
+default_geometry_load (TerminalWindow *window)
+{
+  GError *err;
+  int w, h;
+  gboolean maximize;
+  char *geometry;
+
+  err = NULL;
+  w = gconf_client_get_int (window->priv->conf,
+                            CONF_GLOBAL_PREFIX"/default_width",
+                            &err);
+  if (err)
+    {
+      g_printerr (_("There was an error loading config value for default width. (%s)\n"),
+                  err->message);
+      g_error_free (err);
+      w = 80;
+    }
+
+  err = NULL;
+  h = gconf_client_get_int (window->priv->conf,
+                            CONF_GLOBAL_PREFIX"/default_height",
+                            &err);
+  if (err)
+    {
+      g_printerr (_("There was an error loading config value for default height. (%s)\n"),
+                  err->message);
+      g_error_free (err);
+      h = 24;
+    }
+
+  err = NULL;
+  maximize = gconf_client_get_bool (window->priv->conf,
+                                    CONF_GLOBAL_PREFIX"/default_maximize",
+                                    &err);
+  if (err)
+    {
+      g_printerr (_("There was an error loading config value for whether to maximize window or not. (%s)\n"),
+                  err->message);
+      g_error_free (err);
+      maximize = FALSE;
+    }
+
+  geometry = g_strdup_printf ("%dx%d", w, h);
+  gtk_window_parse_geometry (GTK_WINDOW (window), geometry);
+  g_free (geometry);
+
+  if (maximize)
+    gtk_window_maximize(GTK_WINDOW (window));
+}
+
+static void
+default_geometry_save (TerminalWindow *window)
+{
+  GdkWindowState state;
+  gboolean maximize;
+  GError *err;
+
+  /* Geometry is saved twice in some cases. The second time is always
+   * indirectly from terminal_window_destroy () which means we can't get the
+   * window state. geometry_saved prevents us from even trying a second time.
+   */
+  if (window->priv->geometry_saved)
+    return;
+
+  state = gdk_window_get_state(GTK_WIDGET (window)->window);
+  maximize = (state & GDK_WINDOW_STATE_MAXIMIZED) != 0;
+
+  err = NULL;
+  gconf_client_set_bool (window->priv->conf,
+                         CONF_GLOBAL_PREFIX"/default_maximize",
+                         maximize, &err);
+  if (err != NULL)
+    {
+      g_printerr (_("Error setting %s config key: %s\n"), CONF_GLOBAL_PREFIX"/default_maximize", err->message);
+      g_error_free (err);
+    }
+
+  if (!maximize && window->priv->active_term != NULL)
+    {
+      int w, h;
+      GtkWidget *widget;
+
+      widget = terminal_screen_get_widget (window->priv->active_term);
+      terminal_widget_get_size (widget, &w, &h);
+
+      err = NULL;
+      gconf_client_set_int (window->priv->conf,
+                            CONF_GLOBAL_PREFIX"/default_width",
+                            w, &err);
+      if (err != NULL)
+        {
+          g_printerr (_("Error setting %s config key: %s\n"), CONF_GLOBAL_PREFIX"/default_width", err->message);
+          g_error_free (err);
+        }
+
+      err = NULL;
+      gconf_client_set_int (window->priv->conf,
+                            CONF_GLOBAL_PREFIX"/default_height",
+                            h, &err);
+      if (err != NULL)
+        {
+          g_printerr (_("Error setting %s config key: %s\n"), CONF_GLOBAL_PREFIX"/default_height", err->message);
+          g_error_free (err);
+        }
+    }
+
+  window->priv->geometry_saved = TRUE;
+}
+
+static void
 close_window_callback (GtkWidget      *menuitem,
                        TerminalWindow *window)
 {
   if (confirm_close_window (window))
-    gtk_widget_destroy (GTK_WIDGET (window));
+    {
+      default_geometry_save (window);
+      gtk_widget_destroy (GTK_WIDGET (window));
+    }
 }
 
 static void
