1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-25 04:06:03 +00:00

xmms/bmp/audacious/infopipe reorgamization

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@487 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Philip Kovacs 2006-01-08 08:02:37 +00:00
parent ed34f5d401
commit 6d24365953
9 changed files with 451 additions and 469 deletions

90
README
View File

@ -4,16 +4,16 @@ conky(1) conky(1)
NAME NAME
conky - A system monitor for X originally based on the torsmo code, but conky - A system monitor for X originally based on the torsmo code, but
more kickass. It just keeps on given'er. Yeah. more kickass. It just keeps on givener. Yeah.
SYNOPSIS SYNOPSIS
conky [options] conky [options]
DESCRIPTION DESCRIPTION
Conky is a system monitor for X originally based on the torsmo code. Conky is a system monitor for X originally based on the torsmo code.
Since it's original conception, Conky has changed a fair bit from it's Since its original conception, Conky has changed a fair bit from its
predecessor. Conky can display just about anything, either on your predecessor. Conky can display just about anything, either on your
root desktop or in it's own window. Conky has many built-in objects, root desktop or in its own window. Conky has many built-in objects,
as well as the ability to execute programs and scripts, then display as well as the ability to execute programs and scripts, then display
the output from stdout. the output from stdout.
@ -28,11 +28,11 @@ COMPILING
libraries installed. This should be a package along the lines of libraries installed. This should be a package along the lines of
"libx11-dev or xorg-x11-dev". "libx11-dev or xorg-x11-dev".
Gentoo users -- Conky is in Gentoo's Portage... simply use "emerge app- Gentoo users -- Conky is in Gentoos Portage... simply use "emerge app-
admin/conky" for installation. There is also usually an up-to-date admin/conky" for installation. There is also usually an up-to-date
ebuild within Conky's package or in CVS. ebuild within Conkys package or in CVS.
Debian,etc. users -- Conky will be in Debian's repositories soon (by Debian,etc. users -- Conky will be in Debians repositories soon (by
mid-September, hopefully), and then Ubuntu shortly thereafter. Until mid-September, hopefully), and then Ubuntu shortly thereafter. Until
then, "dpkg -i" the .deb package to install. then, "dpkg -i" the .deb package to install.
@ -43,7 +43,7 @@ COMPILING
./configure --prefix=/usr --mandir=/usr/share/man ./configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --datadir=/usr/share --sysconfdir=/etc --infodir=/usr/share/info --datadir=/usr/share --sysconfdir=/etc
--localstatedir=/var/lib --enable-xft --enable-seti --enable-dou- --localstatedir=/var/lib --enable-xft --enable-seti --enable-dou
ble-buffer --enable-own-window --enable-proc-uptime --enable-mpd ble-buffer --enable-own-window --enable-proc-uptime --enable-mpd
--enable-mldonkey --enable-x11 --enable-portmon --enable-bmpx --enable-mldonkey --enable-x11 --enable-portmon --enable-bmpx
--enable-infopipe --enable-infopipe
@ -54,14 +54,14 @@ COMPILING
src/conky src/conky
Conky probably doesn't compile with compilers other than gcc and icc. Conky probably doesnt compile with compilers other than gcc and icc.
It doesn't compile with C89 compiler and not even with pure C99. It It doesnt compile with C89 compiler and not even with pure C99. It
uses a few things that might not exist: strdup(), strcasecmp(), strn- uses a few things that might not exist: strdup(), strcasecmp(), strn
casecmp(), optarg variable with getopt() and long long (not in C89). casecmp(), optarg variable with getopt() and long long (not in C89).
Crashes in file system statistics stuff when compiled with icc, I don't Crashes in file system statistics stuff when compiled with icc, I dont
know exactly why. know exactly why.
You can disable 'drawing to own window' feature in case you don't need You can disable drawing to own window feature in case you dont need
it by passing --disable-own-window to configure -script. it by passing --disable-own-window to configure -script.
@ -72,14 +72,14 @@ YOU SHOULD KNOW
rest of Conky. rest of Conky.
If you do use them, please do not complain about memory or CPU usage, If you do use them, please do not complain about memory or CPU usage,
unless you think something's seriously wrong (mem leak, etc.). unless you think somethings seriously wrong (mem leak, etc.).
An easy way to force Conky to reload your ~/.conkyrc: "killall -SIGUSR1 An easy way to force Conky to reload your ~/.conkyrc: "killall -SIGUSR1
conky". Saves you the trouble of having to kill and then restart. conky". Saves you the trouble of having to kill and then restart.
IMPORTANT: For previous Conky users, Conky 1.3 no longer supports the IMPORTANT: For previous Conky users, Conky 1.3 no longer supports the
metar stuff. mdsplib was causing way too many problems. Hopefully metar stuff. mdsplib was causing way too many problems. Hopefully
there'll be a better solution in Conky 2.x... therell be a better solution in Conky 2.x...
OPTIONS OPTIONS
Command line options override configurations defined in configuration Command line options override configurations defined in configuration
@ -114,7 +114,7 @@ OPTIONS
-t TEXT -t TEXT
Text to render, remember single quotes, like -t ' $uptime ' Text to render, remember single quotes, like -t $uptime
-u SECONDS -u SECONDS
@ -136,14 +136,14 @@ OPTIONS
CONFIGURATION SETTINGS CONFIGURATION SETTINGS
Default configuration file is $HOME/.conkyrc (can be changed from Default configuration file is $HOME/.conkyrc (can be changed from
conky.c among other things). See conkyrc.sample. If installing from conky.c among other things). See conkyrc.sample. If installing from
Debian package, this should be in /usr/share/doc/conky/examples ("gun- Debian package, this should be in /usr/share/doc/conky/examples ("gun
zip conkyrc.sample.gz" to get conkyrc.sample). zip conkyrc.sample.gz" to get conkyrc.sample).
You might want to copy it to $HOME/.conkyrc and then start modifying You might want to copy it to $HOME/.conkyrc and then start modifying
it. Other configs can be found at http://conky.sf.net it. Other configs can be found at http://conky.sf.net
alignment alignment
Aligned position on screen, may be top_left, top_right, bot- Aligned position on screen, may be top_left, top_right, bot
tom_left, bottom_right, or none tom_left, bottom_right, or none
@ -173,7 +173,7 @@ CONFIGURATION SETTINGS
default_shade_color default_shade_color
Default shading color and border's shading color Default shading color and borders shading color
default_outline_color default_outline_color
@ -181,8 +181,8 @@ CONFIGURATION SETTINGS
double_buffer double_buffer
Use the Xdbe extension? (eliminates flicker) It is highly recom- Use the Xdbe extension? (eliminates flicker) It is highly recom
mended to use own window with this one so double buffer won't be mended to use own window with this one so double buffer wont be
so big. so big.
@ -330,7 +330,7 @@ CONFIGURATION SETTINGS
VARIABLES VARIABLES
Colors are parsed using XParsecolor(), there might be a list of them: Colors are parsed using XParsecolor(), there might be a list of them:
/usr/X11R6/lib/X11/rgb.txt. Also, http://sedition.com/perl/rgb.html /usr/X11R6/lib/X11/rgb.txt. Also, http://sedition.com/perl/rgb.html
[http://sedition.com/perl/rgb.html]. Color can be also in #rrggbb for- [http://sedition.com/perl/rgb.html]. Color can be also in #rrggbb for
mat (hex). Note that when displaying bytes, power is 1024 and not 1000 mat (hex). Note that when displaying bytes, power is 1024 and not 1000
so 1M really means 1024*1024 bytes and not 1000*1000. so 1M really means 1024*1024 bytes and not 1000*1000.
@ -430,7 +430,7 @@ VARIABLES
cpubar (cpu number) (height),(width) cpubar (cpu number) (height),(width)
Bar that shows CPU usage, height is bar's height in pixels. See Bar that shows CPU usage, height is bars height in pixels. See
$cpu for more info on SMP. $cpu for more info on SMP.
@ -467,8 +467,8 @@ VARIABLES
exec command exec command
Executes a shell command and displays the output in conky. warn- Executes a shell command and displays the output in conky. warn
ing: this takes a lot more resources than other variables. I'd ing: this takes a lot more resources than other variables. Id
recommend coding wanted behaviour in C and posting a patch. recommend coding wanted behaviour in C and posting a patch.
@ -483,7 +483,7 @@ VARIABLES
execi interval command execi interval command
Same as exec but with specific interval. Interval can't be less Same as exec but with specific interval. Interval cant be less
than update_interval in configuration. See also $texeci than update_interval in configuration. See also $texeci
@ -540,7 +540,7 @@ VARIABLES
head logfile lines (interval) head logfile lines (interval)
Displays first N lines of supplied text text file. If interval Displays first N lines of supplied text text file. If interval
is not supplied, Conky assumes 2x Conky's interval. Max of 30 is not supplied, Conky assumes 2x Conkys interval. Max of 30
lines can be displayed, or until the text buffer is filled. lines can be displayed, or until the text buffer is filled.
@ -585,7 +585,7 @@ VARIABLES
i8k_left_fan_rpm i8k_left_fan_rpm
If running the i8k kernel driver for Inspiron laptops, displays If running the i8k kernel driver for Inspiron laptops, displays
the left fan's rate of rotation, in revolutions per minute as the left fans rate of rotation, in revolutions per minute as
listed in /proc/i8k. Beware, some laptops i8k reports these fans listed in /proc/i8k. Beware, some laptops i8k reports these fans
in reverse order. in reverse order.
@ -599,7 +599,7 @@ VARIABLES
i8k_right_fan_rpm i8k_right_fan_rpm
If running the i8k kernel driver for Inspiron laptops, displays If running the i8k kernel driver for Inspiron laptops, displays
the right fan's rate of rotation, in revolutions per minute as the right fans rate of rotation, in revolutions per minute as
listed in /proc/i8k. Beware, some laptops i8k reports these fans listed in /proc/i8k. Beware, some laptops i8k reports these fans
in reverse order. in reverse order.
@ -740,7 +740,7 @@ VARIABLES
mpd_bar (height),(width) mpd_bar (height),(width)
Bar of mpd's progress Bar of mpds progress
mpd_bitrate mpd_bitrate
@ -756,19 +756,19 @@ VARIABLES
mpd_vol mpd_vol
MPD's volume MPDs volume
mpd_elapsed mpd_elapsed
Song's elapsed time Songs elapsed time
mpd_length mpd_length
Song's length Songs length
mpd_percent mpd_percent
Percent of song's progress Percent of songs progress
mpd_random mpd_random
@ -861,7 +861,7 @@ VARIABLES
Examples: Examples:
${tcp_portmon 6881 6999 count} - displays the number of connec- ${tcp_portmon 6881 6999 count} - displays the number of connec
tions in the bittorrent port range tions in the bittorrent port range
${tcp_portmon 22 22 rip 0} - displays the remote host ip of the ${tcp_portmon 22 22 rip 0} - displays the remote host ip of the
@ -880,7 +880,7 @@ VARIABLES
name of the fifteenth connection in the range of all ports name of the fifteenth connection in the range of all ports
Note that port monitor variables which share the same port range Note that port monitor variables which share the same port range
actually refer to the same monitor, so many references to a sin- actually refer to the same monitor, so many references to a sin
gle port range for different items and different indexes all use gle port range for different items and different indexes all use
the same monitor internally. In other words, the program avoids the same monitor internally. In other words, the program avoids
creating redundant monitors. creating redundant monitors.
@ -888,7 +888,7 @@ VARIABLES
texeci interval command texeci interval command
Runs a command at an interval inside a thread and displays the Runs a command at an interval inside a thread and displays the
output. Same as $execi, except the command is run inside a output. Same as $execi, except the command is run inside a
thread. Use this if you have a slow script to keep Conky updat- thread. Use this if you have a slow script to keep Conky updat
ing. You should make the interval slightly longer then the time ing. You should make the interval slightly longer then the time
it takes your script to execute. For example, if you have a it takes your script to execute. For example, if you have a
script that take 5 seconds to execute, you should make the script that take 5 seconds to execute, you should make the
@ -901,18 +901,18 @@ VARIABLES
tail logfile lines (interval) tail logfile lines (interval)
Displays last N lines of supplied text text file. If interval is Displays last N lines of supplied text text file. If interval is
not supplied, Conky assumes 2x Conky's interval. Max of 30 lines not supplied, Conky assumes 2x Conkys interval. Max of 30 lines
can be displayed, or until the text buffer is filled. can be displayed, or until the text buffer is filled.
time (format) time (format)
Local time, see man strftime to get more information about for- Local time, see man strftime to get more information about for
mat mat
totaldown net totaldown net
Total download, overflows at 4 GB on Linux with 32-bit arch and Total download, overflows at 4 GB on Linux with 32-bit arch and
there doesn't seem to be a way to know how many times it has there doesnt seem to be a way to know how many times it has
already done that before conky has started. already done that before conky has started.
@ -975,7 +975,7 @@ VARIABLES
EXAMPLES EXAMPLES
conky -t '${time %D %H:%m}' -o -u 30 conky -t ${time %D %H:%m} -o -u 30
Start Conky in its own window with date and clock as text and 30 Start Conky in its own window with date and clock as text and 30
sec update interval. sec update interval.
@ -986,9 +986,9 @@ FILES
~/.conkyrc default configuration file ~/.conkyrc default configuration file
BUGS BUGS
Drawing to root or some other desktop window directly doesn't work with Drawing to root or some other desktop window directly doesnt work with
all window managers. Especially doesn't work well with Gnome and it has all window managers. Especially doesnt work well with Gnome and it has
been reported that it doesn't work with KDE either. Nautilus can be been reported that it doesnt work with KDE either. Nautilus can be
disabled from drawing to desktop with program gconf-editor. Uncheck disabled from drawing to desktop with program gconf-editor. Uncheck
show_desktop in /apps/nautilus/preferences/. There is -w switch in show_desktop in /apps/nautilus/preferences/. There is -w switch in
Conky to set some specific window id. You might find xwininfo -tree Conky to set some specific window id. You might find xwininfo -tree
@ -998,13 +998,13 @@ BUGS
SEE ALSO SEE ALSO
http://conky.sourceforge.net [http://conky.sourceforge.net] http://conky.sourceforge.net [http://conky.sourceforge.net]
http://www.sourceforge.net/projects/conky [http://www.source- http://www.sourceforge.net/projects/conky [http://www.source
forge.net/projects/conky] forge.net/projects/conky]
#conky on irc.freenode.net #conky on irc.freenode.net
AUTHORS AUTHORS
The Conky dev team. What's up now! The Conky dev team. Whats up now!

