Code

Made the xterm title dynamic, added configuration option xterm-title-format
authorKalle Wallin <kaw@linux.se>
Thu, 24 Jun 2004 16:12:51 +0000 (16:12 +0000)
committerKalle Wallin <kaw@linux.se>
Thu, 24 Jun 2004 16:12:51 +0000 (16:12 +0000)
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@1648 09075e82-0dd4-0310-85a5-a0d7c8717e4f

src/main.c

index f42a2b01c7f221514181a28b2639a6e6e9c3892e..bc607da81ab74134a14c327f371feeeabd151761 100644 (file)
@@ -34,8 +34,9 @@
 #include "command.h"
 #include "screen.h"
 #include "screen_utils.h"
+#include "strfsong.h"
 
-#define BUFSIZE 256
+#define BUFSIZE 1024
 
 static mpdclient_t   *mpd = NULL;
 static gboolean connected = FALSE;
@@ -78,6 +79,35 @@ error_callback(mpdclient_t *c, gint error, gchar *msg)
     }
 }
 
+static void
+update_xterm_title(void)
+{
+  static char title[BUFSIZE];
+  char tmp[BUFSIZE];
+  mpd_Status *status = NULL;
+  mpd_Song *song = NULL;
+
+  if( mpd )
+    {
+      status = mpd->status;
+      song = mpd->song;
+    }
+
+  if(options.xterm_title_format && status && song && IS_PLAYING(status->state))
+    {
+      strfsong(tmp, BUFSIZE, options.xterm_title_format, song);
+    }
+  else
+    strncpy(tmp, PACKAGE " version " VERSION, BUFSIZE);
+
+  if( strcmp(title,tmp) )
+    {
+      strncpy(title, tmp, BUFSIZE);
+      fprintf(stderr, "%s\n", title);
+      set_xterm_title(title);
+    }
+}
+
 void
 exit_and_cleanup(void)
 {
@@ -164,9 +194,6 @@ main(int argc, const char *argv[])
       exit(EXIT_FAILURE);
     }
 
-  /* set xterm title */
-  set_xterm_title(PACKAGE " version " VERSION);
-
   /* install exit function */
   atexit(exit_and_cleanup);
 
@@ -259,7 +286,8 @@ main(int argc, const char *argv[])
            }     
          doupdate();
        }
-
+      if( options->enable_xterm_title )
+       update_xterm_title();
       t = g_timer_elapsed(timer, NULL);
     }
   exit(EXIT_FAILURE);