[Xfce4-commits] [apps/xfce4-terminal] 01/01: Allow per-tab configuration for initial title and dynamic title mode

noreply at xfce.org noreply at xfce.org
Tue Jun 6 17:37:27 CEST 2017


This is an automated email from the git hooks/post-receive script.

f   2   4   0   4       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository apps/xfce4-terminal.

commit 494ad2787d6a08d117bd0f02896e6a0f126f8272
Author: Igor <f2404 at yandex.ru>
Date:   Tue Jun 6 11:36:07 2017 -0400

    Allow per-tab configuration for initial title and dynamic title mode
    
    Fixes https://bugzilla.xfce.org/show_bug.cgi?id=2908
---
 terminal/main.c                 |  7 ++++-
 terminal/terminal-app.c         |  8 +----
 terminal/terminal-options.c     | 42 +++++++++++++++++++++++++
 terminal/terminal-options.h     | 11 ++++---
 terminal/terminal-preferences.h |  3 +-
 terminal/terminal-screen.c      | 70 +++++++++++++++++++++++++----------------
 terminal/terminal-screen.h      |  6 ++--
 7 files changed, 103 insertions(+), 44 deletions(-)

diff --git a/terminal/main.c b/terminal/main.c
index de0410e..6a8f233 100644
--- a/terminal/main.c
+++ b/terminal/main.c
@@ -118,12 +118,17 @@ usage (void)
 
   g_print ("%s:\n"
            "  -x, --execute; -e, --command=%s; -T, --title=%s;\n"
-           "  --working-directory=%s; -H, --hold\n\n",
+           "  --dynamic-title-mode=%s ('replace', 'before', 'after', 'none');\n"
+           "  --initial-title=%s; --working-directory=%s; -H, --hold\n\n",
            _("Tab Options"),
            /* parameter of --command */
            _("command"),
            /* parameter of --title */
            _("title"),
+           /* parameter of --dynamic-title-mode */
+           _("mode"),
+           /* parameter of --initial-title */
+           _("title"),
            /* parameter of --working-directory */
            _("directory"));
 
