[Xfce4-commits] <terminal:master> Allow re-using of last window with --tab.

Nick Schermer noreply at xfce.org
Tue Dec 25 16:14:02 CET 2012


Updating branch refs/heads/master
         to cfd38dba452380c76ddfc3b73724e05a9b1d2b9a (commit)
       from 1db926495fb9020ec01f28fd6eb32a8e24e07dbc (commit)

commit cfd38dba452380c76ddfc3b73724e05a9b1d2b9a
Author: Nick Schermer <nick at xfce.org>
Date:   Tue Dec 25 16:12:51 2012 +0100

    Allow re-using of last window with --tab.

 doc/xfce4-terminal.1.xml    |    1 +
 terminal/terminal-app.c     |   64 +++++++++++++++++++++++++++----------------
 terminal/terminal-options.c |   19 +++++++++++-
 terminal/terminal-options.h |    8 +++--
 4 files changed, 63 insertions(+), 29 deletions(-)

diff --git a/doc/xfce4-terminal.1.xml b/doc/xfce4-terminal.1.xml
index 16d711c..bc82d5b 100644
--- a/doc/xfce4-terminal.1.xml
+++ b/doc/xfce4-terminal.1.xml
@@ -209,6 +209,7 @@
           </term>
           <listitem>
             <para>Open a new tab in the last-specified window; more than one of these options can be provided.</para>
+            <para>If you use this as the first option, without --window separators, the last window will be re-used.</para>
           </listitem>
         </varlistentry>
 
