mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-16 18:15:17 +00:00
* Fixed potential issue on FreeBSD when nprocs < 10 (thanks zotrix)
* Added support for multiple batteries when using acpi (thanks Phil) * a bunch of code cleanups (thanks Psychon) * added max length paramater to mpd_title (thinks fow) * a number of small bug fixes git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@889 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
parent
906e7e8bfd
commit
f95d63bf56
12
AUTHORS
12
AUTHORS
@ -80,6 +80,9 @@ Fanat1k
|
||||
flitsch <flitsch at users dot sourceforge dot net>
|
||||
hwmon support
|
||||
|
||||
fow <facadedewalls at yahoo dot com>
|
||||
mpd_title max length
|
||||
|
||||
Gwenhael LE MOINE <cycojesus at yahoo dot fr>
|
||||
Manual setting of the position
|
||||
WM_CLASS for window when drawing to own window
|
||||
@ -176,6 +179,12 @@ Philip Kovacs <pkovacs at users dot sourceforge dot net>
|
||||
Audacious, Xmms, BMP, Infopipe stuff
|
||||
Various Xlib changes, e.g. own_window hints, etc.
|
||||
|
||||
Phil <n0-1 at users dot sourceforge dot net>
|
||||
multiple batteries support
|
||||
|
||||
Psychon <psychon at users dot sourceforge dot net>
|
||||
a bunch of code cleanups
|
||||
|
||||
roiban adi <adiroiban at users dot sourceforge dot net>
|
||||
hex colour patch
|
||||
|
||||
@ -217,3 +226,6 @@ William DiPlacido <bimbasaari at yahoo dot com>
|
||||
|
||||
zimba-tm <zimba-tm at users dot sourceforge dot net>
|
||||
alignment none patch
|
||||
|
||||
zotrix <zotrix at users dot sourceforge dot net>
|
||||
FreeBSD patch for <10 procs
|
||||
|
@ -1,5 +1,12 @@
|
||||
# $Id$
|
||||
|
||||
2007-08-04
|
||||
* Fixed potential issue on FreeBSD when nprocs < 10 (thanks zotrix)
|
||||
* Added support for multiple batteries when using acpi (thanks Phil)
|
||||
* a bunch of code cleanups (thanks Psychon)
|
||||
* added max length paramater to mpd_title (thinks fow)
|
||||
* a number of small bug fixes
|
||||
|
||||
2007-07-15
|
||||
* Fix PID display, patch #1753934. thanks sohalt.
|
||||
* Fix displaying 4 GB traffic after reloading network driver,
|
||||
|
@ -1192,6 +1192,7 @@
|
||||
<varlistentry>
|
||||
<term>
|
||||
<command><option>mpd_title</option></command>
|
||||
<option>(max length)</option>
|
||||
</term>
|
||||
<listitem>
|
||||
Title of current MPD song
|
||||
|
@ -5,7 +5,7 @@
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <bmp/dbus.h>
|
||||
#include <bmp/dbus.hh>
|
||||
#include <dbus/dbus-glib.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
69
src/conky.c
69
src/conky.c
@ -299,7 +299,6 @@ static int draw_shades, draw_outline;
|
||||
static int border_margin, border_width;
|
||||
|
||||
static long default_fg_color, default_bg_color, default_out_color;
|
||||
static long color0, color1, color2, color3, color4, color5, color6, color7, color8, color9;
|
||||
|
||||
/* create own window or draw stuff to root? */
|
||||
static int set_transparent = 0;
|
||||
@ -321,6 +320,8 @@ static int maximum_width;
|
||||
static int sensor_device;
|
||||
#endif
|
||||
|
||||
static long color0, color1, color2, color3, color4, color5, color6, color7, color8, color9;
|
||||
|
||||
/* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
|
||||
static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
|
||||
|
||||
@ -429,42 +430,6 @@ static int blockdepth = 0;
|
||||
static int if_jumped = 0;
|
||||
static int blockstart[MAX_IF_BLOCK_DEPTH];
|
||||
|
||||
int check_mount(char *s)
|
||||
{
|
||||
#if defined(__linux__)
|
||||
int ret = 0;
|
||||
FILE *mtab = fopen("/etc/mtab", "r");
|
||||
if (mtab) {
|
||||
char buf1[256], buf2[128];
|
||||
while (fgets(buf1, 256, mtab)) {
|
||||
sscanf(buf1, "%*s %128s", buf2);
|
||||
if (!strcmp(s, buf2)) {
|
||||
ret = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(mtab);
|
||||
} else {
|
||||
ERR("Could not open mtab");
|
||||
}
|
||||
return ret;
|
||||
#elif defined(__FreeBSD__)
|
||||
struct statfs *mntbuf;
|
||||
int i, mntsize;
|
||||
|
||||
mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
|
||||
for (i = mntsize - 1; i >= 0; i--)
|
||||
if (strcmp(mntbuf[i].f_mntonname, s) == 0)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
#elif defined(__OpenBSD__)
|
||||
/* stub */
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int check_contains(char *f, char *s)
|
||||
{
|
||||
int ret = 0;
|
||||
@ -1865,7 +1830,8 @@ static void free_text_objects(unsigned int count, struct text_object *objs)
|
||||
free(objs[i].data.tail.logfile);
|
||||
free(objs[i].data.tail.buffer);
|
||||
break;
|
||||
case OBJ_text: case OBJ_font:
|
||||
case OBJ_text:
|
||||
case OBJ_font:
|
||||
free(objs[i].data.s);
|
||||
break;
|
||||
case OBJ_image:
|
||||
@ -2366,8 +2332,7 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
|
||||
obj->data.l = color9;
|
||||
END OBJ(font, 0)
|
||||
obj->data.s = scan_font(arg);
|
||||
END
|
||||
OBJ(downspeed, INFO_NET)
|
||||
END OBJ(downspeed, INFO_NET)
|
||||
if(arg) {
|
||||
obj->data.net = get_net_stat(arg);
|
||||
}
|
||||
@ -3032,8 +2997,18 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
|
||||
}
|
||||
END
|
||||
#ifdef MPD
|
||||
OBJ(mpd_artist, INFO_MPD)
|
||||
END OBJ(mpd_title, INFO_MPD)
|
||||
OBJ(mpd_artist, INFO_MPD) END
|
||||
OBJ(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++;
|
||||
else
|
||||
CRIT_ERR ("mpd_title: invalid length argument");
|
||||
}
|
||||
}
|
||||
END OBJ(mpd_random, INFO_MPD)
|
||||
END OBJ(mpd_repeat, INFO_MPD)
|
||||
END OBJ(mpd_elapsed, INFO_MPD)
|
||||
@ -3718,11 +3693,11 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
|
||||
}
|
||||
#endif /* __OpenBSD__ */
|
||||
|
||||
#ifdef X11
|
||||
OBJ(font) {
|
||||
#ifdef X11
|
||||
new_font(p, obj->data.s);
|
||||
}
|
||||
#endif /* X11 */
|
||||
}
|
||||
void format_diskio(unsigned int diskio_value)
|
||||
{
|
||||
if (!use_spacer) {
|
||||
@ -4635,7 +4610,7 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
|
||||
trans_speed /
|
||||
1024));
|
||||
else
|
||||
snprintf(p, 5, "%d ",
|
||||
snprintf(p, 6, "%d ",
|
||||
(int) (obj->data.net->
|
||||
trans_speed /
|
||||
1024));
|
||||
@ -4690,7 +4665,9 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
|
||||
|
||||
#ifdef MPD
|
||||
OBJ(mpd_title) {
|
||||
snprintf(p, p_max_size, "%s", cur->mpd.title);
|
||||
snprintf(p, cur->mpd.max_title_len > 0 ?
|
||||
cur->mpd.max_title_len : p_max_size, "%s",
|
||||
cur->mpd.title);
|
||||
}
|
||||
OBJ(mpd_artist) {
|
||||
snprintf(p, p_max_size, "%s", cur->mpd.artist);
|
||||
|
@ -155,6 +155,7 @@ struct mpd_s {
|
||||
int bitrate;
|
||||
int length;
|
||||
int elapsed;
|
||||
int max_title_len; /* e.g. ${mpd_title 50} */
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -462,6 +463,7 @@ extern int no_buffers;
|
||||
|
||||
/* system dependant (in linux.c) */
|
||||
|
||||
int check_mount(char *s);
|
||||
void update_diskio(void);
|
||||
void prepare_update(void);
|
||||
void update_uptime(void);
|
||||
|
@ -113,6 +113,19 @@ update_uptime()
|
||||
}
|
||||
}
|
||||
|
||||
int check_mount(char *s)
|
||||
{
|
||||
struct statfs *mntbuf;
|
||||
int i, mntsize;
|
||||
|
||||
mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
|
||||
for (i = mntsize - 1; i >= 0; i--)
|
||||
if (strcmp(mntbuf[i].f_mntonname, s) == 0)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
update_meminfo()
|
||||
{
|
||||
@ -753,7 +766,7 @@ proc_find_top(struct process **cpu, struct process **mem)
|
||||
}
|
||||
|
||||
qsort(processes, j - 1, sizeof (struct process), comparemem);
|
||||
for (i = 0; i < 10; i++) {
|
||||
for (i = 0; i < 10 && i < n_processes; i++) {
|
||||
struct process *tmp, *ttmp;
|
||||
|
||||
tmp = malloc(sizeof (struct process));
|
||||
@ -771,7 +784,7 @@ proc_find_top(struct process **cpu, struct process **mem)
|
||||
}
|
||||
|
||||
qsort(processes, j - 1, sizeof (struct process), comparecpu);
|
||||
for (i = 0; i < 10; i++) {
|
||||
for (i = 0; i < 10 && i < n_processes; i++) {
|
||||
struct process *tmp, *ttmp;
|
||||
|
||||
tmp = malloc(sizeof (struct process));
|
||||
|
384
src/linux.c
384
src/linux.c
@ -38,8 +38,8 @@
|
||||
static int show_nice_processes;
|
||||
|
||||
/* this flags tells the linux routines to use the /proc system
|
||||
* where possible, even if other api's are available, e.g. sysinfo()
|
||||
* or getloadavg(). the reason for this is to allow for /proc-based
|
||||
* where possible, even if other api's are available, e.g. sysinfo()
|
||||
* or getloadavg(). the reason for this is to allow for /proc-based
|
||||
* distributed monitoring. using a flag in this manner creates less
|
||||
* confusing code.
|
||||
*/
|
||||
@ -63,7 +63,7 @@ void update_uptime()
|
||||
{
|
||||
static int rep = 0;
|
||||
FILE *fp;
|
||||
|
||||
|
||||
if (!(fp = open_file("/proc/uptime", &rep)))
|
||||
{
|
||||
info.uptime=0.0;
|
||||
@ -75,6 +75,26 @@ void update_uptime()
|
||||
info.mask |= (1 << INFO_UPTIME);
|
||||
}
|
||||
|
||||
int check_mount(char *s)
|
||||
{
|
||||
int ret = 0;
|
||||
FILE *mtab = fopen("/etc/mtab", "r");
|
||||
if (mtab) {
|
||||
char buf1[256], buf2[128];
|
||||
while (fgets(buf1, 256, mtab)) {
|
||||
sscanf(buf1, "%*s %128s", buf2);
|
||||
if (!strcmp(s, buf2)) {
|
||||
ret = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(mtab);
|
||||
} else {
|
||||
ERR("Could not open mtab");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* these things are also in sysinfo except Buffers:, that's why I'm reading
|
||||
* them from proc */
|
||||
|
||||
@ -109,7 +129,7 @@ void update_meminfo()
|
||||
sscanf(buf, "%*s %Lu", &info.cached);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
info.mem = info.memmax - info.mem;
|
||||
info.swap = info.swapmax - info.swap;
|
||||
|
||||
@ -344,14 +364,14 @@ struct cpu_info {
|
||||
};
|
||||
static short cpu_setup = 0;
|
||||
|
||||
/*
|
||||
determine if this kernel gives us "extended" statistics information in /proc/stat.
|
||||
Kernels around 2.5 and earlier only reported user, system, nice and idle values in proc stat.
|
||||
Kernels around 2.6 and greater report these PLUS iowait, irq, softirq, and steal
|
||||
/*
|
||||
determine if this kernel gives us "extended" statistics information in /proc/stat.
|
||||
Kernels around 2.5 and earlier only reported user, system, nice and idle values in proc stat.
|
||||
Kernels around 2.6 and greater report these PLUS iowait, irq, softirq, and steal
|
||||
*/
|
||||
void determine_longstat(char * buf) {
|
||||
void determine_longstat(char * buf) {
|
||||
unsigned long long iowait=0;
|
||||
KFLAG_SETOFF(KFLAG_IS_LONGSTAT);
|
||||
KFLAG_SETOFF(KFLAG_IS_LONGSTAT);
|
||||
/* scanf will either return -1 or 1 because there is only 1 assignment */
|
||||
if (sscanf(buf, "%*s %*d %*d %*d %*d %llu",&iowait)>0) KFLAG_SETON(KFLAG_IS_LONGSTAT);
|
||||
}
|
||||
@ -399,9 +419,9 @@ inline static void update_stat()
|
||||
unsigned int i;
|
||||
unsigned int index;
|
||||
double curtmp;
|
||||
char * stat_template=NULL;
|
||||
char * stat_template=NULL;
|
||||
unsigned int malloc_cpu_size=0;
|
||||
|
||||
|
||||
|
||||
/* add check for !info.cpu_usage since that mem is freed on a SIGUSR1 */
|
||||
if (!cpu_setup || !info.cpu_usage) {
|
||||
@ -411,7 +431,7 @@ inline static void update_stat()
|
||||
|
||||
if (!stat_template) {
|
||||
stat_template = KFLAG_ISSET(KFLAG_IS_LONGSTAT) ? TMPL_LONGSTAT : TMPL_SHORTSTAT ;
|
||||
}
|
||||
}
|
||||
|
||||
if (!cpu) {
|
||||
malloc_cpu_size = (info.cpu_count + 1) * sizeof(struct cpu_info);
|
||||
@ -439,7 +459,7 @@ inline static void update_stat()
|
||||
info.mask |= (1 << INFO_RUN_PROCS);
|
||||
} else if (strncmp(buf, "cpu", 3) == 0) {
|
||||
index = isdigit(buf[3]) ? ((int)buf[3]) - 0x2F : 0;
|
||||
sscanf(buf, stat_template
|
||||
sscanf(buf, stat_template
|
||||
, &(cpu[index].cpu_user)
|
||||
, &(cpu[index].cpu_nice)
|
||||
, &(cpu[index].cpu_system)
|
||||
@ -450,32 +470,32 @@ inline static void update_stat()
|
||||
, &(cpu[index].cpu_steal)
|
||||
);
|
||||
|
||||
cpu[index].cpu_total = cpu[index].cpu_user
|
||||
+ cpu[index].cpu_nice
|
||||
+ cpu[index].cpu_system
|
||||
+ cpu[index].cpu_idle
|
||||
+ cpu[index].cpu_iowait
|
||||
cpu[index].cpu_total = cpu[index].cpu_user
|
||||
+ cpu[index].cpu_nice
|
||||
+ cpu[index].cpu_system
|
||||
+ cpu[index].cpu_idle
|
||||
+ cpu[index].cpu_iowait
|
||||
+ cpu[index].cpu_irq
|
||||
+ cpu[index].cpu_softirq
|
||||
+ cpu[index].cpu_steal
|
||||
;
|
||||
+ cpu[index].cpu_steal
|
||||
;
|
||||
|
||||
cpu[index].cpu_active_total = cpu[index].cpu_total - (cpu[index].cpu_idle + cpu[index].cpu_iowait);
|
||||
info.mask |= (1 << INFO_CPU);
|
||||
|
||||
double delta = current_update_time - last_update_time;
|
||||
if (delta <= 0.001) break;
|
||||
if (delta <= 0.001) break;
|
||||
|
||||
cpu[index].cpu_val[0] = (cpu[index].cpu_active_total - cpu[index].cpu_last_active_total) /
|
||||
(float )(cpu[index].cpu_total - cpu[index].cpu_last_total);
|
||||
cpu[index].cpu_val[0] = (cpu[index].cpu_active_total - cpu[index].cpu_last_active_total) /
|
||||
(float )(cpu[index].cpu_total - cpu[index].cpu_last_total);
|
||||
curtmp = 0;
|
||||
for (i=0; i < info.cpu_avg_samples; i++ ) {
|
||||
curtmp += cpu[index].cpu_val[i];
|
||||
}
|
||||
/* TESTING -- I've removed this, because I don't think it is right. You shouldn't divide
|
||||
/* TESTING -- I've removed this, because I don't think it is right. You shouldn't divide
|
||||
by the cpu count here ... removing for testing */
|
||||
/* if (index == 0) {
|
||||
info.cpu_usage[index] = curtmp / info.cpu_avg_samples / info.cpu_count;
|
||||
info.cpu_usage[index] = curtmp / info.cpu_avg_samples / info.cpu_count;
|
||||
} else {
|
||||
info.cpu_usage[index] = curtmp / info.cpu_avg_samples;
|
||||
} */
|
||||
@ -555,8 +575,8 @@ void update_i8k()
|
||||
i8k.bios = strtok(NULL,I8K_DELIM);
|
||||
i8k.serial = strtok(NULL,I8K_DELIM);
|
||||
i8k.cpu_temp = strtok(NULL,I8K_DELIM);
|
||||
i8k.left_fan_status = strtok(NULL,I8K_DELIM);
|
||||
i8k.right_fan_status = strtok(NULL,I8K_DELIM);
|
||||
i8k.left_fan_status = strtok(NULL,I8K_DELIM);
|
||||
i8k.right_fan_status = strtok(NULL,I8K_DELIM);
|
||||
i8k.left_fan_rpm = strtok(NULL,I8K_DELIM);
|
||||
i8k.right_fan_rpm = strtok(NULL,I8K_DELIM);
|
||||
i8k.ac_status = strtok(NULL,I8K_DELIM);
|
||||
@ -700,7 +720,7 @@ double get_i2c_info(int *fd, int div, char *devtype, char *type)
|
||||
if (*fd < 0)
|
||||
ERR("can't open '%s': %s", devtype, strerror(errno));
|
||||
|
||||
/* My dirty hack for computing CPU value
|
||||
/* My dirty hack for computing CPU value
|
||||
* Filedil, from forums.gentoo.org
|
||||
*/
|
||||
/* if (strstr(devtype, "temp1_input") != NULL)
|
||||
@ -774,7 +794,7 @@ void get_adt746x_cpu( char * p_client_buffer, size_t client_buffer_size )
|
||||
|
||||
if ( !p_client_buffer || client_buffer_size <= 0 )
|
||||
return;
|
||||
|
||||
|
||||
if ((fp = open_file(ADT746X_CPU, &rep)) == NULL
|
||||
&& (fp = open_file(ADT746X_CPU_OLD, &rep)) == NULL)
|
||||
{
|
||||
@ -786,7 +806,7 @@ void get_adt746x_cpu( char * p_client_buffer, size_t client_buffer_size )
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
snprintf( p_client_buffer, client_buffer_size, "%s", adt746x_cpu_state );
|
||||
snprintf( p_client_buffer, client_buffer_size, "%s", adt746x_cpu_state );
|
||||
return;
|
||||
}
|
||||
|
||||
@ -843,8 +863,8 @@ void get_freq_dynamic( char * p_client_buffer, size_t client_buffer_size, char *
|
||||
#else
|
||||
/* FIXME: hardwired: get freq for first cpu!
|
||||
this whole function needs to be rethought and redone for
|
||||
multi-cpu/multi-core/multi-threaded environments and
|
||||
arbitrary combinations thereof
|
||||
multi-cpu/multi-core/multi-threaded environments and
|
||||
arbitrary combinations thereof
|
||||
*/
|
||||
get_freq( p_client_buffer, client_buffer_size, p_format, divisor, 1 );
|
||||
return;
|
||||
@ -863,16 +883,16 @@ char get_freq( char * p_client_buffer, size_t client_buffer_size, char * p_forma
|
||||
char frequency[32];
|
||||
char s[256];
|
||||
double freq = 0;
|
||||
|
||||
|
||||
if ( !p_client_buffer || client_buffer_size <= 0 || !p_format || divisor <= 0 )
|
||||
return 0;
|
||||
|
||||
|
||||
if (!prefer_proc)
|
||||
{
|
||||
char current_freq_file[128];
|
||||
snprintf(current_freq_file, 127, "%s/cpu%d/%s",CPUFREQ_PREFIX, cpu-1, CPUFREQ_POSTFIX);
|
||||
f = fopen(current_freq_file, "r");
|
||||
if (f)
|
||||
if (f)
|
||||
{
|
||||
/* if there's a cpufreq /sys node, read the current frequency from this node;
|
||||
* divide by 1000 to get Mhz. */
|
||||
@ -885,7 +905,7 @@ char get_freq( char * p_client_buffer, size_t client_buffer_size, char * p_forma
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
f = open_file("/proc/cpuinfo", &rep); //open the CPU information file
|
||||
if (!f) {
|
||||
perror("Conky: Failed to access '/proc/cpuinfo' at get_freq()");
|
||||
@ -907,7 +927,7 @@ char get_freq( char * p_client_buffer, size_t client_buffer_size, char * p_forma
|
||||
strcpy(frequency, strchr(s, ':') + 2); //copy just the number
|
||||
#if defined(__alpha)
|
||||
frequency[strlen(frequency) - 6] = '\0';// strip " est.\n"
|
||||
freq = strtod(frequency, NULL)/1000000; // kernel reports in Hz
|
||||
freq = strtod(frequency, NULL)/1000000; // kernel reports in Hz
|
||||
#else
|
||||
frequency[strlen(frequency) - 1] = '\0'; // strip \n
|
||||
freq = strtod(frequency, NULL);
|
||||
@ -915,12 +935,12 @@ char get_freq( char * p_client_buffer, size_t client_buffer_size, char * p_forma
|
||||
break;
|
||||
}
|
||||
if (strncmp(s, "processor", 9) == 0) {
|
||||
cpu--;
|
||||
cpu--;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
fclose(f);
|
||||
snprintf( p_client_buffer, client_buffer_size, p_format, (float)freq/divisor );
|
||||
return 1;
|
||||
@ -931,7 +951,7 @@ char get_freq( char * p_client_buffer, size_t client_buffer_size, char * p_forma
|
||||
/* return cpu voltage in mV (use divisor=1) or V (use divisor=1000) */
|
||||
char get_voltage( char * p_client_buffer, size_t client_buffer_size, char * p_format, int divisor, unsigned int cpu )
|
||||
{
|
||||
/* /sys/devices/system/cpu/cpu0/cpufreq/scaling_voltages looks
|
||||
/* /sys/devices/system/cpu/cpu0/cpufreq/scaling_voltages looks
|
||||
something like this:
|
||||
# frequency voltage
|
||||
1800000 1340
|
||||
@ -950,7 +970,7 @@ char get_voltage( char * p_client_buffer, size_t client_buffer_size, char * p_fo
|
||||
int voltage = 0;
|
||||
char current_freq_file[128];
|
||||
int freq_comp = 0;
|
||||
|
||||
|
||||
|
||||
/* build the voltage file name */
|
||||
cpu--;
|
||||
@ -1055,11 +1075,11 @@ void get_acpi_ac_adapter( char * p_client_buffer, size_t client_buffer_size )
|
||||
if (!get_first_file_in_a_directory(ACPI_AC_ADAPTER_DIR, buf, &rep))
|
||||
{
|
||||
snprintf( p_client_buffer, client_buffer_size, "no ac_adapters?" );
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
snprintf(buf2, sizeof(buf2), "%s%s/state", ACPI_AC_ADAPTER_DIR, buf );
|
||||
|
||||
|
||||
|
||||
fp = open_file(buf2, &rep);
|
||||
if (!fp) {
|
||||
@ -1149,7 +1169,7 @@ double get_acpi_temperature(int fd)
|
||||
}
|
||||
|
||||
/*
|
||||
hipo@lepakko hipo $ cat /proc/acpi/battery/BAT1/info
|
||||
hipo@lepakko hipo $ cat /proc/acpi/battery/BAT1/info
|
||||
present: yes
|
||||
design capacity: 4400 mAh
|
||||
last full capacity: 4064 mAh
|
||||
@ -1176,10 +1196,10 @@ present voltage: 16608 mV
|
||||
*/
|
||||
|
||||
/*
|
||||
2213<@jupet kellari ö> jupet@lagi-unstable:~$ cat /proc/apm
|
||||
2213<@jupet kellari ö> jupet@lagi-unstable:~$ cat /proc/apm
|
||||
2213<@jupet kellari ö> 1.16 1.2 0x03 0x01 0xff 0x10 -1% -1 ?
|
||||
2213<@jupet kellari ö> (-1 ollee ei akkua kiinni, koska akku on pöydällä)
|
||||
2214<@jupet kellari ö> jupet@lagi-unstable:~$ cat /proc/apm
|
||||
2214<@jupet kellari ö> jupet@lagi-unstable:~$ cat /proc/apm
|
||||
2214<@jupet kellari ö> 1.16 1.2 0x03 0x01 0x03 0x09 98% -1 ?
|
||||
|
||||
2238<@jupet kellari ö> 1.16 1.2 0x03 0x00 0x00 0x01 100% -1 ? ilman verkkovirtaa
|
||||
@ -1191,51 +1211,84 @@ present voltage: 16608 mV
|
||||
|
||||
#define ACPI_BATTERY_BASE_PATH "/proc/acpi/battery"
|
||||
#define APM_PATH "/proc/apm"
|
||||
#define MAX_BATTERY_COUNT 4
|
||||
|
||||
static FILE *acpi_bat_fp;
|
||||
static FILE *apm_bat_fp;
|
||||
static FILE *acpi_bat_fp[MAX_BATTERY_COUNT];
|
||||
static FILE *apm_bat_fp[MAX_BATTERY_COUNT];
|
||||
|
||||
static int acpi_last_full;
|
||||
static int acpi_design_capacity;
|
||||
static int batteries_initialized = 0;
|
||||
static char batteries[MAX_BATTERY_COUNT][32];
|
||||
|
||||
static char last_battery_str[64]; /* e.g. "charging 75%" */
|
||||
static char last_battery_time_str[64]; /* e.g. "3h 15m" */
|
||||
static int acpi_last_full[MAX_BATTERY_COUNT];
|
||||
static int acpi_design_capacity[MAX_BATTERY_COUNT];
|
||||
|
||||
static double last_battery_time;
|
||||
static char last_battery_str[MAX_BATTERY_COUNT][64]; /* e.g. "charging 75%" */
|
||||
static char last_battery_time_str[MAX_BATTERY_COUNT][64]; /* e.g. "3h 15m" */
|
||||
|
||||
static int last_battery_perct;
|
||||
static double last_battery_perct_time;
|
||||
static double last_battery_time[MAX_BATTERY_COUNT];
|
||||
|
||||
static int last_battery_perct[MAX_BATTERY_COUNT];
|
||||
static double last_battery_perct_time[MAX_BATTERY_COUNT];
|
||||
|
||||
|
||||
void init_batteries(void)
|
||||
{
|
||||
int idx;
|
||||
if(batteries_initialized)
|
||||
return;
|
||||
for(idx = 0; idx < MAX_BATTERY_COUNT; idx++)
|
||||
batteries[idx][0] = '\0';
|
||||
batteries_initialized = 1;
|
||||
}
|
||||
|
||||
int get_battery_idx(const char *bat)
|
||||
{
|
||||
int idx;
|
||||
for(idx = 0; idx < MAX_BATTERY_COUNT; idx++)
|
||||
if(!strlen(batteries[idx]) || !strcmp(batteries[idx], bat))
|
||||
break;
|
||||
|
||||
/* if not found, enter a new entry */
|
||||
if(!strlen(batteries[idx]))
|
||||
snprintf(batteries[idx], 31, "%s", bat);
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item)
|
||||
{
|
||||
static int rep = 0, rep2 = 0;
|
||||
static int idx, rep = 0, rep2 = 0;
|
||||
char acpi_path[128];
|
||||
snprintf(acpi_path, 127, ACPI_BATTERY_BASE_PATH "/%s/state", bat);
|
||||
|
||||
init_batteries();
|
||||
|
||||
idx = get_battery_idx(bat);
|
||||
|
||||
/* don't update battery too often */
|
||||
if (current_update_time - last_battery_time < 29.5)
|
||||
goto set_return_value;
|
||||
if (current_update_time - last_battery_time[idx] < 29.5)
|
||||
goto set_return_value;
|
||||
|
||||
last_battery_time = current_update_time;
|
||||
last_battery_time[idx] = current_update_time;
|
||||
|
||||
memset (last_battery_str, 0, sizeof (last_battery_str));
|
||||
memset (last_battery_time_str, 0, sizeof (last_battery_time_str));
|
||||
memset (last_battery_str[idx], 0, sizeof (last_battery_str[idx]));
|
||||
memset (last_battery_time_str[idx], 0, sizeof (last_battery_time_str[idx]));
|
||||
|
||||
/* first try ACPI */
|
||||
|
||||
if (acpi_bat_fp == NULL && apm_bat_fp == NULL)
|
||||
acpi_bat_fp = open_file(acpi_path, &rep);
|
||||
if (acpi_bat_fp[idx] == NULL && apm_bat_fp[idx] == NULL)
|
||||
acpi_bat_fp[idx] = open_file(acpi_path, &rep);
|
||||
|
||||
if (acpi_bat_fp != NULL) {
|
||||
if (acpi_bat_fp[idx] != NULL) {
|
||||
int present_rate = -1;
|
||||
int remaining_capacity = -1;
|
||||
char charging_state[64];
|
||||
char present[4];
|
||||
|
||||
/* read last full capacity if it's zero */
|
||||
if (acpi_last_full == 0) {
|
||||
if (acpi_last_full[idx] == 0) {
|
||||
static int rep = 0;
|
||||
char path[128];
|
||||
char path[128];
|
||||
FILE *fp;
|
||||
snprintf(path, 127,
|
||||
ACPI_BATTERY_BASE_PATH "/%s/info", bat);
|
||||
@ -1245,7 +1298,7 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item)
|
||||
char b[256];
|
||||
if (fgets(b, 256, fp) == NULL)
|
||||
break;
|
||||
if (sscanf(b, "last full capacity: %d", &acpi_last_full) != 0) {
|
||||
if (sscanf(b, "last full capacity: %d", &acpi_last_full[idx]) != 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1254,17 +1307,17 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item)
|
||||
}
|
||||
}
|
||||
|
||||
fseek(acpi_bat_fp, 0, SEEK_SET);
|
||||
fseek(acpi_bat_fp[idx], 0, SEEK_SET);
|
||||
|
||||
strcpy(charging_state, "unknown");
|
||||
|
||||
while (!feof(acpi_bat_fp)) {
|
||||
while (!feof(acpi_bat_fp[idx])) {
|
||||
char buf[256];
|
||||
if (fgets(buf, 256, acpi_bat_fp) == NULL)
|
||||
if (fgets(buf, 256, acpi_bat_fp[idx]) == NULL)
|
||||
break;
|
||||
|
||||
/* let's just hope units are ok */
|
||||
if (strncmp (buf, "present:", 8) == 0)
|
||||
if (strncmp (buf, "present:", 8) == 0)
|
||||
sscanf(buf, "present: %4s", present);
|
||||
else if (strncmp (buf, "charging state:", 15) == 0)
|
||||
sscanf(buf, "charging state: %63s", charging_state);
|
||||
@ -1275,88 +1328,94 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item)
|
||||
}
|
||||
|
||||
/* Hellf[i]re notes that remaining capacity can exceed acpi_last_full */
|
||||
if (remaining_capacity > acpi_last_full)
|
||||
acpi_last_full = remaining_capacity; /* normalize to 100% */
|
||||
if (remaining_capacity > acpi_last_full[idx])
|
||||
acpi_last_full[idx] = remaining_capacity; /* normalize to 100% */
|
||||
|
||||
/* not present */
|
||||
if (strcmp(present, "no") == 0) {
|
||||
strncpy(last_battery_str, "not present", 64);
|
||||
strncpy(last_battery_str[idx], "not present", 64);
|
||||
}
|
||||
/* charging */
|
||||
else if (strcmp(charging_state, "charging") == 0) {
|
||||
if (acpi_last_full != 0 && present_rate > 0) {
|
||||
if (acpi_last_full[idx] != 0 && present_rate > 0) {
|
||||
/* e.g. charging 75% */
|
||||
snprintf(last_battery_str, sizeof(last_battery_str)-1, "charging %i%%",
|
||||
(int) ((remaining_capacity * 100) / acpi_last_full));
|
||||
snprintf(last_battery_str[idx], sizeof(last_battery_str[idx])-1, "charging %i%%",
|
||||
(int) ((remaining_capacity * 100) / acpi_last_full[idx]));
|
||||
/* e.g. 2h 37m */
|
||||
format_seconds(last_battery_time_str, sizeof(last_battery_time_str)-1,
|
||||
(long) (((acpi_last_full - remaining_capacity) * 3600) /
|
||||
format_seconds(last_battery_time_str[idx], sizeof(last_battery_time_str[idx])-1,
|
||||
(long) (((acpi_last_full[idx] - remaining_capacity) * 3600) /
|
||||
present_rate));
|
||||
} else if (acpi_last_full != 0 && present_rate <= 0) {
|
||||
snprintf(last_battery_str, sizeof(last_battery_str)-1, "charging %d%%",
|
||||
(int) ((remaining_capacity * 100) / acpi_last_full));
|
||||
} else if (acpi_last_full[idx] != 0 && present_rate <= 0) {
|
||||
snprintf(last_battery_str[idx], sizeof(last_battery_str[idx])-1, "charging %d%%",
|
||||
(int) ((remaining_capacity * 100) / acpi_last_full[idx]));
|
||||
} else {
|
||||
strncpy(last_battery_str, "charging", sizeof(last_battery_str)-1);
|
||||
strncpy(last_battery_str[idx], "charging", sizeof(last_battery_str[idx])-1);
|
||||
}
|
||||
}
|
||||
/* discharging */
|
||||
else if (strncmp(charging_state, "discharging", 64) == 0) {
|
||||
if (present_rate > 0) {
|
||||
/* e.g. discharging 35% */
|
||||
snprintf(last_battery_str, sizeof(last_battery_str)-1, "discharging %i%%",
|
||||
(int) ((remaining_capacity * 100) / acpi_last_full));
|
||||
snprintf(last_battery_str[idx], sizeof(last_battery_str[idx])-1, "discharging %i%%",
|
||||
(int) ((remaining_capacity * 100) / acpi_last_full[idx]));
|
||||
/* e.g. 1h 12m */
|
||||
format_seconds(last_battery_time_str, sizeof(last_battery_time_str)-1,
|
||||
format_seconds(last_battery_time_str[idx], sizeof(last_battery_time_str[idx])-1,
|
||||
(long) ((remaining_capacity * 3600) / present_rate));
|
||||
} else if (present_rate == 0) { /* Thanks to Nexox for this one */
|
||||
snprintf(last_battery_str, sizeof(last_battery_str)-1, "full");
|
||||
snprintf(last_battery_str[idx], sizeof(last_battery_str[idx])-1, "full");
|
||||
} else {
|
||||
snprintf(last_battery_str, sizeof(last_battery_str)-1,
|
||||
snprintf(last_battery_str[idx], sizeof(last_battery_str[idx])-1,
|
||||
"discharging %d%%",
|
||||
(int) ((remaining_capacity * 100) / acpi_last_full));
|
||||
(int) ((remaining_capacity * 100) / acpi_last_full[idx]));
|
||||
}
|
||||
}
|
||||
/* charged */
|
||||
/* thanks to Lukas Zapletal <lzap@seznam.cz> */
|
||||
else if (strncmp(charging_state, "charged", 64) == 0) {
|
||||
strcpy(last_battery_str, "charged");
|
||||
}
|
||||
/* Below happens with the second battery on my X40,
|
||||
* when the second one is empty and the first one
|
||||
* being charged. */
|
||||
if (remaining_capacity == 0)
|
||||
strcpy(last_battery_str[idx], "empty");
|
||||
else
|
||||
strcpy(last_battery_str[idx], "charged");
|
||||
}
|
||||
/* unknown, probably full / AC */
|
||||
else {
|
||||
if (acpi_last_full != 0
|
||||
&& remaining_capacity != acpi_last_full)
|
||||
snprintf(last_battery_str, 64, "unknown %d%%",
|
||||
(int) ((remaining_capacity * 100) / acpi_last_full));
|
||||
if (acpi_last_full[idx] != 0
|
||||
&& remaining_capacity != acpi_last_full[idx])
|
||||
snprintf(last_battery_str[idx], 64, "unknown %d%%",
|
||||
(int) ((remaining_capacity * 100) / acpi_last_full[idx]));
|
||||
else
|
||||
strncpy(last_battery_str, "AC", 64);
|
||||
strncpy(last_battery_str[idx], "AC", 64);
|
||||
}
|
||||
} else {
|
||||
/* APM */
|
||||
if (apm_bat_fp == NULL)
|
||||
apm_bat_fp = open_file(APM_PATH, &rep2);
|
||||
if (apm_bat_fp[idx] == NULL)
|
||||
apm_bat_fp[idx] = open_file(APM_PATH, &rep2);
|
||||
|
||||
if (apm_bat_fp != NULL) {
|
||||
if (apm_bat_fp[idx] != NULL) {
|
||||
int ac, status, flag, life;
|
||||
|
||||
fscanf(apm_bat_fp,
|
||||
fscanf(apm_bat_fp[idx],
|
||||
"%*s %*s %*x %x %x %x %d%%",
|
||||
&ac, &status, &flag, &life);
|
||||
|
||||
if (life == -1) {
|
||||
/* could check now that there is ac */
|
||||
snprintf(last_battery_str, 64, "AC");
|
||||
snprintf(last_battery_str[idx], 64, "AC");
|
||||
} else if (ac && life != 100) { /* could check that status==3 here? */
|
||||
snprintf(last_battery_str, 64,
|
||||
snprintf(last_battery_str[idx], 64,
|
||||
"charging %d%%", life);
|
||||
} else {
|
||||
snprintf(last_battery_str, 64, "%d%%",
|
||||
snprintf(last_battery_str[idx], 64, "%d%%",
|
||||
life);
|
||||
}
|
||||
|
||||
/* it seemed to buffer it so file must be closed (or could use syscalls
|
||||
* directly but I don't feel like coding it now) */
|
||||
fclose(apm_bat_fp);
|
||||
apm_bat_fp = NULL;
|
||||
fclose(apm_bat_fp[idx]);
|
||||
apm_bat_fp[idx] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1364,41 +1423,46 @@ set_return_value:
|
||||
switch (item) {
|
||||
case BATTERY_STATUS:
|
||||
{
|
||||
snprintf(buf, n, "%s", last_battery_str);
|
||||
snprintf(buf, n, "%s", last_battery_str[idx]);
|
||||
break;
|
||||
}
|
||||
case BATTERY_TIME:
|
||||
{
|
||||
snprintf(buf, n, "%s", last_battery_time_str);
|
||||
snprintf(buf, n, "%s", last_battery_time_str[idx]);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int get_battery_perct(const char *bat)
|
||||
{
|
||||
static int rep;
|
||||
int idx;
|
||||
char acpi_path[128];
|
||||
snprintf(acpi_path, 127, ACPI_BATTERY_BASE_PATH "/%s/state", bat);
|
||||
|
||||
init_batteries();
|
||||
|
||||
idx = get_battery_idx(bat);
|
||||
|
||||
/* don't update battery too often */
|
||||
if (current_update_time - last_battery_perct_time < 30) {
|
||||
return last_battery_perct;
|
||||
if (current_update_time - last_battery_perct_time[idx] < 30) {
|
||||
return last_battery_perct[idx];
|
||||
}
|
||||
last_battery_perct_time = current_update_time;
|
||||
last_battery_perct_time[idx] = current_update_time;
|
||||
|
||||
/* Only check for ACPI */
|
||||
|
||||
if (acpi_bat_fp == NULL && apm_bat_fp == NULL)
|
||||
acpi_bat_fp = open_file(acpi_path, &rep);
|
||||
acpi_bat_fp[idx] = open_file(acpi_path, &rep);
|
||||
|
||||
int remaining_capacity = -1;
|
||||
if (acpi_bat_fp != NULL) {
|
||||
if (acpi_bat_fp[idx] != NULL) {
|
||||
/* read last full capacity if it's zero */
|
||||
if (acpi_design_capacity == 0) {
|
||||
if (acpi_design_capacity[idx] == 0) {
|
||||
static int rep;
|
||||
char path[128];
|
||||
FILE *fp;
|
||||
@ -1410,7 +1474,7 @@ int get_battery_perct(const char *bat)
|
||||
char b[256];
|
||||
if (fgets(b, 256, fp) == NULL)
|
||||
break;
|
||||
if (sscanf(b, "design capacity: %d", &acpi_design_capacity) != 0) {
|
||||
if (sscanf(b, "design capacity: %d", &acpi_design_capacity[idx]) != 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1418,11 +1482,11 @@ int get_battery_perct(const char *bat)
|
||||
}
|
||||
}
|
||||
|
||||
fseek(acpi_bat_fp, 0, SEEK_SET);
|
||||
fseek(acpi_bat_fp[idx], 0, SEEK_SET);
|
||||
|
||||
while (!feof(acpi_bat_fp)) {
|
||||
while (!feof(acpi_bat_fp[idx])) {
|
||||
char buf[256];
|
||||
if (fgets(buf, 256, acpi_bat_fp) == NULL)
|
||||
if (fgets(buf, 256, acpi_bat_fp[idx]) == NULL)
|
||||
break;
|
||||
|
||||
if (buf[0] == 'r')
|
||||
@ -1433,15 +1497,17 @@ int get_battery_perct(const char *bat)
|
||||
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;
|
||||
last_battery_perct[idx] =
|
||||
(int) (((float)remaining_capacity/acpi_design_capacity[idx]) * 100);
|
||||
return last_battery_perct[idx];
|
||||
}
|
||||
|
||||
int get_battery_perct_bar(const char *bar)
|
||||
{
|
||||
int idx;
|
||||
get_battery_perct(bar);
|
||||
return (int) (last_battery_perct * 2.56 - 1);
|
||||
idx = get_battery_idx(bar);
|
||||
return (int) (last_battery_perct[idx] * 2.56 - 1);
|
||||
}
|
||||
|
||||
|
||||
@ -1469,7 +1535,7 @@ static FILE* pmu_battery_fp;
|
||||
static FILE* pmu_info_fp;
|
||||
static char pb_battery_info[3][32];
|
||||
static double pb_battery_info_update;
|
||||
|
||||
|
||||
#define PMU_PATH "/proc/pmu"
|
||||
void get_powerbook_batt_info(char *buf, size_t n, int i)
|
||||
{
|
||||
@ -1533,7 +1599,7 @@ void get_powerbook_batt_info(char *buf, size_t n, int i)
|
||||
|
||||
/* update percentage string */
|
||||
if (time == 0)
|
||||
pb_battery_info[PB_BATT_PERCENT][0] = 0;
|
||||
pb_battery_info[PB_BATT_PERCENT][0] = 0;
|
||||
else
|
||||
snprintf(pb_battery_info[PB_BATT_PERCENT],
|
||||
sizeof(pb_battery_info[PB_BATT_PERCENT]),
|
||||
@ -1541,7 +1607,7 @@ void get_powerbook_batt_info(char *buf, size_t n, int i)
|
||||
|
||||
/* update time string */
|
||||
if (time == 0) /* fully charged or battery not present */
|
||||
pb_battery_info[PB_BATT_TIME][0] = 0;
|
||||
pb_battery_info[PB_BATT_TIME][0] = 0;
|
||||
else if (time < 60*60) /* don't show secs */
|
||||
format_seconds_short(pb_battery_info[PB_BATT_TIME],
|
||||
sizeof(pb_battery_info[PB_BATT_TIME]), time);
|
||||
@ -1626,12 +1692,12 @@ void update_diskio()
|
||||
int tot = ((double)(current-last)/2);
|
||||
int tot_read = ((double)(current_read-last_read)/2);
|
||||
int tot_write = ((double)(current_write-last_write)/2);
|
||||
|
||||
|
||||
if (last_read > current_read)
|
||||
tot_read = 0;
|
||||
if (last_write > current_write)
|
||||
tot_write = 0;
|
||||
|
||||
tot_write = 0;
|
||||
|
||||
if (last > current) {
|
||||
/* we hit this either if it's the very first time we
|
||||
* run this, or when /proc/diskstats overflows; while
|
||||
@ -1686,11 +1752,11 @@ Peter Tarjan (ptarjan@citromail.hu)
|
||||
|
||||
if ( !p_client_buffer || client_buffer_size <= 0 )
|
||||
return;
|
||||
|
||||
|
||||
FILE *fp;
|
||||
unsigned int speed=0;
|
||||
char fan[128];
|
||||
snprintf(fan, 127, "%s/fan",IBM_ACPI_DIR);
|
||||
snprintf(fan, 127, "%s/fan",IBM_ACPI_DIR);
|
||||
|
||||
fp = fopen(fan, "r");
|
||||
if (fp != NULL)
|
||||
@ -1699,10 +1765,10 @@ Peter Tarjan (ptarjan@citromail.hu)
|
||||
{
|
||||
char line[256];
|
||||
if (fgets(line, 255, fp) == NULL) break;
|
||||
if (sscanf(line, "speed: %d", &speed)) break;
|
||||
if (sscanf(line, "speed: %d", &speed)) break;
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
CRIT_ERR("can't open '%s': %s\nYou are not using the IBM ACPI. Remove ibm* from your Conky config file.", fan, strerror(errno));
|
||||
}
|
||||
@ -1710,15 +1776,15 @@ Peter Tarjan (ptarjan@citromail.hu)
|
||||
fclose(fp);
|
||||
snprintf( p_client_buffer, client_buffer_size, "%d", speed );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static double last_ibm_acpi_temp_time;
|
||||
void get_ibm_acpi_temps()
|
||||
{
|
||||
/* get the measured temperatures from the temperature sensors
|
||||
/* get the measured temperatures from the temperature sensors
|
||||
on IBM/Lenovo laptops running the ibm acpi.
|
||||
There are 8 values in /proc/acpi/ibm/thermal, and according to
|
||||
There are 8 values in /proc/acpi/ibm/thermal, and according to
|
||||
http://ibm-acpi.sourceforge.net/README
|
||||
these mean the following (at least on an IBM R51...)
|
||||
0: CPU (also on the T series laptops)
|
||||
@ -1728,30 +1794,30 @@ void get_ibm_acpi_temps()
|
||||
4: Battery (?)
|
||||
5: N/A
|
||||
6: Battery (?)
|
||||
7: N/A
|
||||
I'm not too sure about those with the question mark, but the values I'm
|
||||
reading from *my* thermal file (on a T42p) look realistic for the
|
||||
hdd and the battery.
|
||||
#5 and #7 are always -128.
|
||||
7: N/A
|
||||
I'm not too sure about those with the question mark, but the values I'm
|
||||
reading from *my* thermal file (on a T42p) look realistic for the
|
||||
hdd and the battery.
|
||||
#5 and #7 are always -128.
|
||||
/proc/acpi/ibm/thermal looks like this (1 line):
|
||||
temperatures: 41 43 31 46 33 -128 29 -128
|
||||
Peter Tarjan (ptarjan@citromail.hu)
|
||||
*/
|
||||
|
||||
/* don't update too often */
|
||||
if (current_update_time - last_ibm_acpi_temp_time < 10.00)
|
||||
if (current_update_time - last_ibm_acpi_temp_time < 10.00)
|
||||
{
|
||||
return;
|
||||
}
|
||||
last_ibm_acpi_temp_time = current_update_time;
|
||||
|
||||
last_ibm_acpi_temp_time = current_update_time;
|
||||
|
||||
/* if ( !p_client_buffer || client_buffer_size <= 0 )
|
||||
return; */
|
||||
|
||||
FILE *fp;
|
||||
|
||||
char thermal[128];
|
||||
snprintf(thermal, 127, "%s/thermal",IBM_ACPI_DIR);
|
||||
snprintf(thermal, 127, "%s/thermal",IBM_ACPI_DIR);
|
||||
fp = fopen(thermal, "r");
|
||||
|
||||
if (fp != NULL)
|
||||
@ -1763,18 +1829,18 @@ Peter Tarjan (ptarjan@citromail.hu)
|
||||
if (sscanf(line, "temperatures: %d %d %d %d %d %d %d %d",
|
||||
&ibm_acpi.temps[0], &ibm_acpi.temps[1],
|
||||
&ibm_acpi.temps[2], &ibm_acpi.temps[3],
|
||||
&ibm_acpi.temps[4], &ibm_acpi.temps[5],
|
||||
&ibm_acpi.temps[4], &ibm_acpi.temps[5],
|
||||
&ibm_acpi.temps[6], &ibm_acpi.temps[7])) break;
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
CRIT_ERR("can't open '%s': %s\nYou are not using the IBM ACPI. Remove ibm* from your Conky config file.", thermal, strerror(errno));
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void get_ibm_acpi_volume( char * p_client_buffer, size_t client_buffer_size )
|
||||
@ -1790,14 +1856,14 @@ commands: up, down, mute
|
||||
commands: level <level> (<level> is 0-15)
|
||||
Peter Tarjan (ptarjan@citromail.hu)
|
||||
*/
|
||||
|
||||
|
||||
if ( !p_client_buffer || client_buffer_size <= 0 )
|
||||
return;
|
||||
|
||||
|
||||
FILE *fp;
|
||||
|
||||
char volume[128];
|
||||
snprintf(volume, 127, "%s/volume",IBM_ACPI_DIR);
|
||||
snprintf(volume, 127, "%s/volume",IBM_ACPI_DIR);
|
||||
unsigned int vol=-1;
|
||||
char mute[3]="";
|
||||
|
||||
@ -1812,7 +1878,7 @@ Peter Tarjan (ptarjan@citromail.hu)
|
||||
if (sscanf(line, "mute: %s", mute)) break;
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
CRIT_ERR("can't open '%s': %s\nYou are not using the IBM ACPI. Remove ibm* from your Conky config file.", volume, strerror(errno));
|
||||
}
|
||||
@ -1850,7 +1916,7 @@ Peter Tarjan (ptarjan@citromail.hu)
|
||||
FILE *fp;
|
||||
unsigned int brightness=0;
|
||||
char filename[128];
|
||||
snprintf(filename, 127, "%s/brightness",IBM_ACPI_DIR);
|
||||
snprintf(filename, 127, "%s/brightness",IBM_ACPI_DIR);
|
||||
|
||||
fp = fopen(filename, "r");
|
||||
if (fp != NULL)
|
||||
@ -1859,10 +1925,10 @@ Peter Tarjan (ptarjan@citromail.hu)
|
||||
{
|
||||
char line[256];
|
||||
if (fgets(line, 255, fp) == NULL) break;
|
||||
if (sscanf(line, "level: %d", &brightness)) break;
|
||||
if (sscanf(line, "level: %d", &brightness)) break;
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
CRIT_ERR("can't open '%s': %s\nYou are not using the IBM ACPI. Remove ibm* from your Conky config file.", filename, strerror(errno));
|
||||
}
|
||||
@ -1871,8 +1937,8 @@ Peter Tarjan (ptarjan@citromail.hu)
|
||||
|
||||
snprintf( p_client_buffer, client_buffer_size, "%d", brightness );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void update_entropy (void)
|
||||
{
|
||||
|
203
src/mpd.c
203
src/mpd.c
@ -10,6 +10,40 @@
|
||||
#include <stdlib.h>
|
||||
#include "libmpdclient.h"
|
||||
|
||||
static void clear_mpd_stats(struct information *current_info)
|
||||
{
|
||||
if (current_info->mpd.artist == NULL)
|
||||
current_info->mpd.artist = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.album == NULL)
|
||||
current_info->mpd.album = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.title == NULL)
|
||||
current_info->mpd.title = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.random == NULL)
|
||||
current_info->mpd.random = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.repeat == NULL)
|
||||
current_info->mpd.repeat = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.track == NULL)
|
||||
current_info->mpd.track = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.status == NULL)
|
||||
current_info->mpd.status = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.name == NULL)
|
||||
current_info->mpd.name = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.file == NULL)
|
||||
current_info->mpd.file = malloc(TEXT_BUFFER_SIZE);
|
||||
|
||||
*current_info->mpd.name=0;
|
||||
*current_info->mpd.file=0;
|
||||
*current_info->mpd.artist=0;
|
||||
*current_info->mpd.album=0;
|
||||
*current_info->mpd.title=0;
|
||||
*current_info->mpd.random=0;
|
||||
*current_info->mpd.repeat=0;
|
||||
*current_info->mpd.track=0;
|
||||
current_info->mpd.bitrate = 0;
|
||||
current_info->mpd.progress = 0;
|
||||
current_info->mpd.elapsed = 0;
|
||||
current_info->mpd.length = 0;
|
||||
}
|
||||
|
||||
void update_mpd()
|
||||
{
|
||||
@ -22,45 +56,16 @@ void update_mpd()
|
||||
current_info->mpd.password);
|
||||
mpd_finishCommand(current_info->conn);
|
||||
}
|
||||
|
||||
// This makes sure everything we need is malloc'ed and clear
|
||||
clear_mpd_stats(current_info);
|
||||
|
||||
if (current_info->conn->error) {
|
||||
//ERR("%MPD error: s\n", current_info->conn->errorStr);
|
||||
mpd_closeConnection(current_info->conn);
|
||||
current_info->conn = 0;
|
||||
if (current_info->mpd.artist == NULL)
|
||||
current_info->mpd.artist =
|
||||
malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.album == NULL)
|
||||
current_info->mpd.album = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.title == NULL)
|
||||
current_info->mpd.title = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.random == NULL)
|
||||
current_info->mpd.random =
|
||||
malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.repeat == NULL)
|
||||
current_info->mpd.repeat =
|
||||
malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.track == NULL)
|
||||
current_info->mpd.track = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.status == NULL)
|
||||
current_info->mpd.status =
|
||||
malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.name == NULL)
|
||||
current_info->mpd.name = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.file == NULL)
|
||||
current_info->mpd.file = malloc(TEXT_BUFFER_SIZE);
|
||||
*current_info->mpd.name=0;
|
||||
*current_info->mpd.file=0;
|
||||
*current_info->mpd.artist=0;
|
||||
*current_info->mpd.album=0;
|
||||
*current_info->mpd.title=0;
|
||||
*current_info->mpd.random=0;
|
||||
*current_info->mpd.repeat=0;
|
||||
*current_info->mpd.track=0;
|
||||
|
||||
strncpy(current_info->mpd.status, "MPD not responding", TEXT_BUFFER_SIZE - 1);
|
||||
current_info->mpd.bitrate = 0;
|
||||
current_info->mpd.progress = 0;
|
||||
current_info->mpd.elapsed = 0;
|
||||
current_info->mpd.length = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -74,134 +79,29 @@ void update_mpd()
|
||||
//ERR("MPD error: %s\n", current_info->conn->errorStr);
|
||||
mpd_closeConnection(current_info->conn);
|
||||
current_info->conn = 0;
|
||||
if (current_info->mpd.artist == NULL)
|
||||
current_info->mpd.artist =
|
||||
malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.album == NULL)
|
||||
current_info->mpd.album = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.title == NULL)
|
||||
current_info->mpd.title = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.random == NULL)
|
||||
current_info->mpd.random =
|
||||
malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.repeat == NULL)
|
||||
current_info->mpd.repeat =
|
||||
malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.track == NULL)
|
||||
current_info->mpd.track = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.status == NULL)
|
||||
current_info->mpd.status = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.name == NULL)
|
||||
current_info->mpd.name = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.file == NULL)
|
||||
current_info->mpd.file = malloc(TEXT_BUFFER_SIZE);
|
||||
*current_info->mpd.name=0;
|
||||
*current_info->mpd.file=0;
|
||||
*current_info->mpd.artist=0;
|
||||
*current_info->mpd.album=0;
|
||||
*current_info->mpd.title=0;
|
||||
*current_info->mpd.random=0;
|
||||
*current_info->mpd.repeat=0;
|
||||
*current_info->mpd.track=0;
|
||||
|
||||
strncpy(current_info->mpd.status, "MPD not responding", TEXT_BUFFER_SIZE - 1);
|
||||
current_info->mpd.bitrate = 0;
|
||||
current_info->mpd.progress = 0;
|
||||
current_info->mpd.elapsed = 0;
|
||||
current_info->mpd.length = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
current_info->mpd.volume = status->volume;
|
||||
//if (status->error)
|
||||
//printf("error: %s\n", status->error);
|
||||
|
||||
if (status->state == MPD_STATUS_STATE_PLAY) {
|
||||
if (current_info->mpd.status == NULL)
|
||||
current_info->mpd.status =
|
||||
malloc(TEXT_BUFFER_SIZE);
|
||||
strncpy(current_info->mpd.status, "Playing",
|
||||
TEXT_BUFFER_SIZE - 1);
|
||||
}
|
||||
if (status->state == MPD_STATUS_STATE_STOP) {
|
||||
current_info->mpd.bitrate = 0;
|
||||
current_info->mpd.progress = 0;
|
||||
current_info->mpd.elapsed = 0;
|
||||
current_info->mpd.length = 0;
|
||||
if (current_info->mpd.artist == NULL)
|
||||
current_info->mpd.artist =
|
||||
malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.album == NULL)
|
||||
current_info->mpd.album = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.title == NULL)
|
||||
current_info->mpd.title = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.random == NULL)
|
||||
current_info->mpd.random =
|
||||
malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.repeat == NULL)
|
||||
current_info->mpd.repeat =
|
||||
malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.track == NULL)
|
||||
current_info->mpd.track = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.status == NULL)
|
||||
current_info->mpd.status =
|
||||
malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.name == NULL)
|
||||
current_info->mpd.name = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.file == NULL)
|
||||
current_info->mpd.file = malloc(TEXT_BUFFER_SIZE);
|
||||
*current_info->mpd.name=0;
|
||||
*current_info->mpd.file=0;
|
||||
*current_info->mpd.artist=0;
|
||||
*current_info->mpd.album=0;
|
||||
*current_info->mpd.title=0;
|
||||
*current_info->mpd.random=0;
|
||||
*current_info->mpd.repeat=0;
|
||||
*current_info->mpd.track=0;
|
||||
strncpy(current_info->mpd.status, "Stopped",
|
||||
TEXT_BUFFER_SIZE - 1);
|
||||
}
|
||||
if (status->state == MPD_STATUS_STATE_PAUSE) {
|
||||
if (current_info->mpd.status == NULL)
|
||||
current_info->mpd.status =
|
||||
malloc(TEXT_BUFFER_SIZE);
|
||||
strncpy(current_info->mpd.status, "Paused",
|
||||
TEXT_BUFFER_SIZE - 1);
|
||||
}
|
||||
if (status->state == MPD_STATUS_STATE_UNKNOWN) {
|
||||
current_info->mpd.bitrate = 0;
|
||||
current_info->mpd.progress = 0;
|
||||
current_info->mpd.elapsed = 0;
|
||||
current_info->mpd.length = 0;
|
||||
if (current_info->mpd.artist == NULL)
|
||||
current_info->mpd.artist =
|
||||
malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.album == NULL)
|
||||
current_info->mpd.album = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.title == NULL)
|
||||
current_info->mpd.title = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.random == NULL)
|
||||
current_info->mpd.random =
|
||||
malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.repeat == NULL)
|
||||
current_info->mpd.repeat =
|
||||
malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.track == NULL)
|
||||
current_info->mpd.track = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.status == NULL)
|
||||
current_info->mpd.status =
|
||||
malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.name == NULL)
|
||||
current_info->mpd.name = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.file == NULL)
|
||||
current_info->mpd.file = malloc(TEXT_BUFFER_SIZE);
|
||||
*current_info->mpd.name=0;
|
||||
*current_info->mpd.file=0;
|
||||
*current_info->mpd.artist=0;
|
||||
*current_info->mpd.album=0;
|
||||
*current_info->mpd.title=0;
|
||||
*current_info->mpd.random=0;
|
||||
*current_info->mpd.repeat=0;
|
||||
*current_info->mpd.track=0;
|
||||
*current_info->mpd.status=0;
|
||||
// current_info was already cleaned up by clear_mpd_stats()
|
||||
}
|
||||
if (status->state == MPD_STATUS_STATE_PLAY ||
|
||||
status->state == MPD_STATUS_STATE_PAUSE) {
|
||||
@ -210,12 +110,6 @@ void update_mpd()
|
||||
(float) status->elapsedTime / status->totalTime;
|
||||
current_info->mpd.elapsed = status->elapsedTime;
|
||||
current_info->mpd.length = status->totalTime;
|
||||
if (current_info->mpd.random == NULL)
|
||||
current_info->mpd.random =
|
||||
malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.repeat == NULL)
|
||||
current_info->mpd.repeat =
|
||||
malloc(TEXT_BUFFER_SIZE);
|
||||
if (status->random == 0) {
|
||||
strcpy(current_info->mpd.random, "Off");
|
||||
} else if (status->random == 1) {
|
||||
@ -248,19 +142,6 @@ void update_mpd()
|
||||
continue;
|
||||
}
|
||||
|
||||
if (current_info->mpd.artist == NULL)
|
||||
current_info->mpd.artist =
|
||||
malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.album == NULL)
|
||||
current_info->mpd.album = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.title == NULL)
|
||||
current_info->mpd.title = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.track == NULL)
|
||||
current_info->mpd.track = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.name == NULL)
|
||||
current_info->mpd.name = malloc(TEXT_BUFFER_SIZE);
|
||||
if (current_info->mpd.file == NULL)
|
||||
current_info->mpd.file = malloc(TEXT_BUFFER_SIZE);
|
||||
if (song->artist) {
|
||||
strncpy(current_info->mpd.artist, song->artist,
|
||||
TEXT_BUFFER_SIZE - 1);
|
||||
|
@ -110,6 +110,11 @@ void update_uptime()
|
||||
}
|
||||
}
|
||||
|
||||
int check_mount(char *s)
|
||||
{
|
||||
/* stub */
|
||||
return 0;
|
||||
}
|
||||
|
||||
void update_meminfo()
|
||||
{
|
||||
|
@ -105,6 +105,12 @@ swapmode(int *used, int *total)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int check_mount(char *s)
|
||||
{
|
||||
/* stub */
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
update_uptime()
|
||||
{
|
||||
|
@ -50,3 +50,9 @@ void update_meminfo()
|
||||
{
|
||||
/* TODO */
|
||||
}
|
||||
|
||||
int check_mount(char *s)
|
||||
{
|
||||
/* stub */
|
||||
return 0;
|
||||
}
|
||||
|
262
src/xmms2.c
262
src/xmms2.c
@ -16,191 +16,195 @@
|
||||
|
||||
/* callbacks */
|
||||
|
||||
void connection_lost( void *ptr ) {
|
||||
((struct information *)ptr)->xmms2_conn_state = CONN_NO;
|
||||
static void xmms_alloc(struct information *ptr)
|
||||
{
|
||||
if (ptr->xmms2.status == NULL) {
|
||||
ptr->xmms2.status = malloc(TEXT_BUFFER_SIZE);
|
||||
ptr->xmms2.status[0] = '\0';
|
||||
}
|
||||
|
||||
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 (ptr->xmms2.artist == NULL) {
|
||||
ptr->xmms2.artist = malloc(TEXT_BUFFER_SIZE);
|
||||
ptr->xmms2.artist[0] = '\0';
|
||||
}
|
||||
|
||||
if (ptr->xmms2.album == NULL) {
|
||||
ptr->xmms2.album = malloc(TEXT_BUFFER_SIZE);
|
||||
ptr->xmms2.album[0] = '\0';
|
||||
}
|
||||
|
||||
if ( ((struct information *)ptr)->xmms2.artist == NULL )
|
||||
((struct information *)ptr)->xmms2.artist = malloc( TEXT_BUFFER_SIZE );
|
||||
strncpy( ((struct information *)ptr)->xmms2.artist, "", TEXT_BUFFER_SIZE - 1 );
|
||||
if (ptr->xmms2.title == NULL) {
|
||||
ptr->xmms2.title = malloc(TEXT_BUFFER_SIZE);
|
||||
ptr->xmms2.title[0] = '\0';
|
||||
}
|
||||
|
||||
if ( ((struct information *)ptr)->xmms2.album == NULL )
|
||||
((struct information *)ptr)->xmms2.album = malloc( TEXT_BUFFER_SIZE );
|
||||
strncpy( ((struct information *)ptr)->xmms2.album, "", TEXT_BUFFER_SIZE - 1 );
|
||||
if (ptr->xmms2.genre == NULL) {
|
||||
ptr->xmms2.genre = malloc(TEXT_BUFFER_SIZE);
|
||||
ptr->xmms2.genre[0] = '\0';
|
||||
}
|
||||
|
||||
if ( ((struct information *)ptr)->xmms2.title == NULL )
|
||||
((struct information *)ptr)->xmms2.title = malloc( TEXT_BUFFER_SIZE );
|
||||
strncpy( ((struct information *)ptr)->xmms2.title, "", TEXT_BUFFER_SIZE - 1 );
|
||||
if (ptr->xmms2.comment == NULL) {
|
||||
ptr->xmms2.comment = malloc(TEXT_BUFFER_SIZE);
|
||||
ptr->xmms2.comment[0] = '\0';
|
||||
}
|
||||
|
||||
if ( ((struct information *)ptr)->xmms2.genre == NULL )
|
||||
((struct information *)ptr)->xmms2.genre = malloc( TEXT_BUFFER_SIZE );
|
||||
strncpy( ((struct information *)ptr)->xmms2.genre, "", TEXT_BUFFER_SIZE - 1 );
|
||||
if (ptr->xmms2.decoder == NULL) {
|
||||
ptr->xmms2.decoder = malloc(TEXT_BUFFER_SIZE);
|
||||
ptr->xmms2.decoder[0] = '\0';
|
||||
}
|
||||
|
||||
if ( ((struct information *)ptr)->xmms2.comment == NULL )
|
||||
((struct information *)ptr)->xmms2.comment = malloc( TEXT_BUFFER_SIZE );
|
||||
strncpy( ((struct information *)ptr)->xmms2.comment, "", TEXT_BUFFER_SIZE - 1 );
|
||||
if (ptr->xmms2.transport == NULL) {
|
||||
ptr->xmms2.transport = malloc(TEXT_BUFFER_SIZE);
|
||||
ptr->xmms2.transport[0] = '\0';
|
||||
}
|
||||
|
||||
if ( ((struct information *)ptr)->xmms2.decoder == NULL )
|
||||
((struct information *)ptr)->xmms2.decoder = malloc( TEXT_BUFFER_SIZE );
|
||||
strncpy( ((struct information *)ptr)->xmms2.decoder, "", TEXT_BUFFER_SIZE - 1 );
|
||||
if (ptr->xmms2.url == NULL) {
|
||||
ptr->xmms2.url = malloc(TEXT_BUFFER_SIZE);
|
||||
ptr->xmms2.url[0] = '\0';
|
||||
}
|
||||
|
||||
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 );
|
||||
|
||||
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 );
|
||||
|
||||
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.tracknr = 0;
|
||||
((struct information *)ptr)->xmms2.id = 0;
|
||||
((struct information *)ptr)->xmms2.bitrate = 0;
|
||||
((struct information *)ptr)->xmms2.duration = 0;
|
||||
((struct information *)ptr)->xmms2.elapsed = 0;
|
||||
((struct information *)ptr)->xmms2.size = 0;
|
||||
((struct information *)ptr)->xmms2.progress = 0;
|
||||
if (ptr->xmms2.date == NULL) {
|
||||
ptr->xmms2.date = malloc(TEXT_BUFFER_SIZE);
|
||||
ptr->xmms2.date[0] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
void handle_curent_id( xmmsc_result_t *res, void *ptr ) {
|
||||
static void xmms_clear(struct information *ptr) {
|
||||
xmms_alloc(ptr);
|
||||
ptr->xmms2.status[0] = '\0';
|
||||
ptr->xmms2.artist[0] = '\0';
|
||||
ptr->xmms2.album[0] = '\0';
|
||||
ptr->xmms2.title[0] = '\0';
|
||||
ptr->xmms2.genre[0] = '\0';
|
||||
ptr->xmms2.comment[0] = '\0';
|
||||
ptr->xmms2.decoder[0] = '\0';
|
||||
ptr->xmms2.transport[0] = '\0';
|
||||
ptr->xmms2.url[0] = '\0';
|
||||
ptr->xmms2.date[0] = '\0';
|
||||
}
|
||||
|
||||
void connection_lost(void *p)
|
||||
{
|
||||
struct information *ptr = p;
|
||||
ptr->xmms2_conn_state = CONN_NO;
|
||||
|
||||
xmms_clear(ptr);
|
||||
ptr->xmms2.tracknr = 0;
|
||||
ptr->xmms2.id = 0;
|
||||
ptr->xmms2.bitrate = 0;
|
||||
ptr->xmms2.duration = 0;
|
||||
ptr->xmms2.elapsed = 0;
|
||||
ptr->xmms2.size = 0;
|
||||
ptr->xmms2.progress = 0;
|
||||
}
|
||||
|
||||
void handle_curent_id(xmmsc_result_t *res, void *p)
|
||||
{
|
||||
uint current_id;
|
||||
struct information *ptr = p;
|
||||
|
||||
if ( xmmsc_result_get_uint( res, ¤t_id ) ) {
|
||||
|
||||
xmmsc_result_t *res2;
|
||||
res2 = xmmsc_medialib_get_info( ((struct information *)ptr)->xmms2_conn, current_id );
|
||||
res2 = xmmsc_medialib_get_info(ptr->xmms2_conn, current_id);
|
||||
xmmsc_result_wait( res2 );
|
||||
|
||||
xmms_clear(ptr);
|
||||
|
||||
|
||||
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 );
|
||||
|
||||
|
||||
((struct information *)ptr)->xmms2.id = current_id;
|
||||
ptr->xmms2.id = current_id;
|
||||
|
||||
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 );
|
||||
strncpy(ptr->xmms2.artist, temp, TEXT_BUFFER_SIZE - 1);
|
||||
} else {
|
||||
strncpy( ((struct information *)ptr)->xmms2.artist, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
|
||||
strncpy(ptr->xmms2.artist, "[Unknown]", 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 );
|
||||
strncpy(ptr->xmms2.title, temp, TEXT_BUFFER_SIZE - 1);
|
||||
} else {
|
||||
strncpy( ((struct information *)ptr)->xmms2.title, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
|
||||
strncpy(ptr->xmms2.title, "[Unknown]", 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 );
|
||||
strncpy(ptr->xmms2.album, temp, TEXT_BUFFER_SIZE - 1);
|
||||
} else {
|
||||
strncpy( ((struct information *)ptr)->xmms2.album, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
|
||||
strncpy(ptr->xmms2.album, "[Unknown]", TEXT_BUFFER_SIZE - 1);
|
||||
}
|
||||
|
||||
|
||||
xmmsc_result_get_dict_entry_string( res2, "genre", &temp );
|
||||
if ( temp != NULL ) {
|
||||
|
||||
strncpy( ((struct information *)ptr)->xmms2.genre, temp, TEXT_BUFFER_SIZE - 1 );
|
||||
strncpy(ptr->xmms2.genre, temp, TEXT_BUFFER_SIZE - 1);
|
||||
} else {
|
||||
strncpy( ((struct information *)ptr)->xmms2.genre, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
|
||||
strncpy(ptr->xmms2.genre, "[Unknown]", 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 );
|
||||
strncpy(ptr->xmms2.comment, temp, TEXT_BUFFER_SIZE - 1);
|
||||
} else {
|
||||
strncpy( ((struct information *)ptr)->xmms2.comment, "", TEXT_BUFFER_SIZE - 1 );
|
||||
strncpy(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 );
|
||||
strncpy(ptr->xmms2.decoder, temp, TEXT_BUFFER_SIZE - 1);
|
||||
} else {
|
||||
strncpy( ((struct information *)ptr)->xmms2.decoder, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
|
||||
strncpy(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 );
|
||||
strncpy(ptr->xmms2.transport, temp, TEXT_BUFFER_SIZE - 1);
|
||||
} else {
|
||||
strncpy( ((struct information *)ptr)->xmms2.transport, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
|
||||
strncpy(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 );
|
||||
strncpy(ptr->xmms2.url, temp, TEXT_BUFFER_SIZE - 1);
|
||||
} else {
|
||||
strncpy( ((struct information *)ptr)->xmms2.url, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
|
||||
strncpy(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 );
|
||||
strncpy(ptr->xmms2.date, temp, TEXT_BUFFER_SIZE - 1);
|
||||
} else {
|
||||
strncpy( ((struct information *)ptr)->xmms2.date, "????", TEXT_BUFFER_SIZE - 1 );
|
||||
strncpy(ptr->xmms2.date, "????", TEXT_BUFFER_SIZE - 1);
|
||||
}
|
||||
|
||||
|
||||
int itemp;
|
||||
xmmsc_result_get_dict_entry_int( res2, "tracknr", &itemp );
|
||||
((struct information *)ptr)->xmms2.tracknr = itemp;
|
||||
ptr->xmms2.tracknr = itemp;
|
||||
|
||||
xmmsc_result_get_dict_entry_int( res2, "duration", &itemp );
|
||||
((struct information *)ptr)->xmms2.duration = itemp;
|
||||
ptr->xmms2.duration = itemp;
|
||||
|
||||
xmmsc_result_get_dict_entry_int( res2, "bitrate", &itemp );
|
||||
((struct information *)ptr)->xmms2.bitrate = itemp / 1000;
|
||||
ptr->xmms2.bitrate = itemp / 1000;
|
||||
|
||||
xmmsc_result_get_dict_entry_int( res2, "size", &itemp );
|
||||
((struct information *)ptr)->xmms2.size = (float)itemp / 1048576;
|
||||
ptr->xmms2.size = (float)itemp / 1048576;
|
||||
|
||||
xmmsc_result_unref( res2 );
|
||||
}
|
||||
}
|
||||
|
||||
void handle_playtime( xmmsc_result_t *res, void *ptr ) {
|
||||
void handle_playtime(xmmsc_result_t *res, void *p) {
|
||||
struct information *ptr = p;
|
||||
xmmsc_result_t * res2;
|
||||
uint play_time;
|
||||
|
||||
@ -213,11 +217,12 @@ void handle_playtime( xmmsc_result_t *res, void *ptr ) {
|
||||
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;
|
||||
ptr->xmms2.elapsed = play_time;
|
||||
ptr->xmms2.progress = (float) play_time / ptr->xmms2.duration;
|
||||
}
|
||||
|
||||
void handle_playback_state_change( xmmsc_result_t *res, void *ptr ) {
|
||||
void handle_playback_state_change(xmmsc_result_t *res, void *p) {
|
||||
struct information *ptr = p;
|
||||
uint pb_state = 0;
|
||||
if ( xmmsc_result_iserror( res ) )
|
||||
return;
|
||||
@ -225,25 +230,18 @@ void handle_playback_state_change( xmmsc_result_t *res, void *ptr ) {
|
||||
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 );
|
||||
|
||||
switch (pb_state) {
|
||||
case XMMS_PLAYBACK_STATUS_PLAY:
|
||||
strncpy( ((struct information *)ptr)->xmms2.status,
|
||||
"Playing", TEXT_BUFFER_SIZE - 1 );
|
||||
strncpy(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 );
|
||||
strncpy(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 );
|
||||
strncpy(ptr->xmms2.status, "Stopped", TEXT_BUFFER_SIZE - 1);
|
||||
break;
|
||||
default:
|
||||
strncpy( ((struct information *)ptr)->xmms2.status,
|
||||
"Unknown", TEXT_BUFFER_SIZE - 1 );
|
||||
strncpy(ptr->xmms2.status, "Unknown", TEXT_BUFFER_SIZE - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -269,42 +267,7 @@ void update_xmms2() {
|
||||
current_info->xmms2_conn_state = CONN_NO;
|
||||
|
||||
/* clear all values */
|
||||
if ( current_info->xmms2.artist == NULL )
|
||||
current_info->xmms2.artist = malloc( TEXT_BUFFER_SIZE );
|
||||
strncpy( current_info->xmms2.artist, "", TEXT_BUFFER_SIZE - 1 );
|
||||
|
||||
if ( current_info->xmms2.album == NULL )
|
||||
current_info->xmms2.album = malloc( TEXT_BUFFER_SIZE );
|
||||
strncpy( current_info->xmms2.album, "", TEXT_BUFFER_SIZE - 1 );
|
||||
|
||||
if ( current_info->xmms2.title == NULL )
|
||||
current_info->xmms2.title = malloc( TEXT_BUFFER_SIZE );
|
||||
strncpy( current_info->xmms2.title, "", TEXT_BUFFER_SIZE - 1 );
|
||||
|
||||
if ( current_info->xmms2.genre == NULL )
|
||||
current_info->xmms2.genre = malloc( TEXT_BUFFER_SIZE );
|
||||
strncpy( current_info->xmms2.genre, "", TEXT_BUFFER_SIZE - 1 );
|
||||
|
||||
if ( current_info->xmms2.comment == NULL )
|
||||
current_info->xmms2.comment = malloc( TEXT_BUFFER_SIZE );
|
||||
strncpy( current_info->xmms2.comment, "", TEXT_BUFFER_SIZE - 1 );
|
||||
|
||||
if ( current_info->xmms2.decoder == NULL )
|
||||
current_info->xmms2.decoder = malloc( TEXT_BUFFER_SIZE );
|
||||
strncpy( current_info->xmms2.decoder, "", TEXT_BUFFER_SIZE - 1 );
|
||||
|
||||
if ( current_info->xmms2.transport == NULL )
|
||||
current_info->xmms2.transport = malloc( TEXT_BUFFER_SIZE );
|
||||
strncpy( current_info->xmms2.transport, "", TEXT_BUFFER_SIZE - 1 );
|
||||
|
||||
if ( current_info->xmms2.url == NULL )
|
||||
current_info->xmms2.url = malloc( TEXT_BUFFER_SIZE );
|
||||
strncpy( current_info->xmms2.url, "", TEXT_BUFFER_SIZE - 1 );
|
||||
|
||||
if ( current_info->xmms2.date == NULL )
|
||||
current_info->xmms2.date = malloc( TEXT_BUFFER_SIZE );
|
||||
strncpy( current_info->xmms2.date, "", TEXT_BUFFER_SIZE - 1 );
|
||||
|
||||
xmms_clear(current_info);
|
||||
|
||||
current_info->xmms2.tracknr = 0;
|
||||
current_info->xmms2.id = 0;
|
||||
@ -342,13 +305,10 @@ void update_xmms2() {
|
||||
xmmsc_result_wait ( res );
|
||||
unsigned int pb_state;
|
||||
|
||||
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,
|
||||
strncpy(current_info->xmms2.status,
|
||||
"Playing", TEXT_BUFFER_SIZE - 1 );
|
||||
break;
|
||||
case XMMS_PLAYBACK_STATUS_PAUSE:
|
||||
|
Loading…
Reference in New Issue
Block a user