View File

@ -1,6 +1,6 @@
AC_INIT([Conky],[1.3.6_CVS_20060107],[brenden1@users.sourceforge.net]) AC_INIT([Conky],[1.3.6_CVS_20060108],[brenden1@users.sourceforge.net])
AM_INIT_AUTOMAKE(conky, 1.3.6_CVS_20060107) AM_INIT_AUTOMAKE(conky, 1.3.6_CVS_20060108)
AM_CONFIG_HEADER(src/config.h) AM_CONFIG_HEADER(src/config.h)
AC_PROG_LIBTOOL AC_PROG_LIBTOOL
@ -99,7 +99,7 @@ case x$xmms_support in
xnone|xyes|xno) xnone|xyes|xno)
;; ;;
xxmms) xxmms)
AC_DEFINE(XMMS, 1, [Define for XMMS support]) AC_DEFINE(XMMS_H, 1, [Define for XMMS support])
echo "Sorry, xmms isn't supported yet" echo "Sorry, xmms isn't supported yet"
exit -1 exit -1
;; ;;
@ -107,16 +107,16 @@ case x$xmms_support in
PKG_CHECK_MODULES([BMP], [bmp], []) PKG_CHECK_MODULES([BMP], [bmp], [])
CFLAGS="$CFLAGS $BMP_CFLAGS" CFLAGS="$CFLAGS $BMP_CFLAGS"
LIBS="$LIBS $BMP_LIBS" LIBS="$LIBS $BMP_LIBS"
AC_DEFINE(BMP, 1, [Define for BMP support]) AC_DEFINE(BMP_H, 1, [Define for BMP support])
;; ;;
xaudacious) xaudacious)
PKG_CHECK_MODULES([AUDACIOUS], [audacious >= 0.1]) PKG_CHECK_MODULES([AUDACIOUS], [audacious >= 0.1])
CFLAGS="$CFLAGS $AUDACIOUS_CFLAGS" CFLAGS="$CFLAGS $AUDACIOUS_CFLAGS"
LIBS="$LIBS $AUDACIOUS_LIBS" LIBS="$LIBS $AUDACIOUS_LIBS"
AC_DEFINE(AUDACIOUS, 1, [Define for Audacious support]) AC_DEFINE(AUDACIOUS_H, 1, [Define for Audacious support])
;; ;;
xinfopipe) xinfopipe)
AC_DEFINE(INFOPIPE, 1, [Define for XMMS/BMP InfoPipe support]) AC_DEFINE(INFOPIPE_H, 1, [Define for XMMS/BMP InfoPipe support])
;; ;;
*) *)
echo "Error: invalid xmms-status specified: $xmms_support" echo "Error: invalid xmms-status specified: $xmms_support"
@ -124,9 +124,9 @@ case x$xmms_support in
;; ;;
esac esac
AM_CONDITIONAL(BUILD_XMMS, test x$xmms_support = xxmms) AM_CONDITIONAL(BUILD_XMMS, test x$xmms_support = xxmms)
AM_CONDITIONAL(BUILD_BMP, test x$xmms_support = xbmp) AM_CONDITIONAL(BUILD_XMMS_BMP, test x$xmms_support = xbmp)
AM_CONDITIONAL(BUILD_AUDACIOUS, test x$xmms_support = xaudacious) AM_CONDITIONAL(BUILD_XMMS_AUDACIOUS, test x$xmms_support = xaudacious)
AM_CONDITIONAL(BUILD_INFOPIPE, test x$xmms_support = xinfopipe) AM_CONDITIONAL(BUILD_XMMS_INFOPIPE, test x$xmms_support = xinfopipe)
dnl dnl
dnl BMPx dnl BMPx

