Index: terminal-screen.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-screen.c,v
retrieving revision 1.127
diff -U5 -r1.127 terminal-screen.c
--- terminal-screen.c	30 Jul 2006 21:44:22 -0000	1.127
+++ terminal-screen.c	28 Aug 2006 06:32:36 -0000
@@ -1323,11 +1323,11 @@
   
   terminal_app_new_terminal (terminal_app_get (),
                              terminal_profile_get_for_new_term (screen->priv->profile),
                              NULL,
                              NULL,
-                             FALSE, FALSE, FALSE,
+                             FALSE, FALSE, FALSE, FALSE,
                              NULL, NULL, NULL, dir, NULL, 1.0,
                              NULL, name, -1);
 
   g_free (name);
 }
@@ -1342,11 +1342,11 @@
 
   terminal_app_new_terminal (terminal_app_get (),
                              terminal_profile_get_for_new_term (screen->priv->profile),
                              screen->priv->window,
                              NULL,
-                             FALSE, FALSE, FALSE,
+                             FALSE, FALSE, FALSE, FALSE,
                              NULL, NULL, NULL, dir, NULL, 1.0,
                              NULL, NULL, -1);
 }
 
 static void
Index: terminal-window.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-window.c,v
retrieving revision 1.132
diff -U5 -r1.132 terminal-window.c
--- terminal-window.c	26 Aug 2006 21:48:18 -0000	1.132
+++ terminal-window.c	28 Aug 2006 06:32:37 -0000
@@ -78,15 +78,12 @@
   guint menubar_visible : 1;
   guint use_default_menubar_visibility : 1;
   guint use_mnemonics : 1;   /* config key value */
   guint using_mnemonics : 1; /* current menubar state */
 
-  /* FIXME we brokenly maintain this flag here instead of
-   * being event-driven, because it's too annoying to be
-   * event-driven while GTK doesn't support _NET_WM_STATE_FULLSCREEN
-   */
   guint fullscreen : 1;
+  guint maximized : 1;
 
   /* Compositing manager integration */
   guint have_argb_visual : 1;
 };
 
@@ -2190,12 +2187,10 @@
 terminal_window_set_fullscreen (TerminalWindow *window,
                                 gboolean        setting)
 {
   g_return_if_fail (GTK_WIDGET_REALIZED (window));
 
-  window->priv->fullscreen = setting;
-  
   if (setting)
     gtk_window_fullscreen (GTK_WINDOW (window));
   else
     gtk_window_unfullscreen (GTK_WINDOW (window));
 }
@@ -2204,10 +2199,29 @@
 terminal_window_get_fullscreen (TerminalWindow *window)
 {
   return window->priv->fullscreen;
 }
 
+void
+terminal_window_set_maximized (TerminalWindow *window,
+                               gboolean        setting)
+{
+  g_return_if_fail (GTK_WIDGET_REALIZED (window));
+
+  if (setting)
+    gtk_window_maximize (GTK_WINDOW (window));
+  else
+    gtk_window_unmaximize (GTK_WINDOW (window));
+}
+
+gboolean
+terminal_window_get_maximized (TerminalWindow *window)
+{
+  return window->priv->maximized;
+}
+
+
 /*
  * Callbacks for the menus
  */
 
 static void
@@ -2260,11 +2274,11 @@
 
   terminal_app_new_terminal (terminal_app_get (),
                              profile,
                              NULL,
                              screen,
-                             FALSE, FALSE, FALSE,
+                             FALSE, FALSE, FALSE, FALSE,
                              NULL, geometry, NULL, dir, NULL, 1.0,
                              NULL, name, -1);
 
   g_free (geometry);
 }
@@ -2288,11 +2302,11 @@
 
       terminal_app_new_terminal (terminal_app_get (),
                                  profile,
                                  window,
                                  NULL,
-                                 FALSE, FALSE, FALSE,
+                                 FALSE, FALSE, FALSE, FALSE,
                                  NULL, NULL, NULL, dir, NULL, 1.0,
                                  NULL, NULL, -1);
     }
 }
 
