From 11d0bf3e6e4128a8afb3dd92dbf5c2adca74f642 Mon Sep 17 00:00:00 2001 From: Kalle Wallin Date: Thu, 24 Jun 2004 16:12:51 +0000 Subject: Made the xterm title dynamic, added configuration option xterm-title-format git-svn-id: https://svn.musicpd.org/ncmpc/trunk@1648 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/main.c | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index f42a2b01c..bc607da81 100644 --- a/src/main.c +++ b/src/main.c @@ -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); -- cgit v1.2.3