1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-23 19:39:06 +00:00

* Added if_existing patch for string matching (thanks cromka)

* Added hwmon support (thanks flitsch)
* Some xmms2 updates (thanks sleipner)
* Added $battery_percent and $battery_bar (thanks akash)


git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@855 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Brenden Matthews 2007-04-06 06:11:53 +00:00
parent 3d9d260f4c
commit fc72692cc7
8 changed files with 640 additions and 206 deletions

View File

@ -13,6 +13,9 @@ Alex <godexsoft at bk dot ru>
affinity <affy at users dot sourceforge dot net>
X-Mozilla-Status support
akash <akash at users dot sourceforge dot net>
battery_percent and battery_bar
Blondak <blondak_nesercz at users dot sourceforge dot net>
diskio read & write patch
@ -34,6 +37,9 @@ btlee
calmar <mac at calmar dot ws>
mboxscan
cromka <cromka at users dot sourceforge dot net>
if_existing patch for string matching
dan-h <dan-h at users dot sourceforge dot net>
adt746x fix
@ -71,6 +77,9 @@ Falk Feuersenger <lumberjack at users dot sourceforge dot net>
Fanat1k
Iconv patch
flitsch <flitsch at users dot sourceforge dot net>
hwmon support
Gwenhael LE MOINE <cycojesus at yahoo dot fr>
Manual setting of the position
WM_CLASS for window when drawing to own window

View File

@ -1,5 +1,12 @@
# $Id$
2007-04-5
* Added if_empty patch (thanks Erik)
* Added if_existing patch for string matching (thanks cromka)
* Added hwmon support (thanks flitsch)
* Some xmms2 updates (thanks sleipner)
* Added $battery_percent and $battery_bar (thanks akash)
2007-02-25
* OpenBSD support added to Conky (thanks hifi)
* Updated mboxscan stuff (thanks calmar)

View File