@@ -2458,23 +2472,29 @@
 static gboolean
 window_state_event_callback (GtkWidget            *widget, 
                              GdkEventWindowState  *event,
                              gpointer              user_data)
 {
-  if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
-    {
-    TerminalWindow *window;
-    GtkCheckMenuItem *menu_item;
-    gboolean new_state;
+  TerminalWindow *window;
+  GtkCheckMenuItem *menu_item;
+  gboolean new_state;
 
-    window = TERMINAL_WINDOW (widget);
-    menu_item = GTK_CHECK_MENU_ITEM (user_data);
+  window = TERMINAL_WINDOW (widget);
+  menu_item = GTK_CHECK_MENU_ITEM (user_data);
 
-    new_state = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
+  if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
+    {
+    new_state = !!(event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN);
 
     window->priv->fullscreen = new_state;
     gtk_check_menu_item_set_active (menu_item, new_state);
+    }
+  else if (event->changed_mask & GDK_WINDOW_STATE_MAXIMIZED)
+    {
+    new_state = !!(event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED);
+
+    window->priv->maximized = new_state;
     }
   
   /* Call any other handlers there may be */
   return FALSE;
 }
Index: terminal-window.h
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-window.h,v
retrieving revision 1.12
diff -U5 -r1.12 terminal-window.h
--- terminal-window.h	10 Jul 2006 18:32:21 -0000	1.12
+++ terminal-window.h	28 Aug 2006 06:32:37 -0000
@@ -88,10 +88,13 @@
                                           int             force_grid_height);
 
 void     terminal_window_set_fullscreen (TerminalWindow *window,
                                          gboolean        setting);
 gboolean terminal_window_get_fullscreen (TerminalWindow *window);
+void     terminal_window_set_maximized  (TerminalWindow *window,
+                                         gboolean        setting);
+gboolean terminal_window_get_maximized  (TerminalWindow *window);
 
 GtkWidget* terminal_window_get_notebook (TerminalWindow *window);
 
 void terminal_window_reread_profile_list (TerminalWindow *window);
 
Index: terminal.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal.c,v
retrieving revision 1.98
diff -U5 -r1.98 terminal.c
--- terminal.c	24 Jul 2006 22:05:38 -0000	1.98
+++ terminal.c	28 Aug 2006 06:32:38 -0000
@@ -95,10 +95,11 @@
   int screen_number;
   GList *initial_windows;
   gboolean default_window_menubar_forced;
   gboolean default_window_menubar_state;
   gboolean default_start_fullscreen;
+  gboolean default_maximized;
   char *default_geometry;
   char *default_working_dir;
   char **post_execute_args;
 } OptionParsingResults;
 
@@ -156,10 +157,11 @@
   OPTION_TAB_WITH_PROFILE_ID,
   OPTION_ROLE,
   OPTION_SHOW_MENUBAR,
   OPTION_HIDE_MENUBAR,
   OPTION_FULLSCREEN,
+  OPTION_MAXIMIZED,
   OPTION_GEOMETRY,
   OPTION_DISABLE_FACTORY,
   OPTION_USE_FACTORY,
   OPTION_STARTUP_ID,
   OPTION_TITLE,
@@ -288,10 +290,19 @@
     OPTION_FULLSCREEN,
     N_("Set the last-specified window into fullscreen mode; applies to only one window; can be specified once for each window you create from the command line."),
     NULL
   },
   {
+    "maximized",
+    '\0',
+    POPT_ARG_NONE,
+    NULL,
+    OPTION_MAXIMIZED,
+    N_("Set the last-specified window to be maximized; applies to only one window; can be specified once for each window you create from the command line."),
+    NULL
+  },
+  {
     "geometry",
     '\0',
     POPT_ARG_STRING,
     NULL,
     OPTION_GEOMETRY,
@@ -571,10 +582,11 @@
 
   gboolean force_menubar_state;
   gboolean menubar_state;
 
   gboolean start_fullscreen;
+  gboolean maximized;
 
   char *geometry;
   char *role;
   
 } InitialWindow;