View File

@ -1,17 +1,25 @@
bin_PROGRAMS = conky bin_PROGRAMS = conky
if BUILD_AUDACIOUS if BUILD_XMMS
audacious = audacious.c xmms = xmms.c xmms.h
endif
if BUILD_XMMS_BMP
xmms = xmms.c xmms.h
endif
if BUILD_XMMS_AUDACIOUS
xmms = xmms.c xmms.h
endif
if BUILD_XMMS_INFOPIPE
xmms = xmms.c xmms.h
endif endif
if BUILD_BMPX if BUILD_BMPX
bmpx = bmpx.c bmpx = bmpx.c
endif endif
if BUILD_INFOPIPE
infopipe = infopipe.c
endif
if BUILD_SETI if BUILD_SETI
seti = seti.c seti = seti.c
endif endif
@ -50,7 +58,7 @@ if BUILD_X11
x11 = x11.c x11 = x11.c
endif endif
conky_SOURCES = common.c fs.c $(linux) mail.c mixer.c $(seti) $(mpd) $(solaris) $(freebsd) $(netbsd) $(port_monitors) conky.c conky.h $(x11) $(mldonkey) remoted.c remoted.h remotec.c remotec.h $(audacious) $(bmpx) $(infopipe) conky_SOURCES = common.c fs.c $(linux) mail.c mixer.c $(seti) $(mpd) $(solaris) $(freebsd) $(netbsd) $(port_monitors) conky.c conky.h $(x11) $(mldonkey) remoted.c remoted.h remotec.c remotec.h $(xmms) $(bmpx)
AM_LDFLAGS = $(X11_LIBS) $(XFT_LIBS) $(CAIRO_LIBS) $(PTHREAD_LIBS) -lm AM_LDFLAGS = $(X11_LIBS) $(XFT_LIBS) $(CAIRO_LIBS) $(PTHREAD_LIBS) -lm

View File