@ -1065,6 +1065,78 @@ Returns CPU #n's voltage in V. CPUs are
counted from 1. If omitted, the parameter
defaults to 1.
.TP
\fB\*(T<\fBxmms2_artist\fR\*(T>\fR
Artist in current XMMS2 song
.TP
\fB\*(T<\fBxmms2_album\fR\*(T>\fR
Album in current XMMS2 song
.TP
\fB\*(T<\fBxmms2_title\fR\*(T>\fR
Title in current XMMS2 song
.TP
\fB\*(T<\fBxmms2_genre\fR\*(T>\fR
Genre in current XMMS2 song
.TP
\fB\*(T<\fBxmms2_comment\fR\*(T>\fR
Comment in current XMMS2 song
.TP
\fB\*(T<\fBxmms2_decoder\fR\*(T>\fR
Decoder plugin used
.TP
\fB\*(T<\fBxmms2_transport\fR\*(T>\fR
Transport plugin used
.TP
\fB\*(T<\fBxmms2_url\fR\*(T>\fR
Full path to current song
.TP
\fB\*(T<\fBxmms2_tracknr\fR\*(T>\fR
Track number in current XMMS2 song
.TP
\fB\*(T<\fBxmms2_bitrate\fR\*(T>\fR
Bitrate of current song
.TP
\fB\*(T<\fBxmms2_id\fR\*(T>\fR
XMMS2 id of current song
.TP
\fB\*(T<\fBxmms2_duration\fR\*(T>\fR
Duration of current song
.TP
\fB\*(T<\fBxmms2_elapsed\fR\*(T>\fR
Song's elapsed time
.TP
\fB\*(T<\fBxmms2_size\fR\*(T>\fR
Size of current song
.TP
\fB\*(T<\fBxmms2_percent\fR\*(T>\fR
Percent of song's progress
.TP
\fB\*(T<\fBxmms2_status\fR\*(T>\fR
XMMS2 status (Playing, Paused, Stopped, or Disconnected)
.TP
\fB\*(T<\fBxmms2_bar\fR\*(T>\fR \*(T<\fB(height),(width)\fR\*(T>
XMMS2 progress bar
.TP
\fB\*(T<\fBxmms2_smart\fR\*(T>\fR
Prints the song name in either the form "artist - title" or file name, depending on whats available
.SH EXAMPLES
.TP
\*(T<conky \*(T>\*(T<\fB\-t '${time %D %H:%m}' \-o \-u 30\fR\*(T>

View File

@ -240,6 +240,26 @@
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>battery_bar</option></command>
<option>(height),(width) (num)</option>
</term>
<listitem>
Battery percentage remaining of ACPI battery in a bar. ACPI battery number can be given as argument (default is BAT0).
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>battery_percent</option></command>
<option>(num)</option>
</term>
<listitem>
Battery percentage remaining for ACPI battery. ACPI battery number can be given as argument (default is BAT0).
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>battery_time</option></command>
@ -689,6 +709,16 @@
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>hwmon</option></command>
<option>N sensor number input</option>
</term>
<listitem>
This has the ability to display the contents of hwmon files located under "/sys/class/hwmon/hwmonX/device/N". For example, use ${hwmon 0 temp 1 input} to read the temperature of the CPU (in °C) from "/sys/class/hwmon/hwmon0/device/temp1_input". If the sensor name equals "temp", then the value read will be divided by 1000, otherwise the number will be used unchanged. The factor 1000 is just for the Abit uGuru sensor.
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>iconv_start</option></command>
@ -876,7 +906,7 @@
<option>(var)</option>
</term>
<listitem>
if conky variable VAR is empty, display everything between if_empty and the matching $endif
if conky variable VAR is empty, display everything between $if_empty and the matching $endif
<para></para></listitem>
</varlistentry>
@ -886,17 +916,17 @@
<option>(process)</option>
</term>
<listitem>
if PROCESS is running, display everything if_running and the matching $endif
if PROCESS is running, display everything $if_running and the matching $endif
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>if_existing</option></command>
<option>(file)</option>
<option>file (string)</option>
</term>
<listitem>
if FILE exists, display everything between if_existing and the matching $endif
if FILE exists, display everything between if_existing and the matching $endif. The optional second paramater checks for FILE containing the specified string and prints everything between $if_existing and the matching $endif.
<para></para></listitem>
</varlistentry>
@ -906,7 +936,7 @@
<option>(mountpoint)</option>
</term>
<listitem>
if MOUNTPOINT is mounted, display everything between if_mounted and the matching $endif
if MOUNTPOINT is mounted, display everything between $if_mounted and the matching $endif
<para></para></listitem>
</varlistentry>
@ -1591,5 +1621,168 @@
defaults to 1.
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>xmms2_artist</option></command>
</term>
<listitem>
Artist in current XMMS2 song
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>xmms2_album</option></command>
</term>
<listitem>
Album in current XMMS2 song
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>xmms2_title</option></command>
</term>
<listitem>
Title in current XMMS2 song
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>xmms2_genre</option></command>
</term>
<listitem>
Genre in current XMMS2 song
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>xmms2_comment</option></command>
</term>
<listitem>
Comment in current XMMS2 song
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>xmms2_decoder</option></command>
</term>
<listitem>
Decoder plugin used
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>xmms2_transport</option></command>
</term>
<listitem>
Transport plugin used
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>xmms2_url</option></command>
</term>
<listitem>
Full path to current song
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>xmms2_tracknr</option></command>
</term>
<listitem>
Track number in current XMMS2 song
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>xmms2_bitrate</option></command>
</term>
<listitem>
Bitrate of current song
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>xmms2_id</option></command>
</term>
<listitem>
XMMS2 id of current song
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>xmms2_duration</option></command>
</term>
<listitem>
Duration of current song
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>xmms2_elapsed</option></command>
</term>
<listitem>
Song's elapsed time
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>xmms2_size</option></command>
</term>
<listitem>
Size of current song
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>xmms2_percent</option></command>
</term>
<listitem>
Percent of song's progress
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>xmms2_status</option></command>
</term>
<listitem>
XMMS2 status (Playing, Paused, Stopped, or Disconnected)
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>xmms2_bar</option></command>
<option>(height),(width)</option>
</term>
<listitem>
Bar of XMMS2's progress
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>xmms2_smart</option></command>
</term>
<listitem>
Prints the song name in either the form "artist - title" or file name, depending on whats available
<para></para></listitem>
</varlistentry>
</variablelist>

View File

@ -457,6 +457,27 @@ int check_mount(char *s)
}
int check_contains(char *f, char *s)
{
int ret = 0;
FILE *where = fopen(f, "r");
if (where) {
char buf1[256], buf2[256];
while (fgets(buf1, 256, where)) {
sscanf(buf1, "%255s", buf2);
if (strstr(buf2, s)) {
ret = 1;
break;
}
}
fclose(where);
} else {
ERR("Could not open the file");
}
return ret;
}
#ifdef X11
static inline int calc_text_width(const char *s, int l)
{
@ -927,6 +948,8 @@ enum text_object_type {
OBJ_acpitempf,
OBJ_battery,
OBJ_battery_time,
OBJ_battery_percent,
OBJ_battery_bar,
OBJ_buffers,
OBJ_cached,
OBJ_color,
@ -1185,10 +1208,13 @@ struct text_object {
char devtype[256];
char type[64];
} i2c; /* 2 */
struct {
int pos;
char *s;
char *str;
} ifblock;
struct {
int num;
int type;
@ -1804,6 +1830,7 @@ static void free_text_objects(unsigned int count, struct text_object *objs)
case OBJ_if_mounted:
case OBJ_if_running:
free(objs[i].data.ifblock.s);
free(objs[i].data.ifblock.str);
break;
case OBJ_tail:
free(objs[i].data.tail.logfile);
@ -2151,6 +2178,21 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
else
strcpy(bat, "BAT0");
obj->data.s = strdup(bat);
END OBJ(battery_percent, 0);
char bat[64];
if (arg)
sscanf(arg, "%63s", bat);
else
strcpy(bat, "BAT0");
obj->data.s = strdup(bat);
END OBJ(battery_bar, 0);
char bat[64];
if (arg) {
arg = scan_bar(arg, &obj->a, &obj->b);
sscanf(arg, "%63s", bat);
} else {
strcpy(bat, "BAT0");
}
#if defined(__linux__)
END OBJ(i8k_version, INFO_I8K)
END OBJ(i8k_bios, INFO_I8K)
@ -2695,10 +2737,20 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
}
if (!arg) {
ERR("if_existing needs an argument");
obj->data.ifblock.s = 0;
} else
obj->data.ifblock.s = strdup(arg);
ERR("if_existing needs an argument or two");
obj->data.ifblock.s = NULL;
obj->data.ifblock.str = NULL;
} else {
char buf1[256], buf2[256];
int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
if (r == 1) {
obj->data.ifblock.s = strdup(buf1);
obj->data.ifblock.str = NULL;
} else {
obj->data.ifblock.s = strdup(buf1);
obj->data.ifblock.str = strdup(buf2);
}
}
blockstart[blockdepth] = object_count;
obj->data.ifblock.pos = object_count + 2;
blockdepth++;
@ -3409,6 +3461,13 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
OBJ(battery_time) {
get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
}
OBJ(battery_percent) {
snprintf(p, p_max_size, "%d",
get_battery_perct(obj->data.s));
}
OBJ(battery_bar) {
new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
}
OBJ(buffers) {
human_readable(cur->buffers * 1024, p, 255);
}
@ -4195,7 +4254,15 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
i = obj->data.ifblock.pos;
if_jumped = 1;
} else {
if_jumped = 0;
if (obj->data.ifblock.str) {
if (!check_contains(obj->data.ifblock.s,
obj->data.ifblock.str)) {
i = obj->data.ifblock.pos;
if_jumped = 1;
} else
if_jumped = 0;
} else
if_jumped = 0;
}
}
OBJ(if_mounted) {

View File

@ -481,6 +481,8 @@ double get_acpi_temperature(int fd);
void get_acpi_ac_adapter( char *, size_t );
void get_acpi_fan( char *, size_t );
void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item);
int get_battery_perct(const char *bat);
int get_battery_perct_bar(const char *bat);
void get_ibm_acpi_fan(char *buf, size_t client_buffer_size);
void get_ibm_acpi_temps(void);
void get_ibm_acpi_volume(char *buf, size_t client_buffer_size);

View File

@ -1200,12 +1200,16 @@ static FILE *acpi_bat_fp;
static FILE *apm_bat_fp;
static int acpi_last_full;
static int acpi_design_capacity;
static char last_battery_str[64]; /* e.g. "charging 75%" */
static char last_battery_time_str[64]; /* e.g. "3h 15m" */
static double last_battery_time;
static int last_battery_perct;
static double last_battery_perct_time;
void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item)
{
static int rep = 0, rep2 = 0;
@ -1378,6 +1382,74 @@ set_return_value:
return;
}
int get_battery_perct(const char *bat)
{
static int rep;
char acpi_path[128];
snprintf(acpi_path, 127, ACPI_BATTERY_BASE_PATH "/%s/state", bat);
/* don't update battery too often */
if (current_update_time - last_battery_perct_time < 30) {
return last_battery_perct;
}
last_battery_perct_time = current_update_time;
/* Only check for ACPI */
if (acpi_bat_fp == NULL && apm_bat_fp == NULL)
acpi_bat_fp = open_file(acpi_path, &rep);
int remaining_capacity = -1;
if (acpi_bat_fp != NULL) {
/* read last full capacity if it's zero */
if (acpi_design_capacity == 0) {
static int rep;
char path[128];
FILE *fp;
snprintf(path, 127,
ACPI_BATTERY_BASE_PATH "/%s/info", bat);
fp = open_file(path, &rep);
if (fp != NULL) {
while (!feof(fp)) {
char b[256];
if (fgets(b, 256, fp) == NULL)
break;
if (sscanf(b, "design capacity: %d", &acpi_design_capacity) != 0) {
break;
}
}
fclose(fp);
}
}
fseek(acpi_bat_fp, 0, SEEK_SET);
while (!feof(acpi_bat_fp)) {
char buf[256];
if (fgets(buf, 256, acpi_bat_fp) == NULL)
break;
if (buf[0] == 'r')
sscanf(buf, "remaining capacity: %d",
&remaining_capacity);
}
}
if(remaining_capacity < 0)
return 0;
/* compute the battery percentage */
last_battery_perct =
(int) (((float)remaining_capacity/acpi_design_capacity) * 100);
return last_battery_perct;
}
int get_battery_perct_bar(const char *bar)
{
get_battery_perct(bar);
return (int) (last_battery_perct * 2.56 - 1);
}
/* On Apple powerbook and ibook:
$ cat /proc/pmu/battery_0
flags : 00000013

View File

@ -16,14 +16,12 @@
/* callbacks */
void connection_lost( void *ptr )
{
//struct information * current_info = &info;
void connection_lost( void *ptr ) {
((struct information *)ptr)->xmms2_conn_state = CONN_NO;
if ( ((struct information *)ptr)->xmms2.status == NULL )
((struct information *)ptr)->xmms2.status = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.status, "xmms2 not responding", TEXT_BUFFER_SIZE - 1 );
if ( ((struct information *)ptr)->xmms2.status == NULL )
((struct information *)ptr)->xmms2.status = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.status, "xmms2 not responding", TEXT_BUFFER_SIZE - 1 );
if ( ((struct information *)ptr)->xmms2.artist == NULL )
@ -51,16 +49,16 @@ void connection_lost( void *ptr )
strncpy( ((struct information *)ptr)->xmms2.decoder, "", TEXT_BUFFER_SIZE - 1 );
if ( ((struct information *)ptr)->xmms2.transport == NULL )
((struct information *)ptr)->xmms2.transport = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.transport, "", TEXT_BUFFER_SIZE - 1 );
((struct information *)ptr)->xmms2.transport = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.transport, "", TEXT_BUFFER_SIZE - 1 );
if ( ((struct information *)ptr)->xmms2.url == NULL )
((struct information *)ptr)->xmms2.url = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.url, "", TEXT_BUFFER_SIZE - 1 );
((struct information *)ptr)->xmms2.url = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.url, "", TEXT_BUFFER_SIZE - 1 );
if ( ((struct information *)ptr)->xmms2.date == NULL )
((struct information *)ptr)->xmms2.date = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.date, "", TEXT_BUFFER_SIZE - 1 );
((struct information *)ptr)->xmms2.date = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.date, "", TEXT_BUFFER_SIZE - 1 );
((struct information *)ptr)->xmms2.tracknr = 0;
((struct information *)ptr)->xmms2.id = 0;
@ -71,167 +69,198 @@ void connection_lost( void *ptr )
((struct information *)ptr)->xmms2.progress = 0;
}
void handle_curent_id( xmmsc_result_t *res, void *ptr )
{
void handle_curent_id( xmmsc_result_t *res, void *ptr ) {
uint current_id;
if ( xmmsc_result_get_uint( res, &current_id ) )
{
xmmsc_result_t *res2;
res2 = xmmsc_medialib_get_info( ((struct information *)ptr)->xmms2_conn,
current_id );
xmmsc_result_wait ( res2 );
if ( xmmsc_result_get_uint( res, &current_id ) ) {
xmmsc_result_t *res2;
res2 = xmmsc_medialib_get_info( ((struct information *)ptr)->xmms2_conn, current_id );
xmmsc_result_wait( res2 );
if ( ((struct information *)ptr)->xmms2.artist == NULL )
((struct information *)ptr)->xmms2.artist = malloc( TEXT_BUFFER_SIZE );
if ( ((struct information *)ptr)->xmms2.album == NULL )
((struct information *)ptr)->xmms2.album = malloc( TEXT_BUFFER_SIZE );
if ( ((struct information *)ptr)->xmms2.title == NULL )
((struct information *)ptr)->xmms2.title = malloc( TEXT_BUFFER_SIZE );
if ( ((struct information *)ptr)->xmms2.genre == NULL )
((struct information *)ptr)->xmms2.genre = malloc( TEXT_BUFFER_SIZE );
if ( ((struct information *)ptr)->xmms2.comment == NULL )
((struct information *)ptr)->xmms2.comment = malloc( TEXT_BUFFER_SIZE );
if ( ((struct information *)ptr)->xmms2.decoder == NULL )
((struct information *)ptr)->xmms2.decoder = malloc( TEXT_BUFFER_SIZE );
if ( ((struct information *)ptr)->xmms2.transport == NULL )
((struct information *)ptr)->xmms2.transport = malloc( TEXT_BUFFER_SIZE );
if ( ((struct information *)ptr)->xmms2.url == NULL )
((struct information *)ptr)->xmms2.url = malloc( TEXT_BUFFER_SIZE );
if ( ((struct information *)ptr)->xmms2.date == NULL )
((struct information *)ptr)->xmms2.date = malloc( TEXT_BUFFER_SIZE );
/* update song info here */
((struct information *)ptr)->xmms2.id = current_id;
char *temp;
xmmsc_result_get_dict_entry_str( res2, "artist", &temp );
if ( temp != NULL ) {
if ( ((struct information *)ptr)->xmms2.artist == NULL )
((struct information *)ptr)->xmms2.artist = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.artist, temp, TEXT_BUFFER_SIZE - 1 );
}
char *temp;
xmmsc_result_get_dict_entry_string( res2, "artist", &temp );
if ( temp != NULL ) {
strncpy( ((struct information *)ptr)->xmms2.artist, temp, TEXT_BUFFER_SIZE - 1 );
} else {
strncpy( ((struct information *)ptr)->xmms2.artist, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
}
xmmsc_result_get_dict_entry_str( res2, "title", &temp );
if ( temp != NULL ) {
if ( ((struct information *)ptr)->xmms2.title == NULL )
((struct information *)ptr)->xmms2.title = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.title, temp, TEXT_BUFFER_SIZE - 1 );
}
xmmsc_result_get_dict_entry_str( res2, "album", &temp );
if ( temp != NULL ) {
if ( ((struct information *)ptr)->xmms2.album == NULL )
((struct information *)ptr)->xmms2.album = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.album, temp, TEXT_BUFFER_SIZE - 1 );
}
xmmsc_result_get_dict_entry_string( res2, "title", &temp );
if ( temp != NULL ) {
strncpy( ((struct information *)ptr)->xmms2.title, temp, TEXT_BUFFER_SIZE - 1 );
} else {
strncpy( ((struct information *)ptr)->xmms2.title, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
}
xmmsc_result_get_dict_entry_str( res2, "genre", &temp );
if ( temp != NULL ) {
if ( ((struct information *)ptr)->xmms2.genre == NULL )
((struct information *)ptr)->xmms2.genre = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.genre, temp, TEXT_BUFFER_SIZE - 1 );
}
xmmsc_result_get_dict_entry_string( res2, "album", &temp );
if ( temp != NULL ) {
strncpy( ((struct information *)ptr)->xmms2.album, temp, TEXT_BUFFER_SIZE - 1 );
} else {
strncpy( ((struct information *)ptr)->xmms2.album, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
}
xmmsc_result_get_dict_entry_str( res2, "comment", &temp );
if ( temp != NULL ) {
if ( ((struct information *)ptr)->xmms2.comment == NULL )
((struct information *)ptr)->xmms2.comment = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.comment, temp, TEXT_BUFFER_SIZE - 1 );
}
xmmsc_result_get_dict_entry_str( res2, "decoder", &temp );
if ( temp != NULL ) {
if ( ((struct information *)ptr)->xmms2.decoder == NULL )
((struct information *)ptr)->xmms2.decoder = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.decoder, temp, TEXT_BUFFER_SIZE - 1 );
}
xmmsc_result_get_dict_entry_string( res2, "genre", &temp );
if ( temp != NULL ) {
xmmsc_result_get_dict_entry_str( res2, "transport", &temp );
if ( temp != NULL ) {
if ( ((struct information *)ptr)->xmms2.transport == NULL )
((struct information *)ptr)->xmms2.transport = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.transport, temp, TEXT_BUFFER_SIZE - 1 );
}
strncpy( ((struct information *)ptr)->xmms2.genre, temp, TEXT_BUFFER_SIZE - 1 );
} else {
strncpy( ((struct information *)ptr)->xmms2.genre, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
}
xmmsc_result_get_dict_entry_str( res2, "url", &temp );
if ( temp != NULL ) {
if ( ((struct information *)ptr)->xmms2.url == NULL )
((struct information *)ptr)->xmms2.url = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.url, temp, TEXT_BUFFER_SIZE - 1 );
}
xmmsc_result_get_dict_entry_str( res2, "date", &temp );
if ( temp != NULL ) {
if ( ((struct information *)ptr)->xmms2.date == NULL )
((struct information *)ptr)->xmms2.date = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.date, temp, TEXT_BUFFER_SIZE - 1 );
}
xmmsc_result_get_dict_entry_string( res2, "comment", &temp );
if ( temp != NULL ) {
strncpy( ((struct information *)ptr)->xmms2.comment, temp, TEXT_BUFFER_SIZE - 1 );
} else {
strncpy( ((struct information *)ptr)->xmms2.comment, "", TEXT_BUFFER_SIZE - 1 );
}
xmmsc_result_get_dict_entry_string( res2, "decoder", &temp );
if ( temp != NULL ) {
strncpy( ((struct information *)ptr)->xmms2.decoder, temp, TEXT_BUFFER_SIZE - 1 );
} else {
strncpy( ((struct information *)ptr)->xmms2.decoder, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
}
xmmsc_result_get_dict_entry_string( res2, "transport", &temp );
if ( temp != NULL ) {
strncpy( ((struct information *)ptr)->xmms2.transport, temp, TEXT_BUFFER_SIZE - 1 );
} else {
strncpy( ((struct information *)ptr)->xmms2.transport, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
}
xmmsc_result_get_dict_entry_string( res2, "url", &temp );
if ( temp != NULL ) {
strncpy( ((struct information *)ptr)->xmms2.url, temp, TEXT_BUFFER_SIZE - 1 );
} else {
strncpy( ((struct information *)ptr)->xmms2.url, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
}
xmmsc_result_get_dict_entry_string( res2, "date", &temp );
if ( temp != NULL ) {
strncpy( ((struct information *)ptr)->xmms2.date, temp, TEXT_BUFFER_SIZE - 1 );
} else {
strncpy( ((struct information *)ptr)->xmms2.date, "????", TEXT_BUFFER_SIZE - 1 );
}
int itemp;
xmmsc_result_get_dict_entry_int32( res2, "tracknr", &itemp );
((struct information *)ptr)->xmms2.tracknr = itemp;
xmmsc_result_get_dict_entry_int( res2, "tracknr", &itemp );
((struct information *)ptr)->xmms2.tracknr = itemp;
xmmsc_result_get_dict_entry_int32( res2, "duration", &itemp );
((struct information *)ptr)->xmms2.duration = itemp;
xmmsc_result_get_dict_entry_int( res2, "duration", &itemp );
((struct information *)ptr)->xmms2.duration = itemp;
xmmsc_result_get_dict_entry_int32( res2, "bitrate", &itemp );
((struct information *)ptr)->xmms2.bitrate = itemp / 1000;
xmmsc_result_get_dict_entry_int( res2, "bitrate", &itemp );
((struct information *)ptr)->xmms2.bitrate = itemp / 1000;
xmmsc_result_get_dict_entry_int32( res2, "size", &itemp );
((struct information *)ptr)->xmms2.size = (float)itemp / 1048576;
xmmsc_result_get_dict_entry_int( res2, "size", &itemp );
((struct information *)ptr)->xmms2.size = (float)itemp / 1048576;
xmmsc_result_unref( res2 );
}
xmmsc_result_unref( res2 );
}
}
void handle_playtime( xmmsc_result_t *res, void *ptr )
{
xmmsc_result_t * res2;
uint play_time;
void handle_playtime( xmmsc_result_t *res, void *ptr ) {
xmmsc_result_t * res2;
uint play_time;
if ( xmmsc_result_iserror( res ) )
return;
if ( xmmsc_result_iserror( res ) )
return;
if ( !xmmsc_result_get_uint( res, &play_time ) )
return;
if ( !xmmsc_result_get_uint( res, &play_time ) )
return;
res2 = xmmsc_result_restart( res );
xmmsc_result_unref( res2 );
res2 = xmmsc_result_restart( res );
xmmsc_result_unref( res2 );
((struct information *)ptr)->xmms2.elapsed = play_time;
((struct information *)ptr)->xmms2.progress = (float) play_time / ((struct information *)ptr)->xmms2.duration;
}
void handle_playback_state_change( xmmsc_result_t *res, void *ptr )
{
uint pb_state = 0;
if ( xmmsc_result_iserror( res ) )
return;
void handle_playback_state_change( xmmsc_result_t *res, void *ptr ) {
uint pb_state = 0;
if ( xmmsc_result_iserror( res ) )
return;
if ( !xmmsc_result_get_uint( res, &pb_state ) )
return;
if ( !xmmsc_result_get_uint( res, &pb_state ) )
return;
if ( ((struct information *)ptr)->xmms2.status == NULL )
((struct information *)ptr)->xmms2.status = malloc( TEXT_BUFFER_SIZE );
if ( ((struct information *)ptr)->xmms2.status == NULL )
((struct information *)ptr)->xmms2.status = malloc( TEXT_BUFFER_SIZE );
switch (pb_state)
{
case XMMS_PLAYBACK_STATUS_PLAY:
strncpy( ((struct information *)ptr)->xmms2.status,
"Playing", TEXT_BUFFER_SIZE - 1 );
switch (pb_state) {
case XMMS_PLAYBACK_STATUS_PLAY:
strncpy( ((struct information *)ptr)->xmms2.status,
"Playing", TEXT_BUFFER_SIZE - 1 );
break;
case XMMS_PLAYBACK_STATUS_PAUSE:
strncpy( ((struct information *)ptr)->xmms2.status,
"Paused", TEXT_BUFFER_SIZE - 1 );
case XMMS_PLAYBACK_STATUS_PAUSE:
strncpy( ((struct information *)ptr)->xmms2.status,
"Paused", TEXT_BUFFER_SIZE - 1 );
break;
case XMMS_PLAYBACK_STATUS_STOP:
strncpy( ((struct information *)ptr)->xmms2.status,
"Stopped", TEXT_BUFFER_SIZE - 1 );
break;
default:
strncpy( ((struct information *)ptr)->xmms2.status,
"Unknown", TEXT_BUFFER_SIZE - 1 );
case XMMS_PLAYBACK_STATUS_STOP:
strncpy( ((struct information *)ptr)->xmms2.status,
"Stopped", TEXT_BUFFER_SIZE - 1 );
break;
default:
strncpy( ((struct information *)ptr)->xmms2.status,
"Unknown", TEXT_BUFFER_SIZE - 1 );
}
}
void update_xmms2()
{
struct information * current_info = &info;
void update_xmms2() {
struct information * current_info = &info;
/* initialize connection */
if ( current_info->xmms2_conn_state == CONN_INIT ) {
/* initialize connection */
if ( current_info->xmms2_conn_state == CONN_INIT ) {
if ( current_info->xmms2_conn == NULL ) {
current_info->xmms2_conn = xmmsc_init( "conky" );
}
if ( current_info->xmms2_conn == NULL ) {
current_info->xmms2_conn = xmmsc_init( "conky" );
}
/* did init fail? */
if ( current_info->xmms2_conn == NULL ) {
fprintf(stderr,"Conky: xmms2 init failed. %s\n",
xmmsc_get_last_error ( current_info->xmms2_conn ));
/* did init fail? */
if ( current_info->xmms2_conn == NULL ) {
fprintf(stderr,"Conky: xmms2 init failed. %s\n", xmmsc_get_last_error ( current_info->xmms2_conn ));
fflush(stderr);
return;
}
@ -285,93 +314,76 @@ void update_xmms2()
current_info->xmms2.size = 0;
current_info->xmms2.progress = 0;
/* fprintf(stderr,"Conky: xmms2 init ok.\n");
fflush(stderr); */
}
/* fprintf(stderr,"Conky: xmms2 init ok.\n");
fflush(stderr); */
}
/* connect */
if ( current_info->xmms2_conn_state == CONN_NO ) {
/* connect */
if ( current_info->xmms2_conn_state == CONN_NO ) {
char *path = getenv ( "XMMS_PATH" );
if ( !xmmsc_connect( current_info->xmms2_conn, path ) )
{
char *path = getenv ( "XMMS_PATH" );
if ( !xmmsc_connect( current_info->xmms2_conn, path ) ) {
fprintf(stderr,"Conky: xmms2 connection failed. %s\n",
xmmsc_get_last_error ( current_info->xmms2_conn ));
xmmsc_get_last_error ( current_info->xmms2_conn ));
fflush(stderr);
current_info->xmms2_conn_state = CONN_NO;
return;
}
/* callbacks */
xmmsc_disconnect_callback_set( current_info->xmms2_conn, connection_lost, current_info );
XMMS_CALLBACK_SET( current_info->xmms2_conn, xmmsc_playback_current_id, handle_curent_id, current_info );
XMMS_CALLBACK_SET( current_info->xmms2_conn, xmmsc_broadcast_playback_current_id, handle_curent_id, current_info );
XMMS_CALLBACK_SET( current_info->xmms2_conn, xmmsc_signal_playback_playtime, handle_playtime, current_info );
XMMS_CALLBACK_SET( current_info->xmms2_conn, xmmsc_broadcast_playback_status, handle_playback_state_change, current_info );
// xmmsc_io_need_out_callback_set(current_info->xmms2_conn, io_need_out_callback, NULL);
current_info->xmms2_fd = xmmsc_io_fd_get( current_info->xmms2_conn );
FD_SET( current_info->xmms2_fd, &current_info->xmms2_fdset );
if ( !current_info->xmms2_fd )
{
/* fprintf(stderr,"Conky: xmms2 cb init failed. %s\n",
xmmsc_get_last_error ( current_info->xmms2_conn ));*/
fflush(stderr);
current_info->xmms2_conn_state = CONN_NO;
return;
current_info->xmms2_conn_state = CONN_NO;
return;
}
/* get playback state.. it wont be broadcasted by xmms2d unless it changes */
xmmsc_result_t * res = xmmsc_playback_status( current_info->xmms2_conn );
xmmsc_result_wait ( res );
unsigned int pb_state;
/* set callbacks */
xmmsc_disconnect_callback_set( current_info->xmms2_conn, connection_lost, current_info );
XMMS_CALLBACK_SET( current_info->xmms2_conn, xmmsc_playback_current_id, handle_curent_id, current_info );
XMMS_CALLBACK_SET( current_info->xmms2_conn, xmmsc_broadcast_playback_current_id, handle_curent_id, current_info );
XMMS_CALLBACK_SET( current_info->xmms2_conn, xmmsc_signal_playback_playtime, handle_playtime, current_info );
XMMS_CALLBACK_SET( current_info->xmms2_conn, xmmsc_broadcast_playback_status, handle_playback_state_change, current_info );
if ( current_info->xmms2.status == NULL )
current_info->xmms2.status = malloc( TEXT_BUFFER_SIZE );
/* get playback status, it wont be broadcasted untill it chages */
xmmsc_result_t * res = xmmsc_playback_status( current_info->xmms2_conn );
xmmsc_result_wait ( res );
unsigned int pb_state;
xmmsc_result_get_uint( res, &pb_state );
switch (pb_state)
{
case XMMS_PLAYBACK_STATUS_PLAY:
strncpy( current_info->xmms2.status,
"Playing", TEXT_BUFFER_SIZE - 1 );
if ( current_info->xmms2.status == NULL )
current_info->xmms2.status = malloc( TEXT_BUFFER_SIZE );
xmmsc_result_get_uint( res, &pb_state );
switch (pb_state) {
case XMMS_PLAYBACK_STATUS_PLAY:
strncpy( current_info->xmms2.status,
"Playing", TEXT_BUFFER_SIZE - 1 );
break;
case XMMS_PLAYBACK_STATUS_PAUSE:
strncpy( current_info->xmms2.status,
"Paused", TEXT_BUFFER_SIZE - 1 );
case XMMS_PLAYBACK_STATUS_PAUSE:
strncpy( current_info->xmms2.status,
"Paused", TEXT_BUFFER_SIZE - 1 );
break;
case XMMS_PLAYBACK_STATUS_STOP:
strncpy( current_info->xmms2.status,
"Stopped", TEXT_BUFFER_SIZE - 1 );
break;
default:
strncpy( current_info->xmms2.status,
"Unknown", TEXT_BUFFER_SIZE - 1 );
case XMMS_PLAYBACK_STATUS_STOP:
strncpy( current_info->xmms2.status,
"Stopped", TEXT_BUFFER_SIZE - 1 );
break;
default:
strncpy( current_info->xmms2.status,
"Unknown", TEXT_BUFFER_SIZE - 1 );
}
xmmsc_result_unref ( res );
/* everything seems to be ok */
current_info->xmms2_conn_state = CONN_OK;
current_info->xmms2_conn_state = CONN_OK;
/* fprintf(stderr,"Conky: xmms2 connected.\n");
fflush(stderr); */
}
/* fprintf(stderr,"Conky: xmms2 connected.\n");
fflush(stderr); */
}
/* handle callbacks */
if ( current_info->xmms2_conn_state == CONN_OK ) {
/* handle callbacks */
if ( current_info->xmms2_conn_state == CONN_OK ) {
struct timeval tmout;
tmout.tv_sec = 0;
tmout.tv_usec = 100;
select( current_info->xmms2_fd + 1,
&current_info->xmms2_fdset, NULL, NULL, &tmout );
select( current_info->xmms2_fd + 1, &current_info->xmms2_fdset, NULL, NULL, &tmout );
xmmsc_io_in_handle(current_info->xmms2_conn);
if (xmmsc_io_want_out(current_info->xmms2_conn)) {
xmmsc_io_out_handle(current_info->xmms2_conn);
}
}
}