diff --git a/terminal/terminal-app.c b/terminal/terminal-app.c
index 6d3dbf6..fd8b4ea 100644
--- a/terminal/terminal-app.c
+++ b/terminal/terminal-app.c
@@ -676,7 +676,6 @@ static void
 terminal_app_open_window (TerminalApp        *app,
                           TerminalWindowAttr *attr)
 {
-  TerminalTabAttr *tab_attr = NULL;
   GtkWidget       *window;
   TerminalScreen  *terminal;
   GdkScreen       *screen;
@@ -858,14 +857,9 @@ terminal_app_open_window (TerminalApp        *app,
   /* add the tabs */
   for (lp = attr->tabs; lp != NULL; lp = lp->next)
     {
-      tab_attr = lp->data;
-      terminal = terminal_screen_new (tab_attr->command,
-                                      tab_attr->directory,
-                                      tab_attr->title,
-                                      tab_attr->hold,
+      terminal = terminal_screen_new ((TerminalTabAttr *) lp->data,
                                       width,
                                       height);
-
       terminal_window_add (TERMINAL_WINDOW (window), terminal);
       terminal_screen_launch_child (terminal);
     }
diff --git a/terminal/terminal-options.c b/terminal/terminal-options.c
index c7c9a31..600c2b8 100644
--- a/terminal/terminal-options.c
+++ b/terminal/terminal-options.c
@@ -136,6 +136,7 @@ terminal_tab_attr_free (TerminalTabAttr *attr)
   g_strfreev (attr->command);
   g_free (attr->directory);
   g_free (attr->title);
+  g_free (attr->initial_title);
   g_slice_free (TerminalTabAttr, attr);
 }
 
@@ -306,6 +307,46 @@ terminal_window_attr_parse (gint              argc,
               tab_attr->title = g_strdup (s);
             }
         }
+      else if (terminal_option_cmp ("dynamic-title-mode", 0, argc, argv, &n, &s))
+        {
+          if (G_UNLIKELY (s == NULL))
+            {
+              g_set_error (error, G_SHELL_ERROR, G_SHELL_ERROR_FAILED,
+                           _("Option \"--dynamic-title-mode\" requires specifying "
+                             "the dynamic title mode as its parameter"));
+              goto failed;
+            }
+          else if (g_ascii_strcasecmp (s, "replace") == 0)
+            tab_attr->dynamic_title_mode = TERMINAL_TITLE_REPLACE;
+          else if (g_ascii_strcasecmp (s, "before") == 0)
+            tab_attr->dynamic_title_mode = TERMINAL_TITLE_PREPEND;
+          else if (g_ascii_strcasecmp (s, "after") == 0)
+            tab_attr->dynamic_title_mode = TERMINAL_TITLE_APPEND;
+          else if (g_ascii_strcasecmp (s, "none") == 0)
+            tab_attr->dynamic_title_mode = TERMINAL_TITLE_HIDE;
+          else
+            {
+              g_set_error (error, G_SHELL_ERROR, G_SHELL_ERROR_FAILED,
+                           _("Invalid argument for option \"--dynamic-title\": "
+                             "%s"), s);
+              goto failed;
+            }
+        }
+      else if (terminal_option_cmp ("initial-title", 0, argc, argv, &n, &s))
+        {
+          if (G_UNLIKELY (s == NULL))
+            {
+              g_set_error (error, G_SHELL_ERROR, G_SHELL_ERROR_FAILED,
+                           _("Option \"--initial-title\" requires specifying "
+                             "the initial title as its parameter"));
+              goto failed;
+            }
+          else
+            {
+              g_free (tab_attr->initial_title);
+              tab_attr->initial_title = g_strdup (s);
+            }
+        }
       else if (terminal_option_cmp ("hold", 'H', argc, argv, &n, NULL))
         {
           tab_attr->hold = TRUE;
@@ -564,6 +605,7 @@ terminal_window_attr_new (void)
   win_attr->zoom = TERMINAL_ZOOM_LEVEL_DEFAULT;
 
   tab_attr = g_slice_new0 (TerminalTabAttr);
+  tab_attr->dynamic_title_mode = TERMINAL_TITLE_DEFAULT;
   win_attr->tabs = g_slist_prepend (NULL, tab_attr);
 
   return win_attr;
diff --git a/terminal/terminal-options.h b/terminal/terminal-options.h
index 91e7a92..05c97b3 100644
--- a/terminal/terminal-options.h
+++ b/terminal/terminal-options.h
@@ -21,6 +21,7 @@
 #define TERMINAL_OPTIONS_H
 
 #include <glib.h>
+#include <terminal/terminal-preferences.h>
 
 G_BEGIN_DECLS
 
@@ -53,10 +54,12 @@ typedef enum
 
 typedef struct
 {
-  gchar    **command;
-  gchar     *directory;
-  gchar     *title;
-  guint      hold : 1;
+  gchar       **command;
+  gchar        *directory;
+  gchar        *title;
+  gchar        *initial_title;
+  TerminalTitle dynamic_title_mode;
+  guint         hold : 1;
 } TerminalTabAttr;
 
 typedef struct
diff --git a/terminal/terminal-preferences.h b/terminal/terminal-preferences.h
index 26ca2f5..d90575c 100644
--- a/terminal/terminal-preferences.h
+++ b/terminal/terminal-preferences.h
@@ -46,7 +46,8 @@ typedef enum /*< enum,prefix=TERMINAL_TITLE >*/
   TERMINAL_TITLE_REPLACE,
   TERMINAL_TITLE_PREPEND,
   TERMINAL_TITLE_APPEND,
-  TERMINAL_TITLE_HIDE
+  TERMINAL_TITLE_HIDE,
+  TERMINAL_TITLE_DEFAULT
 } TerminalTitle;
 
 typedef enum /*< enum,prefix=TERMINAL_BACKGROUND >*/
diff --git a/terminal/terminal-screen.c b/terminal/terminal-screen.c
index e300e0a..81be30e 100644
--- a/terminal/terminal-screen.c
+++ b/terminal/terminal-screen.c
@@ -172,7 +172,9 @@ struct _TerminalScreen
 
   gchar              **custom_command;
   gchar               *custom_title;
+  gchar               *initial_title;
 
+  TerminalTitle        dynamic_title_mode;
   guint                hold : 1;
 
   guint                activity_timeout_id;
@@ -257,6 +259,7 @@ terminal_screen_init (TerminalScreen *screen)
 {
   screen->loader = NULL;
   screen->working_directory = g_get_current_dir ();
+  screen->dynamic_title_mode = TERMINAL_TITLE_DEFAULT;
   screen->session_id = ++screen_last_session_id;
 
   screen->terminal = g_object_new (TERMINAL_TYPE_WIDGET, NULL);
@@ -336,6 +339,7 @@ terminal_screen_finalize (GObject *object)
   g_strfreev (screen->custom_command);
   g_free (screen->working_directory);
   g_free (screen->custom_title);
+  g_free (screen->initial_title);
 
   (*G_OBJECT_CLASS (terminal_screen_parent_class)->finalize) (object);
 }
@@ -372,11 +376,18 @@ terminal_screen_get_property (GObject          *object,
         }
       else
         {
-          g_object_get (G_OBJECT (screen->preferences), "title-mode", &mode, NULL);
+          if (G_UNLIKELY (screen->dynamic_title_mode != TERMINAL_TITLE_DEFAULT))
+            mode = screen->dynamic_title_mode;
+          else
+            g_object_get (G_OBJECT (screen->preferences), "title-mode", &mode, NULL);
+
           if (G_UNLIKELY (mode == TERMINAL_TITLE_HIDE))
             {
               /* show the initial title if the dynamic title is set to hidden */
-              g_object_get (G_OBJECT (screen->preferences), "title-initial", &initial, NULL);
+              if (G_UNLIKELY (screen->initial_title != NULL))
+                initial = g_strdup (screen->initial_title);
+              else
+                g_object_get (G_OBJECT (screen->preferences), "title-initial", &initial, NULL);
               parsed_title = terminal_screen_parse_title (screen, initial);
               title = parsed_title;
               g_free (initial);
@@ -1547,32 +1558,29 @@ terminal_screen_set_custom_command (TerminalScreen *screen,
 
 /**
  * terminal_screen_new:
- * @command   : Command.
- * @directory : Working directory.
- * @title     : Terminal title.
- * @hold      : Whether to hold the terminal after child exits.
- * @columns   : Columns (width).
- * @rows      : Rows (height).
+ * @attr    : Terminal attributes.
+ * @columns : Columns (width).
+ * @rows    : Rows (height).
  *
  * Creates a terminal screen object.
  **/
 TerminalScreen *
-terminal_screen_new (gchar    **command,
-                     gchar     *directory,
-                     gchar     *title,
-                     gboolean   hold,
-                     glong      columns,
-                     glong      rows)
+terminal_screen_new (TerminalTabAttr *attr,
+                     glong            columns,
+                     glong            rows)
 {
   TerminalScreen *screen = g_object_new (TERMINAL_TYPE_SCREEN, NULL);
 
-  if (command != NULL)
-    terminal_screen_set_custom_command (screen, command);
-  if (directory != NULL)
-    terminal_screen_set_working_directory (screen, directory);
-  if (title != NULL)
-    terminal_screen_set_custom_title (screen, title);
-  screen->hold = hold;
+  if (attr->command != NULL)
+    terminal_screen_set_custom_command (screen, attr->command);
+  if (attr->directory != NULL)
+    terminal_screen_set_working_directory (screen, attr->directory);
+  if (attr->title != NULL)
+    terminal_screen_set_custom_title (screen, attr->title);
+  if (attr->initial_title != NULL)
+    screen->initial_title = g_strdup (attr->initial_title);
+  screen->dynamic_title_mode = attr->dynamic_title_mode;
+  screen->hold = attr->hold;
   vte_terminal_set_size (VTE_TERMINAL (screen->terminal), columns, rows);
 
   return screen;
@@ -1902,12 +1910,20 @@ terminal_screen_get_title (TerminalScreen *screen)
     return terminal_screen_parse_title (screen, screen->custom_title);
 
   vte_title = vte_terminal_get_window_title (VTE_TERMINAL (screen->terminal));
-  g_object_get (G_OBJECT (screen->preferences),
-                "title-mode", &mode,
-                "title-initial", &tmp,
-                NULL);
-  initial = terminal_screen_parse_title (screen, tmp);
-  g_free (tmp);
+
+  if (G_UNLIKELY (screen->initial_title != NULL))
+    initial = terminal_screen_parse_title (screen, screen->initial_title);
+  else
+    {
+      g_object_get (G_OBJECT (screen->preferences), "title-initial", &tmp, NULL);
+      initial = terminal_screen_parse_title (screen, tmp);
+      g_free (tmp);
+    }
+
+  if (G_UNLIKELY (screen->dynamic_title_mode != TERMINAL_TITLE_DEFAULT))
+    mode = screen->dynamic_title_mode;
+  else
+    g_object_get (G_OBJECT (screen->preferences), "title-mode", &mode, NULL);
 
   switch (mode)
     {
diff --git a/terminal/terminal-screen.h b/terminal/terminal-screen.h
index 6e68dfc..2cafce1 100644
--- a/terminal/terminal-screen.h
+++ b/terminal/terminal-screen.h
@@ -22,6 +22,7 @@
 
 #include <gtk/gtk.h>
 #include <terminal/terminal-private.h>
+#include <terminal/terminal-options.h>
 
 G_BEGIN_DECLS
 
@@ -37,10 +38,7 @@ typedef struct _TerminalScreen      TerminalScreen;
 
 GType           terminal_screen_get_type                  (void) G_GNUC_CONST;
 
-TerminalScreen *terminal_screen_new                       (gchar         **command,
-                                                           gchar          *directory,
-                                                           gchar           *title,
-                                                           gboolean         hold,
+TerminalScreen *terminal_screen_new                       (TerminalTabAttr *attr,
                                                            glong            columns,
                                                            glong            rows);
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list