@ -1,154 +0,0 @@
/* -------------------------------------------------------------------------
* audacious.c: conky support for Audacious media player
*
* http://audacious-media-player.org
*
* Copyright (C) 2005 Philip Kovacs kovacsp3@comcast.net
*
* $Id$
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* --------------------------------------------------------------------------- */
#include <pthread.h>
/*#include <glib.h>*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <audacious/beepctrl.h>
#include "audacious.h"
#include "conky.h"
/* access to this item array is synchronized with mutexes */
static audacious_t g_items;
/* ----------------------------------------
* Conky update function for Audacious data.
* ---------------------------------------- */
void update_audacious(void)
{
/*
The worker thread is updating ihe g_items array asynchronously to the main
conky thread. We merely copy the g_items array into the main thread's info
structure when the main thread's update cycle fires. Note that using the
mutexes here makes it easier since we won't have to do any sync in conky.c.
*/
pthread_mutex_lock(&info.audacious.item_mutex);
memcpy(&info.audacious.items,g_items,sizeof(g_items));
pthread_mutex_unlock(&info.audacious.item_mutex);
}
/* --------------------------------------------------
* Worker thread function for Audacious data sampling.
* -------------------------------------------------- */
void *audacious_thread_func(void *pvoid)
{
int runnable;
static audacious_t items;
int session,playpos,frames,length;
int rate,freq,chans;
char *psong;
pvoid=(void*)pvoid; /* useless cast to avoid unused var warning */
session=0;
/* Grab the runnable signal. Should be non-zero here or we do nothing. */
pthread_mutex_lock(&info.audacious.runnable_mutex);
runnable=info.audacious.runnable;
pthread_mutex_unlock(&info.audacious.runnable_mutex );
/* Loop until the main thread sets the runnable signal to 0. */
while(runnable) {
for (;;) { /* convenience loop so we can break below */
if (!xmms_remote_is_running(session)) {
memset(&items,0,sizeof(items));
strcpy(items[AUDACIOUS_STATUS],"Not running");
break;
}
/* Player status */
if (xmms_remote_is_paused(session))
strcpy(items[AUDACIOUS_STATUS],"Paused");
else if (xmms_remote_is_playing(session))
strcpy(items[AUDACIOUS_STATUS],"Playing");
else
strcpy(items[AUDACIOUS_STATUS],"Stopped");
/* Current song title */
playpos = (int) xmms_remote_get_playlist_pos(session);
psong = (char *) xmms_remote_get_playlist_title(session, playpos);
if (psong)
strncpy(items[AUDACIOUS_SONG],psong,sizeof(items[AUDACIOUS_SONG]));
/* Current song length as MM:SS */
frames = xmms_remote_get_playlist_time(session,playpos);
length = frames / 1000;
snprintf(items[AUDACIOUS_SONG_LENGTH],sizeof(items[AUDACIOUS_SONG_LENGTH]),
"%d:%.2d", length / 60, length % 60);
/* Current song length in seconds */
snprintf(items[AUDACIOUS_SONG_LENGTH_SECONDS],sizeof(items[AUDACIOUS_SONG_LENGTH_SECONDS]),
"%d", length);
/* Current song length in frames */
snprintf(items[AUDACIOUS_SONG_LENGTH_FRAMES],sizeof(items[AUDACIOUS_SONG_LENGTH_FRAMES]),
"%d", frames);
/* Current song output length as MM:SS */
frames = xmms_remote_get_output_time(session);
length = frames / 1000;
snprintf(items[AUDACIOUS_SONG_OUTPUT_LENGTH],sizeof(items[AUDACIOUS_SONG_OUTPUT_LENGTH]),
"%d:%.2d", length / 60, length % 60);
/* Current song output length in seconds */
snprintf(items[AUDACIOUS_SONG_OUTPUT_LENGTH_SECONDS],sizeof(items[AUDACIOUS_SONG_OUTPUT_LENGTH_SECONDS]),
"%d", length);
/* Current song output length in frames */
snprintf(items[AUDACIOUS_SONG_OUTPUT_LENGTH_FRAMES],sizeof(items[AUDACIOUS_SONG_OUTPUT_LENGTH_FRAMES]),
"%d", frames);
/* Current song bitrate */
xmms_remote_get_info(session, &rate, &freq, &chans);
snprintf(items[AUDACIOUS_SONG_BITRATE],sizeof(items[AUDACIOUS_SONG_BITRATE]), "%d", rate);
/* Current song frequency */
snprintf(items[AUDACIOUS_SONG_FREQUENCY],sizeof(items[AUDACIOUS_SONG_FREQUENCY]), "%d", freq);
/* Current song channels */
snprintf(items[AUDACIOUS_SONG_CHANNELS],sizeof(items[AUDACIOUS_SONG_CHANNELS]), "%d", chans);
break;
}
/* Deliver the refreshed items array to g_items. */
pthread_mutex_lock(&info.audacious.item_mutex);
memcpy(&g_items,items,sizeof(items));
pthread_mutex_unlock(&info.audacious.item_mutex);
/* Grab the runnable signal for next loop. */
pthread_mutex_lock(&info.audacious.runnable_mutex);
runnable=info.audacious.runnable;
pthread_mutex_unlock(&info.audacious.runnable_mutex);
sleep(1);
}
pthread_exit(NULL);
}

View File

@ -226,18 +226,15 @@ void update_stuff()
if (NEED(INFO_MPD)) if (NEED(INFO_MPD))
update_mpd(); update_mpd();
#endif #endif
#ifdef AUDACIOUS #if defined(XMMS_H) || defined(BMP_H) || defined(AUDACIOUS_H) || defined(INFOPIPE_H)
if (NEED(INFO_AUDACIOUS)) if (NEED(INFO_XMMS))
update_audacious(); update_xmms();
#endif #endif
#ifdef BMPX #ifdef BMPX
if (NEED(INFO_BMPX)) if (NEED(INFO_BMPX))
update_bmpx(); update_bmpx();
#endif
#ifdef INFOPIPE
if (NEED(INFO_INFOPIPE))
update_infopipe();
#endif #endif
if (NEED(INFO_LOADAVG)) if (NEED(INFO_LOADAVG))
update_load_average(); update_load_average();

View File