@@ -619,10 +631,11 @@
   
   iw->tabs = g_list_prepend (NULL, initial_tab_new (profile, is_id));
   iw->force_menubar_state = FALSE;
   iw->menubar_state = FALSE;
   iw->start_fullscreen = FALSE;
+  iw->maximized = FALSE;
   iw->geometry = NULL;
   iw->role = NULL;
   
   return iw;
 }
@@ -644,22 +657,33 @@
   g_assert (iw->geometry == NULL);
 
   if (results->default_geometry)
     {
       iw->geometry = results->default_geometry;
+
       results->default_geometry = NULL;
     }
 
   if (results->default_window_menubar_forced)
     {
       iw->force_menubar_state = TRUE;
       iw->menubar_state = results->default_window_menubar_state;
 
       results->default_window_menubar_forced = FALSE;
     }
+  if (results->default_start_fullscreen)
+    {
+      iw->start_fullscreen = TRUE;
+        
+      results->default_start_fullscreen = FALSE;
+    }
+  if (results->default_maximized)
+    {
+      iw->maximized = TRUE;
 
-  iw->start_fullscreen = results->default_start_fullscreen;
+      results->default_maximized = FALSE;
+    }
 }
 
 static InitialWindow*
 ensure_top_window (OptionParsingResults *results)
 {
@@ -954,10 +978,34 @@
             results->default_start_fullscreen = TRUE;
           }
       }
       break;
 
