From 36e34a3c8d8256a19eb60151d0072374da3f3a9d Mon Sep 17 00:00:00 2001 From: Phil Date: Mon, 1 Sep 2008 22:30:54 +0000 Subject: [PATCH] enable max length argument for mpd_smart * this also fixes mpd_title for changing lengths, e.g. ${mpd_title 2} ${mpd_title 3} ${mpd_title 4} git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@1241 7f574dfc-610e-0410-a909-a81674777703 --- README | 2 +- doc/conky.1 | 4 ++-- doc/variables.xml | 1 + src/conky.c | 37 ++++++++++++++++++++++++++----------- src/mpd.h | 1 - 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/README b/README index d296ae36..112a8f12 100644 --- a/README +++ b/README @@ -1144,7 +1144,7 @@ conky(1) conky(1) Prints the file name of the current MPD song - 1mmpd_smart0m + 1mmpd_smart (max length)0m Prints the song name in either the form "artist - title" or file name, depending on whats available diff --git a/doc/conky.1 b/doc/conky.1 index a4ec04f0..b78db2b6 100644 --- a/doc/conky.1 +++ b/doc/conky.1 @@ -1,4 +1,4 @@ -.\" -*- coding: us-ascii -*- +'\" -*- coding: us-ascii -*- .if \n(.g .ds T< \\FC .if \n(.g .ds T> \\F[\n[.fam]] .de URL @@ -977,7 +977,7 @@ Prints the MPD name field Prints the file name of the current MPD song .TP -\fB\*(T<\fBmpd_smart\fR\*(T>\fR +\fB\*(T<\fBmpd_smart\fR\*(T>\fR \*(T<\fB(max length)\fR\*(T> Prints the song name in either the form "artist - title" or file name, depending on whats available .TP diff --git a/doc/variables.xml b/doc/variables.xml index 147cb785..d8df26e8 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -1406,6 +1406,7 @@ + Prints the song name in either the form "artist - title" or file name, depending on whats available diff --git a/src/conky.c b/src/conky.c index 7324accf..00a24d53 100644 --- a/src/conky.c +++ b/src/conky.c @@ -3793,14 +3793,14 @@ static struct text_object *construct_text_object(const char *s, END OBJ_THREAD(mpd_artist, INFO_MPD) END OBJ_THREAD(mpd_title, INFO_MPD) if (arg) { - sscanf(arg, "%d", &info.mpd.max_title_len); - if (info.mpd.max_title_len > 0) { - info.mpd.max_title_len++; + sscanf(arg, "%d", &obj->data.i); + if (obj->data.i > 0) { + obj->data.i++; } else { CRIT_ERR("mpd_title: invalid length argument"); } } else { - info.mpd.max_title_len = 0; + obj->data.i = 0; } END OBJ_THREAD(mpd_random, INFO_MPD) END OBJ_THREAD(mpd_repeat, INFO_MPD) @@ -3817,6 +3817,16 @@ static struct text_object *construct_text_object(const char *s, END OBJ_THREAD(mpd_bar, INFO_MPD) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b); END OBJ_THREAD(mpd_smart, INFO_MPD) + if (arg) { + sscanf(arg, "%d", &obj->data.i); + if (obj->data.i > 0) { + obj->data.i++; + } else { + CRIT_ERR("mpd_smart: invalid length argument"); + } + } else { + obj->data.i = 0; + } #endif /* MPD */ #ifdef XMMS2 END OBJ(xmms2_artist, INFO_XMMS2) @@ -5690,9 +5700,10 @@ static void generate_text_internal(char *p, int p_max_size, #ifdef MPD OBJ(mpd_title) { - snprintf(p, cur->mpd.max_title_len > 0 - ? cur->mpd.max_title_len : p_max_size, "%s", - cur->mpd.title); + int len = obj->data.i; + if (len == 0 || len > p_max_size) + len = p_max_size; + snprintf(p, len, "%s", cur->mpd.title); } OBJ(mpd_artist) { snprintf(p, p_max_size, "%s", cur->mpd.artist); @@ -5739,17 +5750,21 @@ static void generate_text_internal(char *p, int p_max_size, (int) (cur->mpd.progress * 255.0f)); } OBJ(mpd_smart) { + int len = obj->data.i; + if (len == 0 || len > p_max_size) + len = p_max_size; + memset(p, 0, p_max_size); if (cur->mpd.artist && *cur->mpd.artist && cur->mpd.title && *cur->mpd.title) { - snprintf(p, p_max_size, "%s - %s", cur->mpd.artist, + snprintf(p, len, "%s - %s", cur->mpd.artist, cur->mpd.title); } else if (cur->mpd.title && *cur->mpd.title) { - snprintf(p, p_max_size, "%s", cur->mpd.title); + snprintf(p, len, "%s", cur->mpd.title); } else if (cur->mpd.artist && *cur->mpd.artist) { - snprintf(p, p_max_size, "%s", cur->mpd.artist); + snprintf(p, len, "%s", cur->mpd.artist); } else if (cur->mpd.file && *cur->mpd.file) { - snprintf(p, p_max_size, "%s", cur->mpd.file); + snprintf(p, len, "%s", cur->mpd.file); } else { *p = 0; } diff --git a/src/mpd.h b/src/mpd.h index e728775f..7f8412fa 100644 --- a/src/mpd.h +++ b/src/mpd.h @@ -26,7 +26,6 @@ struct mpd_s { int bitrate; int length; int elapsed; - int max_title_len; /* e.g. ${mpd_title 50} */ mpd_Connection *conn; timed_thread *timed_thread; };