[gnome-terminal] screen: Allow getting the name of the current foreground process



commit 389d0aede9b5fee0362c869938ffdbfb8b6a5c0d
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Dec 6 17:41:10 2013 +0100

    screen: Allow getting the name of the current foreground process
    
    This would be useful in searching based on the current foreground
    process.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=711075

 src/terminal-screen.c |   21 +++++++++------------
 src/terminal-screen.h |    3 ++-
 src/terminal-window.c |    4 ++--
 3 files changed, 13 insertions(+), 15 deletions(-)
---
diff --git a/src/terminal-screen.c b/src/terminal-screen.c
index 23e4c8e..a2c7dad 100644
--- a/src/terminal-screen.c
+++ b/src/terminal-screen.c
@@ -1951,6 +1951,7 @@ terminal_screen_check_match (TerminalScreen *screen,
 /**
  * terminal_screen_has_foreground_process:
  * @screen:
+ * @process_name: (out) (allow-none): the basename of the program, or %NULL
  *
  * Checks whether there's a foreground process running in
  * this terminal.
@@ -1958,9 +1959,15 @@ terminal_screen_check_match (TerminalScreen *screen,
  * Returns: %TRUE iff there's a foreground process running in @screen
  */
 gboolean
-terminal_screen_has_foreground_process (TerminalScreen *screen)
+terminal_screen_has_foreground_process (TerminalScreen *screen,
+                                        char           **process_name)
 {
   TerminalScreenPrivate *priv = screen->priv;
+  gs_free char *cmdline = NULL;
+  gs_free char *basename = NULL;
+  gs_free char *name = NULL;
+  char filename[64];
+  gsize len;
   int fgpid;
 
   if (priv->pty_fd == -1)
@@ -1970,32 +1977,22 @@ terminal_screen_has_foreground_process (TerminalScreen *screen)
   if (fgpid == -1 || fgpid == priv->child_pid)
     return FALSE;
 
-  return TRUE;
-
-#if 0
-  char *cmdline, *basename, *name;
-  gsize len;
-  char filename[64];
-
   g_snprintf (filename, sizeof (filename), "/proc/%d/cmdline", fgpid);
   if (!g_file_get_contents (filename, &cmdline, &len, NULL))
     return TRUE;
 
   basename = g_path_get_basename (cmdline);
-  g_free (cmdline);
   if (!basename)
     return TRUE;
 
   name = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL);
-  g_free (basename);
   if (!name)
     return TRUE;
 
   if (process_name)
-    *process_name = name;
+    gs_transfer_out_value (process_name, &name);
 
   return TRUE;
-#endif
 }
 
 const char *
diff --git a/src/terminal-screen.h b/src/terminal-screen.h
index fd4ea75..03f6e99 100644
--- a/src/terminal-screen.h
+++ b/src/terminal-screen.h
@@ -133,7 +133,8 @@ void terminal_screen_save_config (TerminalScreen *screen,
 
 void terminal_screen_update_style (TerminalScreen *screen);
 
-gboolean terminal_screen_has_foreground_process (TerminalScreen *screen);
+gboolean terminal_screen_has_foreground_process (TerminalScreen *screen,
+                                                 char           **process_name);
 
 /* Allow scales a bit smaller and a bit larger than the usual pango ranges */
 #define TERMINAL_SCALE_XXX_SMALL   (PANGO_SCALE_XX_SMALL/1.2)
diff --git a/src/terminal-window.c b/src/terminal-window.c
index 00915ce..4176f86 100644
--- a/src/terminal-window.c
+++ b/src/terminal-window.c
@@ -3532,7 +3532,7 @@ confirm_close_window_or_tab (TerminalWindow *window,
 
   if (screen)
     {
-      do_confirm = terminal_screen_has_foreground_process (screen);
+      do_confirm = terminal_screen_has_foreground_process (screen, NULL);
       n_tabs = 1;
     }
   else
@@ -3549,7 +3549,7 @@ confirm_close_window_or_tab (TerminalWindow *window,
           TerminalScreen *terminal_screen;
 
           terminal_screen = terminal_screen_container_get_screen (TERMINAL_SCREEN_CONTAINER (t->data));
-          if (terminal_screen_has_foreground_process (terminal_screen))
+          if (terminal_screen_has_foreground_process (terminal_screen, NULL))
             {
               do_confirm = TRUE;
               break;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]