diff --git a/terminal/terminal-app.c b/terminal/terminal-app.c
index c14b7c7..f3e72cc 100644
--- a/terminal/terminal-app.c
+++ b/terminal/terminal-app.c
@@ -527,36 +527,48 @@ terminal_app_open_window (TerminalApp        *app,
   GdkScreen       *screen;
   gchar           *geometry;
   GSList          *lp;
+  gboolean         reuse_window = FALSE;
 
   terminal_return_if_fail (TERMINAL_IS_APP (app));
   terminal_return_if_fail (attr != NULL);
 
-  window = terminal_app_create_window (app,
-                                       attr->fullscreen,
-                                       attr->menubar,
-                                       attr->borders,
-                                       attr->toolbars);
-
-  if (attr->role != NULL)
-    gtk_window_set_role (GTK_WINDOW (window), attr->role);
-  if (attr->startup_id != NULL)
-    gtk_window_set_startup_id (GTK_WINDOW (window), attr->startup_id);
-  if (attr->maximize)
-    gtk_window_maximize (GTK_WINDOW (window));
-
-  if (attr->icon != NULL)
+  if (attr->reuse_last_window
+      && app->windows != NULL)
     {
-      if (g_path_is_absolute (attr->icon))
-        gtk_window_set_icon_from_file (GTK_WINDOW (window), attr->icon, NULL);
-      else
-        gtk_window_set_icon_name (GTK_WINDOW (window), attr->icon);
+      /* open the tabs in an existing window */
+      window = app->windows->data;
+      reuse_window = TRUE;
     }
-
-  screen = terminal_app_find_screen (attr->display);
-  if (G_LIKELY (screen != NULL))
+  else
     {
-      gtk_window_set_screen (GTK_WINDOW (window), screen);
-      g_object_unref (G_OBJECT (screen));
+      /* create new window */
+      window = terminal_app_create_window (app,
+                                           attr->fullscreen,
+                                           attr->menubar,
+                                           attr->borders,
+                                           attr->toolbars);
+
+      if (attr->role != NULL)
+        gtk_window_set_role (GTK_WINDOW (window), attr->role);
+      if (attr->startup_id != NULL)
+        gtk_window_set_startup_id (GTK_WINDOW (window), attr->startup_id);
+      if (attr->maximize)
+        gtk_window_maximize (GTK_WINDOW (window));
+
+      if (attr->icon != NULL)
+        {
+          if (g_path_is_absolute (attr->icon))
+            gtk_window_set_icon_from_file (GTK_WINDOW (window), attr->icon, NULL);
+          else
+            gtk_window_set_icon_name (GTK_WINDOW (window), attr->icon);
+        }
+
+      screen = terminal_app_find_screen (attr->display);
+      if (G_LIKELY (screen != NULL))
+        {
+          gtk_window_set_screen (GTK_WINDOW (window), screen);
+          g_object_unref (G_OBJECT (screen));
+        }
     }
 
   for (lp = attr->tabs; lp != NULL; lp = lp->next)
@@ -577,6 +589,10 @@ terminal_app_open_window (TerminalApp        *app,
       terminal_screen_launch_child (TERMINAL_SCREEN (terminal));
     }
 
+  /* don't apply other attributes to teh window when reusing */
+  if (reuse_window)
+    return;
+
   /* set the window geometry, this can only be set after one of the tabs
    * has been added, because vte is the geometry widget, so atleast one
    * call should have been made to terminal_screen_set_window_geometry_hints */
@@ -627,7 +643,7 @@ terminal_app_process (TerminalApp  *app,
 {
   GSList *attrs, *lp;
 
-  attrs = terminal_window_attr_parse (argc, argv, error);
+  attrs = terminal_window_attr_parse (argc, argv, app->windows != NULL, error);
   if (G_UNLIKELY (attrs == NULL))
     return FALSE;
 
diff --git a/terminal/terminal-options.c b/terminal/terminal-options.c
index 91fd9e0..332d22b 100644
--- a/terminal/terminal-options.c
+++ b/terminal/terminal-options.c
@@ -183,6 +183,7 @@ terminal_options_parse (gint       argc,
 GSList *
 terminal_window_attr_parse (gint              argc,
                             gchar           **argv,
+                            gboolean          can_reuse_tab,
                             GError          **error)
 {
   TerminalWindowAttr *win_attr;
@@ -401,11 +402,24 @@ terminal_window_attr_parse (gint              argc,
         }
       else if (terminal_option_cmp ("tab", 0, argc, argv, &n, NULL))
         {
-          tab_attr = g_slice_new0 (TerminalTabAttr);
-          win_attr->tabs = g_slist_append (win_attr->tabs, tab_attr);
+          if (n == 4 && can_reuse_tab)
+            {
+              /* tab is the first user option, reuse existing window */
+              win_attr->reuse_last_window = TRUE;
+            }
+          else
+            {
+              /* add new tab */
+              tab_attr = g_slice_new0 (TerminalTabAttr);
+              win_attr->tabs = g_slist_append (win_attr->tabs, tab_attr);
+            }
         }
       else if (terminal_option_cmp ("window", 0, argc, argv, &n, NULL))
         {
+          /* multiple windows, don't reuse */
+          win_attr->reuse_last_window = FALSE;
+
+          /* setup new window */
           win_attr = terminal_window_attr_new ();
           tab_attr = win_attr->tabs->data;
           attrs = g_slist_append (attrs, win_attr);
@@ -445,6 +459,7 @@ unknown_option:
             win_attr->display = g_strdup (default_display);
         }
     }
+
   g_free (default_directory);
   g_free (default_display);
 
diff --git a/terminal/terminal-options.h b/terminal/terminal-options.h
index 98d06ca..b8d4074 100644
--- a/terminal/terminal-options.h
+++ b/terminal/terminal-options.h
@@ -41,7 +41,7 @@ struct _TerminalTabAttr
   gchar    **command;
   gchar     *directory;
   gchar     *title;
-  gboolean   hold;
+  guint      hold : 1;
 };
 
 struct _TerminalWindowAttr
@@ -52,11 +52,12 @@ struct _TerminalWindowAttr
   gchar               *role;
   gchar               *startup_id;
   gchar               *icon;
-  gboolean             fullscreen;
+  guint                fullscreen : 1;
   TerminalVisibility   menubar;
   TerminalVisibility   borders;
   TerminalVisibility   toolbars;
-  gboolean             maximize;
+  guint                maximize : 1;
+  guint                reuse_last_window : 1;
 };
 
 void                terminal_options_parse     (gint                 argc,
@@ -68,6 +69,7 @@ void                terminal_options_parse     (gint                 argc,
 
 GSList             *terminal_window_attr_parse (gint                 argc,
                                                 gchar              **argv,
+                                                gboolean             can_reuse_tab,
                                                 GError             **error);
 
 TerminalWindowAttr *terminal_window_attr_new   (void);


More information about the Xfce4-commits mailing list