+    case OPTION_MAXIMIZED:
+      {
+        InitialWindow *iw;
+            
+        if (results->initial_windows)
+          {
+            iw = g_list_last (results->initial_windows)->data;
+
+            if (iw->maximized)
+              {
+                g_printerr (_("\"%s\" option given twice for the same window\n"), "--maximized");
+
+                exit (1);
+              }
+                
+            iw->maximized = TRUE;
+          }
+        else
+          {
+            results->default_maximized = TRUE;
+          }
+      }
+      break;
+
     case OPTION_ROLE:
       {
         InitialWindow *iw;
 
 
@@ -1435,10 +1483,11 @@
                                          NULL,
                                          NULL,
                                          iw->force_menubar_state,
                                          iw->menubar_state,
                                          iw->start_fullscreen,
+                                         iw->maximized,
                                          it->exec_argv,
                                          iw->geometry,
                                          it->title,
                                          it->working_dir,
                                          iw->role,
@@ -1455,11 +1504,12 @@
               terminal_app_new_terminal (app,
                                          profile,
                                          current_window,
                                          NULL,
                                          FALSE, FALSE,
-                                         FALSE/*not fullscreen*/,
+                                         FALSE /* not fullscreen */,
+                                         FALSE /* not maximized */,
                                          it->exec_argv,
                                          NULL,
                                          it->title,
                                          it->working_dir,
                                          NULL,
@@ -1889,10 +1939,11 @@
                            TerminalWindow  *window,
                            TerminalScreen  *screen,
                            gboolean         force_menubar_state,
                            gboolean         forced_menubar_state,
                            gboolean         start_fullscreen,
+                           gboolean         maximized,
                            char           **override_command,
                            const char      *geometry,
                            const char      *title,
                            const char      *working_dir,
                            const char      *role,
@@ -1992,10 +2043,14 @@
 
   if (start_fullscreen)
     {
       terminal_window_set_fullscreen (window, TRUE);
     }
+  if (maximized)
+    {
+      terminal_window_set_maximized (window, TRUE);
+    }
 
   /* don't present on new tab, or we can accidentally make the
    * terminal jump workspaces.
    * http://bugzilla.gnome.org/show_bug.cgi?id=78253
    */
@@ -3274,190 +3329,122 @@
 static void
 terminal_app_get_clone_command (TerminalApp *app,
                                 int         *argcp,
                                 char      ***argvp)
 {
-  int n_windows;
-  int n_tabs;
   GList *tmp;
-  int argc;
-  char **argv;
-  int i;
-  
-  n_windows = g_list_length (app->windows);
-
-  n_tabs = 0;
-  tmp = app->windows;
-  while (tmp != NULL)
-    {
-      GList *tabs = terminal_window_list_screens (tmp->data);
-
-      n_tabs += g_list_length (tabs);
-
-      g_list_free (tabs);
-      
-      tmp = tmp->next;
-    }
+  GPtrArray *args;
   
-  argc = 1; /* argv[0] */
+  args = g_ptr_array_new ();
 
-  if (terminal_factory_disabled)
-    argc += 1; /* --disable-factory */
-  
-  argc += n_windows; /* one --with-window-profile-internal-id per window,
-                      * for the first tab in that window
-                      */
-  argc += n_windows; /* one --show-menubar or --hide-menubar per window */
-
-  argc += n_windows; /* one --role per window */
-
-  argc += n_windows; /* one --active per window */
-
-  argc += n_tabs - n_windows; /* one --with-tab-profile-internal-id
-                               * per extra tab
-                               */
-
-  argc += n_tabs * 2; /* one "--command foo" per tab */
-
-  argc += n_tabs * 2; /* one "--title foo" per tab */
-
-  argc += n_tabs * 2; /* one "--working-directory foo" per tab */
-
-  argc += n_tabs * 2; /* one "--zoom" per tab */
-  
-  argc += 2; /* one "--geometry" per active tab */
-  
-  argv = g_new0 (char*, argc + 1);
-
-  i = 0;
-  argv[i] = g_strdup (EXECUTABLE_NAME);
-  ++i;
+  g_ptr_array_add (args, g_strdup (EXECUTABLE_NAME));
 
   if (terminal_factory_disabled)
     {
-      argv[i] = g_strdup ("--disable-factory");
-      ++i;
+      g_ptr_array_add (args, g_strdup ("--disable-factory"));
     }
   
-  tmp = app->windows;
-  while (tmp != NULL)
+  for (tmp = app->windows; tmp != NULL; tmp = tmp->next)
     {
       GList *tabs;
       GList *tmp2;
       TerminalWindow *window = tmp->data;
       TerminalScreen *active_screen;
 
       active_screen = terminal_window_get_active (window);
-      
       tabs = terminal_window_list_screens (window);
 
-      tmp2 = tabs;
-      while (tmp2 != NULL)
+      for (tmp2 = tabs; tmp2 != NULL; tmp2 = tmp2->next)
         {
           TerminalScreen *screen = tmp2->data;
           const char *profile_id;
           const char **override_command;
           const char *title;
+          gboolean menubar;
           double zoom;
           
           profile_id = terminal_profile_get_name (terminal_screen_get_profile (screen));
           
           if (tmp2 == tabs)
             {
-              argv[i] = g_strdup_printf ("--window-with-profile-internal-id=%s",
-                                         profile_id);
-              ++i;
-              if (terminal_window_get_menubar_visible (window))
-                argv[i] = g_strdup ("--show-menubar");
-              else
-                argv[i] = g_strdup ("--hide-menubar");
-              ++i;
-              argv[i] = g_strdup_printf ("--role=%s",
-                                         gtk_window_get_role (GTK_WINDOW (window)));
-              ++i;
+              g_ptr_array_add (args, g_strdup_printf ("--window-with-profile-internal-id=%s",
+                                                      profile_id));
+
+              menubar = terminal_window_get_menubar_visible (window);
+              g_ptr_array_add (args, g_strdup (menubar ? "--show-menubar" : "--hide-menubar"));
+
+              if (terminal_window_get_maximized (window))
+                {
+                  g_ptr_array_add (args, g_strdup ("--maximized"));
+                }
+
+              g_ptr_array_add (args, g_strdup_printf ("--role=%s",
+                                                      gtk_window_get_role (GTK_WINDOW (window))));
             }
           else
             {
-              argv[i] = g_strdup_printf ("--tab-with-profile-internal-id=%s",
-                                         profile_id);
-              ++i;
+              g_ptr_array_add (args, g_strdup_printf ("--tab-with-profile-internal-id=%s",
+                                                      profile_id));
             }
 
           if (screen == active_screen)
             {
               int w, h, x, y;
 
+              g_ptr_array_add (args, g_strdup ("--active"));
+
               /* FIXME saving the geometry is not great :-/ */
-              argv[i] = g_strdup ("--active");
-              ++i;
-              argv[i] = g_strdup ("--geometry");
-              ++i;
               terminal_widget_get_size (terminal_screen_get_widget (screen), &w, &h);
               gtk_window_get_position (GTK_WINDOW (window), &x, &y);
-              argv[i] = g_strdup_printf ("%dx%d+%d+%d", w, h, x, y);
-              ++i;
+              g_ptr_array_add (args, g_strdup_printf ("--geometry=%dx%d+%d+%d", w, h, x, y));
             }
 
           override_command = terminal_screen_get_override_command (screen);
           if (override_command)
             {
               char *flattened;
 
-              argv[i] = g_strdup ("--command");
-              ++i;
+              g_ptr_array_add (args, g_strdup ("--command"));
               
               flattened = g_strjoinv (" ", (char**) override_command);
-              argv[i] = flattened;
-              ++i;
+              g_ptr_array_add (args, flattened);
             }
 
           title = terminal_screen_get_dynamic_title (screen);
           if (title)
             {
-              argv[i] = g_strdup ("--title");
-              ++i;
-              argv[i] = g_strdup (title);
-              ++i;
+              g_ptr_array_add (args, g_strdup ("--title"));
+              g_ptr_array_add (args, g_strdup (title));
             }
 
           {
             const char *dir;
 
             dir = terminal_screen_get_working_dir (screen);
 
             if (dir != NULL && *dir != '\0') /* should always be TRUE anyhow */
               {
-                argv[i] = g_strdup ("--working-directory");
-                ++i;
-                argv[i] = g_strdup (dir);
-                ++i;
+                g_ptr_array_add (args, g_strdup ("--working-directory"));
+                g_ptr_array_add (args, g_strdup (dir));
               }
           }
 
           zoom = terminal_screen_get_font_scale (screen);
-          if (zoom < -1e-6 || zoom > 1e-6) /* if not 1.0 */
+          if (zoom < 1-1e-6 || zoom > 1+1e-6) /* if not 1.0 */
             {
               char buf[G_ASCII_DTOSTR_BUF_SIZE];
 
               g_ascii_dtostr (buf, sizeof (buf), zoom);
-              
-              argv[i] = g_strdup ("--zoom");
-              ++i;
-              argv[i] = g_strdup (buf);
-              ++i;
+              g_ptr_array_add (args, g_strdup_printf ("--zoom=%s", buf));
             }
-          
-          tmp2 = tmp2->next;
         }
       
       g_list_free (tabs);
-      
-      tmp = tmp->next;
     }
 
-  *argvp = argv;
-  *argcp = i;
+  *argcp = args->len;
+  *argvp = (char **) g_ptr_array_free (args, FALSE);
 }
 
 static gboolean
 save_yourself_callback (GnomeClient        *client,
                         gint                phase,
Index: terminal.h
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal.h,v
retrieving revision 1.21
diff -U5 -r1.21 terminal.h
--- terminal.h	1 Jan 2006 21:07:57 -0000	1.21
+++ terminal.h	28 Aug 2006 06:32:38 -0000
@@ -44,10 +44,11 @@
                                 TerminalWindow  *window,
                                 TerminalScreen  *screen,
                                 gboolean         force_menubar_state,
                                 gboolean         forced_menubar_state,
                                 gboolean         start_fullscreen,
+                                gboolean         maximized,
                                 char           **override_command,
                                 const char      *geometry,
                                 const char      *title,
                                 const char      *working_dir,
                                 const char      *role,