@ -892,19 +892,20 @@ enum text_object_type {
OBJ_mpd_track, OBJ_mpd_track,
OBJ_mpd_percent, OBJ_mpd_percent,
#endif #endif
#ifdef AUDACIOUS #if defined(XMMS_H) || defined(BMP_H) || defined(AUDACIOUS_H) || defined(INFOPIPE_H)
OBJ_audacious_status, OBJ_xmms_status,
OBJ_audacious_song, OBJ_xmms_title,
OBJ_audacious_song_length, OBJ_xmms_length,
OBJ_audacious_song_length_seconds, OBJ_xmms_length_seconds,
OBJ_audacious_song_length_frames, OBJ_xmms_position,
OBJ_audacious_song_output_length, OBJ_xmms_position_seconds,
OBJ_audacious_song_output_length_seconds, OBJ_xmms_bitrate,
OBJ_audacious_song_output_length_frames, OBJ_xmms_frequency,
OBJ_audacious_song_bitrate, OBJ_xmms_channels,
OBJ_audacious_song_frequency, OBJ_xmms_filename,
OBJ_audacious_song_channels, OBJ_xmms_playlist_length,
OBJ_audacious_bar, OBJ_xmms_playlist_position,
OBJ_xmms_bar,
#endif #endif
#ifdef BMPX #ifdef BMPX
OBJ_bmpx_title, OBJ_bmpx_title,
@ -914,23 +915,6 @@ enum text_object_type {
OBJ_bmpx_uri, OBJ_bmpx_uri,
OBJ_bmpx_bitrate, OBJ_bmpx_bitrate,
#endif #endif
#ifdef INFOPIPE
OBJ_infopipe_protocol,
OBJ_infopipe_version,
OBJ_infopipe_status,
OBJ_infopipe_playlist_tunes,
OBJ_infopipe_playlist_currtune,
OBJ_infopipe_usec_position,
OBJ_infopipe_position,
OBJ_infopipe_usec_time,
OBJ_infopipe_time,
OBJ_infopipe_bitrate,
OBJ_infopipe_frequency,
OBJ_infopipe_channels,
OBJ_infopipe_title,
OBJ_infopipe_file,
OBJ_infopipe_bar,
#endif
#ifdef TCP_PORT_MONITOR #ifdef TCP_PORT_MONITOR
OBJ_tcp_portmon, OBJ_tcp_portmon,
#endif #endif
@ -1825,19 +1809,20 @@ int a = stippled_borders, b = 1;
(void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b); (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
END END
#endif #endif
#ifdef AUDACIOUS #if defined(XMMS_H) || defined(BMP_H) || defined(AUDACIOUS_H) || defined(INFOPIPE_H)
OBJ(audacious_status, INFO_AUDACIOUS) END OBJ(xmms_status, INFO_XMMS) END
OBJ(audacious_song, INFO_AUDACIOUS) END OBJ(xmms_title, INFO_XMMS) END
OBJ(audacious_song_length, INFO_AUDACIOUS) END OBJ(xmms_length, INFO_XMMS) END
OBJ(audacious_song_length_seconds, INFO_AUDACIOUS) END OBJ(xmms_length_seconds, INFO_XMMS) END
OBJ(audacious_song_length_frames, INFO_AUDACIOUS) END OBJ(xmms_position, INFO_XMMS) END
OBJ(audacious_song_output_length, INFO_AUDACIOUS) END OBJ(xmms_position_seconds, INFO_XMMS) END
OBJ(audacious_song_output_length_seconds, INFO_AUDACIOUS) END OBJ(xmms_bitrate, INFO_XMMS) END
OBJ(audacious_song_output_length_frames, INFO_AUDACIOUS) END OBJ(xmms_frequency, INFO_XMMS) END
OBJ(audacious_song_bitrate, INFO_AUDACIOUS) END OBJ(xmms_channels, INFO_XMMS) END
OBJ(audacious_song_frequency, INFO_AUDACIOUS) END OBJ(xmms_filename, INFO_XMMS) END
OBJ(audacious_song_channels, INFO_AUDACIOUS) END OBJ(xmms_playlist_length, INFO_XMMS) END
OBJ(audacious_bar, INFO_AUDACIOUS) OBJ(xmms_playlist_position, INFO_XMMS) END
OBJ(xmms_bar, INFO_XMMS)
(void) scan_bar(arg, &obj->a, &obj->b); (void) scan_bar(arg, &obj->a, &obj->b);
END END
#endif #endif
@ -1861,25 +1846,6 @@ int a = stippled_borders, b = 1;
memset(&(info.bmpx), 0, sizeof(struct bmpx_s)); memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
END END
#endif #endif
#ifdef INFOPIPE
OBJ(infopipe_protocol, INFO_INFOPIPE) END
OBJ(infopipe_version, INFO_INFOPIPE) END
OBJ(infopipe_status, INFO_INFOPIPE) END
OBJ(infopipe_playlist_tunes, INFO_INFOPIPE) END
OBJ(infopipe_playlist_currtune, INFO_INFOPIPE) END
OBJ(infopipe_usec_position, INFO_INFOPIPE) END
OBJ(infopipe_position, INFO_INFOPIPE) END
OBJ(infopipe_usec_time, INFO_INFOPIPE) END
OBJ(infopipe_time, INFO_INFOPIPE) END
OBJ(infopipe_bitrate, INFO_INFOPIPE) END
OBJ(infopipe_frequency, INFO_INFOPIPE) END
OBJ(infopipe_channels, INFO_INFOPIPE) END
OBJ(infopipe_title, INFO_INFOPIPE) END
OBJ(infopipe_file, INFO_INFOPIPE) END
OBJ(infopipe_bar, INFO_INFOPIPE)
(void) scan_bar(arg, &obj->a, &obj->b);
END
#endif
#ifdef TCP_PORT_MONITOR #ifdef TCP_PORT_MONITOR
OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR) OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
int argc, port_begin, port_end, item, connection_index; int argc, port_begin, port_end, item, connection_index;
@ -3135,46 +3101,48 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
255.0f)); 255.0f));
} }
#endif #endif
#ifdef AUDACIOUS #if defined(XMMS_H) || defined(BMP_H) || defined(AUDACIOUS_H) || defined(INFOPIPE_H)
OBJ(audacious_status) { OBJ(xmms_status) {
snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]); snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_STATUS]);
}
OBJ(audacious_song) {
snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG]);
} }
OBJ(audacious_song_length) { OBJ(xmms_title) {
snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_LENGTH]); snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_TITLE]);
} }
OBJ(audacious_song_length_seconds) { OBJ(xmms_length) {
snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_LENGTH_SECONDS]); snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_LENGTH]);
} }
OBJ(audacious_song_length_frames) { OBJ(xmms_length_seconds) {
snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_LENGTH_FRAMES]); snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_LENGTH_SECONDS]);
} }
OBJ(audacious_song_output_length) { OBJ(xmms_position) {
snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_OUTPUT_LENGTH]); snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_POSITION]);
} }
OBJ(audacious_song_output_length_seconds) { OBJ(xmms_position_seconds) {
snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_OUTPUT_LENGTH_SECONDS]); snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_POSITION_SECONDS]);
} }
OBJ(audacious_song_output_length_frames) { OBJ(xmms_bitrate) {
snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_OUTPUT_LENGTH_FRAMES]); snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_BITRATE]);
} }
OBJ(audacious_song_bitrate) { OBJ(xmms_frequency) {
snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_BITRATE]); snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_FREQUENCY]);
} }
OBJ(audacious_song_frequency) { OBJ(xmms_channels) {
snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_FREQUENCY]); snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_CHANNELS]);
} }
OBJ(audacious_song_channels) { OBJ(xmms_filename) {
snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]); snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_FILENAME]);
} }
OBJ(audacious_bar) { OBJ(xmms_playlist_length) {
snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_PLAYLIST_LENGTH]);
}
OBJ(xmms_playlist_position) {
snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_PLAYLIST_POSITION]);
}
OBJ(xmms_bar) {
double progress; double progress;
progress= atof(cur->audacious.items[AUDACIOUS_SONG_OUTPUT_LENGTH_SECONDS]) / progress= atof(cur->xmms.items[XMMS_POSITION_SECONDS]) /
atof(cur->audacious.items[AUDACIOUS_SONG_LENGTH_SECONDS]); atof(cur->xmms.items[XMMS_LENGTH_SECONDS]);
new_bar(p,obj->a,obj->b,(int)(progress*255.0f)); new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
} }
#endif #endif
#ifdef BMPX #ifdef BMPX
@ -3196,56 +3164,6 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
OBJ(bmpx_bitrate) { OBJ(bmpx_bitrate) {
snprintf(p, p_max_size, "%i", cur->bmpx.bitrate); snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
} }
#endif
#ifdef INFOPIPE
OBJ(infopipe_protocol) {
snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_PROTOCOL]);
}
OBJ(infopipe_version) {
snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_VERSION]);
}
OBJ(infopipe_status) {
snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_STATUS]);
}
OBJ(infopipe_playlist_tunes) {
snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_PLAYLIST_TUNES]);
}
OBJ(infopipe_playlist_currtune) {
snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_PLAYLIST_CURRTUNE]);
}
OBJ(infopipe_usec_position) {
snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_USEC_POSITION]);
}
OBJ(infopipe_position) {
snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_POSITION]);
}
OBJ(infopipe_usec_time) {
snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_USEC_TIME]);
}
OBJ(infopipe_time) {
snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_TIME]);
}
OBJ(infopipe_bitrate) {
snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_BITRATE]);
}
OBJ(infopipe_frequency) {
snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_FREQUENCY]);
}
OBJ(infopipe_channels) {
snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_CHANNELS]);
}
OBJ(infopipe_title) {
snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_TITLE]);
}
OBJ(infopipe_file) {
snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_FILE]);
}
OBJ(infopipe_bar) {
double progress;
progress= atof(cur->infopipe.items[INFOPIPE_USEC_POSITION]) /
atof(cur->infopipe.items[INFOPIPE_USEC_TIME]);
new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
}
#endif #endif
OBJ(top) { OBJ(top) {
if (obj->data.top.type == TOP_NAME if (obj->data.top.type == TOP_NAME
@ -5567,70 +5485,39 @@ int main(int argc, char **argv)
ERR("error setting signal handler: %s", strerror(errno) ); ERR("error setting signal handler: %s", strerror(errno) );
} }
#ifdef AUDACIOUS #if defined(XMMS_H) || defined(BMP_H) || defined(AUDACIOUS_H) || defined(INFOPIPE_H)
/* joinable thread for audacious activity */ /* joinable thread for xmms activity */
pthread_attr_init(&info.audacious.thread_attr); pthread_attr_init(&info.xmms.thread_attr);
pthread_attr_setdetachstate(&info.audacious.thread_attr, PTHREAD_CREATE_JOINABLE); pthread_attr_setdetachstate(&info.xmms.thread_attr, PTHREAD_CREATE_JOINABLE);
/* init mutexex */ /* init mutexex */
pthread_mutex_init(&info.audacious.item_mutex, NULL); pthread_mutex_init(&info.xmms.item_mutex, NULL);
pthread_mutex_init(&info.audacious.runnable_mutex, NULL); pthread_mutex_init(&info.xmms.runnable_mutex, NULL);
/* init runnable condition for worker thread */ /* init runnable condition for worker thread */
pthread_mutex_lock(&info.audacious.runnable_mutex); pthread_mutex_lock(&info.xmms.runnable_mutex);
info.audacious.runnable=1; info.xmms.runnable=1;
pthread_mutex_unlock(&info.audacious.runnable_mutex); pthread_mutex_unlock(&info.xmms.runnable_mutex);
if (pthread_create(&info.audacious.thread, &info.audacious.thread_attr, audacious_thread_func, NULL)) if (pthread_create(&info.xmms.thread, &info.xmms.thread_attr, xmms_thread_func, NULL))
{ {
CRIT_ERR("unable to create audacious thread!"); CRIT_ERR("unable to create xmms thread!");
}
#endif
#ifdef INFOPIPE
/* joinable thread for infopipe activity */
pthread_attr_init(&info.infopipe.thread_attr);
pthread_attr_setdetachstate(&info.infopipe.thread_attr, PTHREAD_CREATE_JOINABLE);
/* init mutexex */
pthread_mutex_init(&info.infopipe.item_mutex, NULL);
pthread_mutex_init(&info.infopipe.runnable_mutex, NULL);
/* init runnable condition for worker thread */
pthread_mutex_lock(&info.infopipe.runnable_mutex);
info.infopipe.runnable=1;
pthread_mutex_unlock(&info.infopipe.runnable_mutex);
if (pthread_create(&info.infopipe.thread, &info.infopipe.thread_attr, infopipe_thread_func, NULL))
{
CRIT_ERR("unable to create infopipe thread!");
} }
#endif #endif
main_loop(); main_loop();
#ifdef AUDACIOUS #if defined(XMMS_H) || defined(BMP_H) || defined(AUDACIOUS_H) || defined(INFOPIPE_H)
/* signal audacious worker thread to terminate */ /* signal xmms worker thread to terminate */
pthread_mutex_lock(&info.audacious.runnable_mutex); pthread_mutex_lock(&info.xmms.runnable_mutex);
info.audacious.runnable=0; info.xmms.runnable=0;
pthread_mutex_unlock(&info.audacious.runnable_mutex); pthread_mutex_unlock(&info.xmms.runnable_mutex);
/* destroy thread attribute and wait for thread */ /* destroy thread attribute and wait for thread */
pthread_attr_destroy(&info.audacious.thread_attr); pthread_attr_destroy(&info.xmms.thread_attr);
if (pthread_join(info.audacious.thread, NULL)) if (pthread_join(info.xmms.thread, NULL))
{ {
ERR("error joining audacious thread"); ERR("error joining xmms thread");
} }
/* destroy mutexes */ /* destroy mutexes */
pthread_mutex_destroy(&info.audacious.item_mutex); pthread_mutex_destroy(&info.xmms.item_mutex);
pthread_mutex_destroy(&info.audacious.runnable_mutex); pthread_mutex_destroy(&info.xmms.runnable_mutex);
#endif
#ifdef INFOPIPE
/* signal infopipe worker thread to terminate */
pthread_mutex_lock(&info.infopipe.runnable_mutex);
info.infopipe.runnable=0;
pthread_mutex_unlock(&info.infopipe.runnable_mutex);
/* destroy thread attribute and wait for thread */
pthread_attr_destroy(&info.infopipe.thread_attr);
if (pthread_join(info.infopipe.thread, NULL))
{
ERR("error joining infopipe thread");
}
/* destroy mutexes */
pthread_mutex_destroy(&info.infopipe.item_mutex);
pthread_mutex_destroy(&info.infopipe.runnable_mutex);
#endif #endif
return 0; return 0;

View File

@ -9,7 +9,7 @@
#ifndef _conky_h_ #ifndef _conky_h_
#define _conky_h_ #define _conky_h_
#if defined(AUDACIOUS) || defined(INFOPIPE) #if defined(XMMS_H) || defined(BMP_H) || defined(AUDACIOUS_H) || defined(INFOPIPE_H)
#include <pthread.h> #include <pthread.h>
#endif #endif
#if defined(HAS_MCHECK_H) #if defined(HAS_MCHECK_H)
@ -127,12 +127,12 @@ struct mpd_s {
}; };
#endif #endif
#ifdef AUDACIOUS #if defined(XMMS_H) || defined(BMP_H) || defined(AUDACIOUS_H) || defined(INFOPIPE_H)
#include "audacious.h" #include "xmms.h"
struct audacious_s { struct xmms_s {
audacious_t items; /* e.g. items[AUDACIOUS_STATUS] yields char[] */ xmms_t items; /* e.g. items[XMMS_STATUS] yields char[] */
int runnable; /* used to signal infopipe thread to stop */ int runnable; /* used to signal worker thread to stop */
pthread_t thread; /* worker thread for infopipe updating */ pthread_t thread; /* worker thread for xmms updating */
pthread_attr_t thread_attr; /* thread attributes */ pthread_attr_t thread_attr; /* thread attributes */
pthread_mutex_t item_mutex; /* mutex for item array */ pthread_mutex_t item_mutex; /* mutex for item array */
pthread_mutex_t runnable_mutex; /* mutex for runnable flag */ pthread_mutex_t runnable_mutex; /* mutex for runnable flag */
@ -151,18 +151,6 @@ struct bmpx_s {
}; };
#endif #endif
#ifdef INFOPIPE
#include "infopipe.h"
struct infopipe_s {
infopipe_t items; /* e.g. items[INFOPIPE_STATUS] yields char[] */
int runnable; /* used to signal infopipe thread to stop */
pthread_t thread; /* worker thread for infopipe updating */
pthread_attr_t thread_attr; /* thread attributes */
pthread_mutex_t item_mutex; /* mutex for item array */
pthread_mutex_t runnable_mutex; /* mutex for runnable flag */
};
#endif
#ifdef TCP_PORT_MONITOR #ifdef TCP_PORT_MONITOR
#include "libtcp-portmon.h" #include "libtcp-portmon.h"
#define MIN_PORT_MONITORS_DEFAULT 16 #define MIN_PORT_MONITORS_DEFAULT 16
@ -200,14 +188,11 @@ enum {
#ifdef TCP_PORT_MONITOR #ifdef TCP_PORT_MONITOR
INFO_TCP_PORT_MONITOR = 22, INFO_TCP_PORT_MONITOR = 22,
#endif #endif
#if defined(XMMS_H) || defined(BMP_H) || defined(AUDACIOUS_H) || defined(INFOPIPE_H)
INFO_XMMS = 23,
#endif
#ifdef BMPX #ifdef BMPX
INFO_BMPX = 23, INFO_BMPX = 24,
#endif
#ifdef INFOPIPE
INFO_INFOPIPE = 24,
#endif
#ifdef AUDACIOUS
INFO_AUDACIOUS = 25,
#endif #endif
}; };
@ -252,14 +237,11 @@ struct information {
struct mpd_s mpd; struct mpd_s mpd;
mpd_Connection *conn; mpd_Connection *conn;
#endif #endif
#ifdef AUDACIOUS #if defined(XMMS_H) || defined(BMP_H) || defined(AUDACIOUS_H) || defined(INFOPIPE_H)
struct audacious_s audacious; struct xmms_s xmms;
#endif #endif
#ifdef BMPX #ifdef BMPX
struct bmpx_s bmpx; struct bmpx_s bmpx;
#endif
#ifdef INFOPIPE
struct infopipe_s infopipe;
#endif #endif
struct process *cpu[10]; struct process *cpu[10];
struct process *memu[10]; struct process *memu[10];

264
src/xmms.c Normal file
View File

@ -0,0 +1,264 @@
/* -------------------------------------------------------------------------
* xmms.c: conky support for XMMS-related projects
*
* Copyright (C) 2005 Philip Kovacs kovacsp3@comcast.net
*
* $Id$
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* --------------------------------------------------------------------------- */
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#if defined(XMMS_H)
#include <xmms/xmmsctrl.h>
#elif defined(BMP_H)
#include <bmp/beepctrl.h>
#elif defined(AUDACIOUS_H)
#include <audacious/beepctrl.h>
#elif defined(INFOPIPE_H)
#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
#include <fcntl.h>
#define INFOPIPE_NAMED_PIPE "/tmp/xmms-info"
#endif
#include "xmms.h"
#include "conky.h"
/* access to this item array is synchronized with mutexes */
static xmms_t g_items;
/* ------------------------------------
* Conky update function for XMMS data.
* ------------------------------------ */
void update_xmms(void)
{
/*
The worker thread is updating the g_items array asynchronously to the main
conky thread. We merely copy the g_items array into the main thread's info
structure when the main thread's update cycle fires. Note that using the
mutexes here makes it easier since we won't have to do any sync in conky.c.
*/
pthread_mutex_lock(&info.xmms.item_mutex);
memcpy(&info.xmms.items,g_items,sizeof(g_items));
pthread_mutex_unlock(&info.xmms.item_mutex);
}
#if defined(XMMS_H) || defined(BMP_H) || defined(AUDACIOUS_H)
/* ------------------------------------------------------------
* Worker thread function for XMMS/BMP/Audacious data sampling.
* ------------------------------------------------------------ */
void *xmms_thread_func(void *pvoid)
{
int runnable;
static xmms_t items;
int session,playpos,frames,length;
int rate,freq,chans;
char *psong,*pfilename;
pvoid=(void*)pvoid; /* useless cast to avoid unused var warning */
session=0;
/* Grab the runnable signal. Should be non-zero here or we do nothing. */
pthread_mutex_lock(&info.xmms.runnable_mutex);
runnable=info.xmms.runnable;
pthread_mutex_unlock(&info.xmms.runnable_mutex );
/* Loop until the main thread sets the runnable signal to 0. */
while(runnable) {
for (;;) { /* convenience loop so we can break below */
if (!xmms_remote_is_running(session)) {
memset(&items,0,sizeof(items));
strcpy(items[XMMS_STATUS],"Not running");
break;
}
/* Player status */
if (xmms_remote_is_paused(session))
strcpy(items[XMMS_STATUS],"Paused");
else if (xmms_remote_is_playing(session))
strcpy(items[XMMS_STATUS],"Playing");
else
strcpy(items[XMMS_STATUS],"Stopped");
/* Current song title */
playpos = (int) xmms_remote_get_playlist_pos(session);
psong = (char *) xmms_remote_get_playlist_title(session, playpos);
if (psong)
strncpy(items[XMMS_TITLE],psong,sizeof(items[XMMS_TITLE]));
/* Current song length as MM:SS */
frames = xmms_remote_get_playlist_time(session,playpos);
length = frames / 1000;
snprintf(items[XMMS_LENGTH],sizeof(items[XMMS_LENGTH]),
"%d:%.2d", length / 60, length % 60);
/* Current song length in seconds */
snprintf(items[XMMS_LENGTH_SECONDS],sizeof(items[XMMS_LENGTH_SECONDS]),
"%d", length);
/* Current song position as MM:SS */
frames = xmms_remote_get_output_time(session);
length = frames / 1000;
snprintf(items[XMMS_POSITION],sizeof(items[XMMS_POSITION]),
"%d:%.2d", length / 60, length % 60);
/* Current song position in seconds */
snprintf(items[XMMS_POSITION_SECONDS],sizeof(items[XMMS_POSITION_SECONDS]),
"%d", length);
/* Current song bitrate */
xmms_remote_get_info(session, &rate, &freq, &chans);
snprintf(items[XMMS_BITRATE],sizeof(items[XMMS_BITRATE]), "%d", rate);
/* Current song frequency */
snprintf(items[XMMS_FREQUENCY],sizeof(items[XMMS_FREQUENCY]), "%d", freq);
/* Current song channels */
snprintf(items[XMMS_CHANNELS],sizeof(items[XMMS_CHANNELS]), "%d", chans);
/* Current song filename */
pfilename = xmms_remote_get_playlist_file(session,playpos);
strncpy(items[XMMS_FILENAME],pfilename,sizeof(items[XMMS_FILENAME]));
/* Length of the Playlist (number of songs) */
length = xmms_remote_get_playlist_length(session);
snprintf(items[XMMS_PLAYLIST_LENGTH],sizeof(items[XMMS_PLAYLIST_LENGTH]), "%d", length);
/* Playlist position (index of song) */
snprintf(items[XMMS_PLAYLIST_POSITION],sizeof(items[XMMS_PLAYLIST_POSITION]), "%d", playpos+1);
break;
}
/* Deliver the refreshed items array to g_items. */
pthread_mutex_lock(&info.xmms.item_mutex);
memcpy(&g_items,items,sizeof(items));
pthread_mutex_unlock(&info.xmms.item_mutex);
/* Grab the runnable signal for next loop. */
pthread_mutex_lock(&info.xmms.runnable_mutex);
runnable=info.xmms.runnable;
pthread_mutex_unlock(&info.xmms.runnable_mutex);
sleep(1);
}
pthread_exit(NULL);
}
#elif defined(INFOPIPE_H)
/* --------------------------------------------------
* Worker thread function for InfoPipe data sampling.
* -------------------------------------------------- */
void *xmms_thread_func(void *pvoid)
{
int i,rc,fd,runnable;
fd_set readset;
struct timeval tm;
static char buf[2048]; /* should equal or exceed sizeof(infopipe_t) */
static xmms_t items;
char *pbuf,c;
pvoid=(void*)pvoid; /* useless cast to avoid unused var warning */
/* Grab the runnable signal. Should be non-zero here or we do nothing. */
pthread_mutex_lock(&info.infopipe.runnable_mutex);
runnable=info.infopipe.runnable;
pthread_mutex_unlock(&info.infopipe.runnable_mutex );
/* Loop until the main thread sets the runnable signal to 0. */
while(runnable) {
for (;;) { /* convenience loop so we can break below */
memset(buf,0,sizeof(buf));
if ((fd=open(INFOPIPE_NAMED_PIPE, O_RDONLY | O_NONBLOCK)) < 0) {
/* InfoPipe is not running */
memset(items,0,sizeof(items));
strcpy(items[INFOPIPE_STATUS],"Not running");
break;
}
FD_ZERO(&readset);
FD_SET(fd,&readset);
/* On Linux, select() reduces the timer by the amount of time not slept,
* so we must reset the timer with each loop. */
tm.tv_sec=1;
tm.tv_usec=0;
rc=select(fd+1,&readset,NULL,NULL,&tm);
if (rc == -1) {
/* -- debug --
perror("infopipe select()");
*/
}
else if (rc && FD_ISSET(fd,&readset)) { /* ready to read */
if (read(fd,buf,sizeof(buf)) > 0) { /* buf has data */
pbuf=buf;
for (i=0;i<14;i++) {
/* 14 lines of key: value pairs presented in a known order */
if ( sscanf(pbuf,"%*[^:]: %[^\n]",items[i]) == EOF )
break;
while((c = *pbuf++) && (c != '\n'));
}
/* -- debug --
for(i=0;i<14;i++)
printf("%s\n",items[i]);
*/
}
}
else {
/* -- debug --
printf("no infopipe data\n");
*/
}
close(fd);
break;
}
/* Deliver the refreshed items array to g_items. */
pthread_mutex_lock(&info.infopipe.item_mutex);
memcpy(&g_items,items,sizeof(items));
pthread_mutex_unlock(&info.infopipe.item_mutex);
/* Grab the runnable signal for next loop. */
pthread_mutex_lock(&info.infopipe.runnable_mutex);
runnable=info.infopipe.runnable;
pthread_mutex_unlock(&info.infopipe.runnable_mutex);
sleep(1);
}
pthread_exit(NULL);
}
#endif

View File

@ -1,7 +1,5 @@
/* ------------------------------------------------------------------------- /* -------------------------------------------------------------------------
* audacious.h: conky support for Audacious audio player * xmms.h: conky support for XMMS-related projects
*
* http://audacious-media-player.org
* *
* Copyright (C) 2005 Philip Kovacs kovacsp3@comcast.net * Copyright (C) 2005 Philip Kovacs kovacsp3@comcast.net
* *
@ -22,31 +20,31 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
#ifndef AUDACIOUS_H #ifndef XMMS_H
#define AUDACIOUS_H #define XMMS_H
/* 11 keys comprise the audacious information. */ enum _xmms_items {
enum _audacious_keys { XMMS_STATUS=0,
AUDACIOUS_STATUS, XMMS_TITLE,
AUDACIOUS_SONG, XMMS_LENGTH,
AUDACIOUS_SONG_LENGTH, XMMS_LENGTH_SECONDS,
AUDACIOUS_SONG_LENGTH_SECONDS, XMMS_POSITION,
AUDACIOUS_SONG_LENGTH_FRAMES, XMMS_POSITION_SECONDS,
AUDACIOUS_SONG_OUTPUT_LENGTH, XMMS_BITRATE,
AUDACIOUS_SONG_OUTPUT_LENGTH_SECONDS, XMMS_FREQUENCY,
AUDACIOUS_SONG_OUTPUT_LENGTH_FRAMES, XMMS_CHANNELS,
AUDACIOUS_SONG_BITRATE, XMMS_FILENAME,
AUDACIOUS_SONG_FREQUENCY, XMMS_PLAYLIST_LENGTH,
AUDACIOUS_SONG_CHANNELS XMMS_PLAYLIST_POSITION,
}; };
/* 11 slots for the audacious values */ /* 12 slots for the xmms values */
typedef char audacious_t[11][128]; typedef char xmms_t[12][128];
/* Service routine for the conky main thread */ /* Service routine for the conky main thread */
void update_audacious(void); void update_xmms(void);
/* Thread function */ /* Thread function */
void *audacious_thread_func(void *); void *xmms_thread_func(void *);
#endif #endif