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

split battery off into battery and battery_time

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@814 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Philip Kovacs 2006-12-12 23:21:14 +00:00
parent a2429c3197
commit 5ff932ff21
14 changed files with 148 additions and 55 deletions

View File

@ -1,5 +1,10 @@
# $Id$ # $Id$
2006-12-12
* Split battery variable into two:
battery, e.g. "charging 75%" and
battery_time, e.g. "3h 15m".
2006-12-11 2006-12-11
* Close pop3/imap sockets. * Close pop3/imap sockets.
* Fix outstanding battery issues. * Fix outstanding battery issues.

10
README
View File

@ -464,8 +464,14 @@ VARIABLES
battery (num) battery (num)
Remaining capacity in ACPI or APM battery. ACPI battery number Battery status and remaining percentage capacity of ACPI or APM
can be given as argument (default is BAT0). battery. ACPI battery number can be given as argument (default
is BAT0).
battery_time (num)
Battery charge/discharge time remaining of ACPI battery. ACPI
battery number can be given as argument (default is BAT0).
bmpx_artist bmpx_artist

View File

@ -92,7 +92,7 @@ dnl OWN_WINDOW option
dnl dnl
AC_ARG_ENABLE([own_window], AC_ARG_ENABLE([own_window],
AC_HELP_STRING([--enable-own-window], [enable if you want support for creating own window [[default=yes]]]), AC_HELP_STRING([--enable-own-window], [enable if you want support for creating own window @<:@default=yes@:>@]),
[dah="$enableval"], [dah=yes]) [dah="$enableval"], [dah=yes])
if test $dah != "no"; then if test $dah != "no"; then
@ -104,7 +104,7 @@ dnl PROC_UPTIME option
dnl dnl
AC_ARG_ENABLE([proc_uptime], AC_ARG_ENABLE([proc_uptime],
AC_HELP_STRING([--enable-proc-uptime], [enable using /proc/uptime for uptime [[default=yes]]]), AC_HELP_STRING([--enable-proc-uptime], [enable using /proc/uptime for uptime @<:@default=yes@:>@]),
[dah="$enableval"], [dah=yes]) [dah="$enableval"], [dah=yes])
if test $dah = "yes"; then if test $dah = "yes"; then
@ -117,7 +117,7 @@ dnl Audacious Media Player
dnl dnl
AC_ARG_ENABLE([audacious], AC_ARG_ENABLE([audacious],
AC_HELP_STRING([--enable-audacious], [enable audacious player support [[default=no]]]), AC_HELP_STRING([--enable-audacious], [enable audacious player support @<:@default=no@:>@]),
[want_audacious="$enableval"], [want_audacious=no]) [want_audacious="$enableval"], [want_audacious=no])
AM_CONDITIONAL(BUILD_AUDACIOUS, test x$want_audacious = xyes) AM_CONDITIONAL(BUILD_AUDACIOUS, test x$want_audacious = xyes)
@ -134,7 +134,7 @@ dnl BMPx
dnl dnl
AC_ARG_ENABLE([bmpx], AC_ARG_ENABLE([bmpx],
AC_HELP_STRING([--enable-bmpx], [enable if you want BMPx support [[default=no]]]), AC_HELP_STRING([--enable-bmpx], [enable if you want BMPx support @<:@default=no@:>@]),
[want_bmpx="$enableval"], [want_bmpx=no]) [want_bmpx="$enableval"], [want_bmpx=no])
AM_CONDITIONAL(BUILD_BMPX, test x$want_bmpx = xyes) AM_CONDITIONAL(BUILD_BMPX, test x$want_bmpx = xyes)
@ -151,7 +151,7 @@ dnl Hddtemp
dnl dnl
AC_ARG_ENABLE([hddtemp], AC_ARG_ENABLE([hddtemp],
AC_HELP_STRING([--enable-hddtemp], [enable if you want hddtemp support [[default=yes]]]), AC_HELP_STRING([--enable-hddtemp], [enable if you want hddtemp support @<:@default=yes@:>@]),
[want_hddtemp="$enableval"], [want_hddtemp=yes]) [want_hddtemp="$enableval"], [want_hddtemp=yes])
AM_CONDITIONAL(BUILD_HDDTEMP, test x$want_hddtemp = xyes) AM_CONDITIONAL(BUILD_HDDTEMP, test x$want_hddtemp = xyes)
@ -164,7 +164,7 @@ dnl MPD
dnl dnl
AC_ARG_ENABLE([mpd], AC_ARG_ENABLE([mpd],
AC_HELP_STRING([--enable-mpd], [enable if you want MPD support [[default=yes]]]), AC_HELP_STRING([--enable-mpd], [enable if you want MPD support @<:@default=yes@:>@]),
[want_mpd="$enableval"], [want_mpd=yes]) [want_mpd="$enableval"], [want_mpd=yes])
AM_CONDITIONAL(BUILD_MPD, test x$want_mpd = xyes) AM_CONDITIONAL(BUILD_MPD, test x$want_mpd = xyes)
@ -177,7 +177,7 @@ dnl XMMS2
dnl dnl
AC_ARG_ENABLE([xmms2], AC_ARG_ENABLE([xmms2],
AC_HELP_STRING([--enable-xmms2], [enable if you want XMMS2 support [[default=no]]]), AC_HELP_STRING([--enable-xmms2], [enable if you want XMMS2 support @<:@default=no@:>@]),
[want_xmms2="$enableval"], [want_xmms2=no]) [want_xmms2="$enableval"], [want_xmms2=no])
AM_CONDITIONAL(BUILD_XMMS2, test x$want_xmms2 = xyes) AM_CONDITIONAL(BUILD_XMMS2, test x$want_xmms2 = xyes)
@ -211,11 +211,15 @@ dnl PORT_MONITORS
dnl dnl
AC_ARG_ENABLE([portmon], AC_ARG_ENABLE([portmon],
AC_HELP_STRING([--enable-portmon], [enable if you want tcp (ip4) port monitoring [[default=yes]]]), AC_HELP_STRING([--enable-portmon], [enable if you want tcp (ip4) port monitoring @<:@default=yes@:>@]),
[want_portmon="$enableval"], [want_portmon=yes]) [want_portmon="$enableval"], [want_portmon=yes])
AM_CONDITIONAL(BUILD_PORT_MONITORS, test x$want_portmon = xyes) AM_CONDITIONAL(BUILD_PORT_MONITORS, test x$want_portmon = xyes)
if test x$want_portmon = xyes; then if test x$want_portmon = xyes; then
if test "x$uname" != xLinux; then
AC_MSG_NOTICE([port monitors not supported on $uname... disabling])
want_portmon=no
else
AC_CHECK_HEADERS([netdb.h netinet/in.h netinet/tcp.h sys/socket.h arpa/inet.h], [], AC_CHECK_HEADERS([netdb.h netinet/in.h netinet/tcp.h sys/socket.h arpa/inet.h], [],
[PORT_MONITORS_MISSING=yes]) [PORT_MONITORS_MISSING=yes])
if test "x$PORT_MONITORS_MISSING" = xyes; then if test "x$PORT_MONITORS_MISSING" = xyes; then
@ -225,6 +229,7 @@ if test x$want_portmon = xyes; then
CFLAGS="$CFLAGS $GLIB_CFLAGS" CFLAGS="$CFLAGS $GLIB_CFLAGS"
LIBS="$LIBS $GLIB_LIBS" LIBS="$LIBS $GLIB_LIBS"
AC_DEFINE(TCP_PORT_MONITOR, 1, [Define if you want tcp port monitoring support]) AC_DEFINE(TCP_PORT_MONITOR, 1, [Define if you want tcp port monitoring support])
fi
fi fi
@ -244,7 +249,7 @@ dnl debug
dnl dnl
AC_ARG_ENABLE([debug], AC_ARG_ENABLE([debug],
AC_HELP_STRING([--enable-debug], [compile with debug symbols [[default=no]]]), AC_HELP_STRING([--enable-debug], [compile with debug symbols @<:@default=no@:>@]),
[want_debug="$enableval"], [want_debug=no]) [want_debug="$enableval"], [want_debug=no])
if test "x$want_debug" = "xyes" -a $ac_cv_c_compiler_gnu != no; then if test "x$want_debug" = "xyes" -a $ac_cv_c_compiler_gnu != no; then
@ -256,7 +261,7 @@ dnl X11
dnl dnl
AC_ARG_ENABLE([x11], AC_ARG_ENABLE([x11],
AC_HELP_STRING([--enable-x11], [enable if you want X11 support [[default=yes]]]), AC_HELP_STRING([--enable-x11], [enable if you want X11 support @<:@default=yes@:>@]),
[want_x11="$enableval"], [want_x11=yes]) [want_x11="$enableval"], [want_x11=yes])
AM_CONDITIONAL(BUILD_X11, test x$want_x11 = xyes) AM_CONDITIONAL(BUILD_X11, test x$want_x11 = xyes)
@ -286,7 +291,7 @@ dnl Xext Double-buffering Extension
dnl dnl
AC_ARG_ENABLE([double_buffer], AC_ARG_ENABLE([double_buffer],
AC_HELP_STRING([--enable-double-buffer], [enable for flicker-free operation [[default=yes]]]), AC_HELP_STRING([--enable-double-buffer], [enable for flicker-free operation @<:@default=yes@:>@]),
[want_double_buffer="$enableval"], [want_double_buffer=yes]) [want_double_buffer="$enableval"], [want_double_buffer=yes])
if test "x$want_double_buffer" = "xyes"; then if test "x$want_double_buffer" = "xyes"; then
@ -311,7 +316,7 @@ dnl Xdamage Extension
dnl dnl
AC_ARG_ENABLE([xdamage], AC_ARG_ENABLE([xdamage],
AC_HELP_STRING([--enable-xdamage], [enable if you want Xdamage support [[default=yes]]]), AC_HELP_STRING([--enable-xdamage], [enable if you want Xdamage support @<:@default=yes@:>@]),
[want_xdamage="$enableval"], [want_xdamage=yes]) [want_xdamage="$enableval"], [want_xdamage=yes])
if test "x$want_xdamage" = "xyes"; then if test "x$want_xdamage" = "xyes"; then
@ -336,7 +341,7 @@ dnl Xft
dnl dnl
AC_ARG_ENABLE([xft], AC_ARG_ENABLE([xft],
AC_HELP_STRING([--enable-xft], [enable if you want to use Xft [[default=yes]]]), AC_HELP_STRING([--enable-xft], [enable if you want to use Xft @<:@default=yes@:>@]),
[want_xft="$enableval"], [want_xft=yes]) [want_xft="$enableval"], [want_xft=yes])
if test x$want_xft = "xyes"; then if test x$want_xft = "xyes"; then

View File

@ -441,7 +441,11 @@ Title of current tune with optional maximum length specifier
.TP .TP
\fB\*(T<\fBbattery\fR\*(T>\fR \*(T<\fB(num)\fR\*(T> \fB\*(T<\fBbattery\fR\*(T>\fR \*(T<\fB(num)\fR\*(T>
Remaining capacity in ACPI or APM battery. ACPI battery number can be given as argument (default is BAT0). Battery status and remaining percentage capacity of ACPI or APM battery. ACPI battery number can be given as argument (default is BAT0).
.TP
\fB\*(T<\fBbattery_time\fR\*(T>\fR \*(T<\fB(num)\fR\*(T>
Battery charge/discharge time remaining of ACPI battery. ACPI battery number can be given as argument (default is BAT0).
.TP .TP
\fB\*(T<\fBbmpx_artist\fR\*(T>\fR \fB\*(T<\fBbmpx_artist\fR\*(T>\fR

View File

@ -236,7 +236,17 @@
<option>(num)</option> <option>(num)</option>
</term> </term>
<listitem> <listitem>
Remaining capacity in ACPI or APM battery. ACPI battery number can be given as argument (default is BAT0). Battery status and remaining percentage capacity of ACPI or APM battery. ACPI battery number can be given as argument (default is BAT0).
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>battery_time</option></command>
<option>(num)</option>
</term>
<listitem>
Battery charge/discharge time remaining of ACPI battery. ACPI battery number can be given as argument (default is BAT0).
<para></para></listitem> <para></para></listitem>
</varlistentry> </varlistentry>

View File

@ -9,7 +9,7 @@ syntax "conky" "\.*conkyrc.*$"
color green "\<(alignment|background|border_margin|border_width|cpu_avg_samples|default_color|default_shade_color|default_outline_color|double_buffer|draw_borders|draw_graph_borders|draw_shades|draw_outline|font|gap_x|gap_y|imap|mail_spool|max_port_monitor_connections|max_specials|max_user_text|maximum_width|minimum_size|mpd_host|mpd_port|mpd_password|net_avg_samples|no_buffers|out_to_console|override_utf8_locale|own_window|own_window_transparent|own_window_type|own_window_hints|own_window_colour|pad_percents|pop3|stippled_borders|total_run_times|update_interval|uppercase|use_spacer|use_xft|wm_class_name|xftalpha|xftfont)\>" color green "\<(alignment|background|border_margin|border_width|cpu_avg_samples|default_color|default_shade_color|default_outline_color|double_buffer|draw_borders|draw_graph_borders|draw_shades|draw_outline|font|gap_x|gap_y|imap|mail_spool|max_port_monitor_connections|max_specials|max_user_text|maximum_width|minimum_size|mpd_host|mpd_port|mpd_password|net_avg_samples|no_buffers|out_to_console|override_utf8_locale|own_window|own_window_transparent|own_window_type|own_window_hints|own_window_colour|pad_percents|pop3|stippled_borders|total_run_times|update_interval|uppercase|use_spacer|use_xft|wm_class_name|xftalpha|xftfont)\>"
## Variables ## Variables
color brightblue "\<(acpiacadapter|acpifan|acpitemp|acpitempf|addr|adt746xcpu|adt746xfan|align|alignr|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|color|colour|cpu|cpubar|diskio|downspeed|downspeedf|else|entropy_avail|entropy_bar|entropy_poolsize|exec|execbar|execgraph|execi|execibar|execigraph|font|freq|freq_dyn|freq_dyn_g|freq_g|fs_bar|fs_free|fs_free_perc|fs_size|fs_used|goto|hddtemp|head|hr|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_cpu_tempf|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|if_existing|if_running|if_mounted|kernel|linkstatus|loadavg|machine|mails|mem|membar|memmax|memperc|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_smart|mpd_status|mpd_title|mpd_vol|new_mails|nodename|offset|outlinecolor|pre_exec|processes|running_processes|shadecolor|stippled_hr|swap|swapbar|swapmax|swapperc|sysname|tab|tail|tcp_portmon|texeci|time|top|top_mem|totaldown|totalup|tztime|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|voffset|voltage_mv|voltage_v)\>" color brightblue "\<(acpiacadapter|acpifan|acpitemp|acpitempf|addr|adt746xcpu|adt746xfan|align|alignr|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_time|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|color|colour|cpu|cpubar|diskio|downspeed|downspeedf|else|entropy_avail|entropy_bar|entropy_poolsize|exec|execbar|execgraph|execi|execibar|execigraph|font|freq|freq_dyn|freq_dyn_g|freq_g|fs_bar|fs_free|fs_free_perc|fs_size|fs_used|goto|hddtemp|head|hr|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_cpu_tempf|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|if_existing|if_running|if_mounted|kernel|linkstatus|loadavg|machine|mails|mem|membar|memmax|memperc|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_smart|mpd_status|mpd_title|mpd_vol|new_mails|nodename|offset|outlinecolor|pre_exec|processes|running_processes|shadecolor|stippled_hr|swap|swapbar|swapmax|swapperc|sysname|tab|tail|tcp_portmon|texeci|time|top|top_mem|totaldown|totalup|tztime|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|voffset|voltage_mv|voltage_v)\>"
color brightblue "\$\{?[0-9A-Z_!@#$*?-]+\}?" color brightblue "\$\{?[0-9A-Z_!@#$*?-]+\}?"
color cyan "(\{|\}|\(|\)|\;|\]|\[|`|\\|\$|<|>|!|=|&|\|)" color cyan "(\{|\}|\(|\)|\;|\]|\[|`|\\|\$|<|>|!|=|&|\|)"
color brightred "^TEXT$" color brightred "^TEXT$"

View File

@ -118,6 +118,7 @@ syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipw
\ audacious_status \ audacious_status
\ audacious_title \ audacious_title
\ battery \ battery
\ battery_time
\ bmpx_album \ bmpx_album
\ bmpx_artist \ bmpx_artist
\ bmpx_bitrate \ bmpx_bitrate

View File

@ -886,6 +886,7 @@ enum text_object_type {
OBJ_acpitemp, OBJ_acpitemp,
OBJ_acpitempf, OBJ_acpitempf,
OBJ_battery, OBJ_battery,
OBJ_battery_time,
OBJ_buffers, OBJ_buffers,
OBJ_cached, OBJ_cached,
OBJ_color, OBJ_color,
@ -1931,7 +1932,9 @@ static void free_text_objects(unsigned int count, struct text_object *objs)
case OBJ_battery: case OBJ_battery:
free(objs[i].data.s); free(objs[i].data.s);
break; break;
case OBJ_battery_time:
free(objs[i].data.s);
break;
case OBJ_execi: case OBJ_execi:
free(objs[i].data.execi.cmd); free(objs[i].data.execi.cmd);
free(objs[i].data.execi.buffer); free(objs[i].data.execi.buffer);
@ -2082,6 +2085,13 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
else else
strcpy(bat, "BAT0"); strcpy(bat, "BAT0");
obj->data.s = strdup(bat); obj->data.s = strdup(bat);
END OBJ(battery_time, 0);
char bat[64];
if (arg)
sscanf(arg, "%63s", bat);
else
strcpy(bat, "BAT0");
obj->data.s = strdup(bat);
#if defined(__linux__) #if defined(__linux__)
END OBJ(i8k_version, INFO_I8K) END OBJ(i8k_version, INFO_I8K)
END OBJ(i8k_bios, INFO_I8K) END OBJ(i8k_bios, INFO_I8K)
@ -3277,7 +3287,10 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
get_acpi_ac_adapter(p, p_max_size); get_acpi_ac_adapter(p, p_max_size);
} }
OBJ(battery) { OBJ(battery) {
get_battery_stuff(p, p_max_size, obj->data.s); get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
}
OBJ(battery_time) {
get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
} }
OBJ(buffers) { OBJ(buffers) {
human_readable(cur->buffers * 1024, p, 255); human_readable(cur->buffers * 1024, p, 255);

View File

@ -236,6 +236,12 @@ enum {
}; };
/* get_battery_stuff() item selector */
enum {
BATTERY_STATUS,
BATTERY_TIME
};
#ifdef MPD #ifdef MPD
#include "libmpdclient.h" #include "libmpdclient.h"
#endif #endif
@ -460,7 +466,7 @@ int open_acpi_temperature(const char *name);
double get_acpi_temperature(int fd); double get_acpi_temperature(int fd);
void get_acpi_ac_adapter( char *, size_t ); void get_acpi_ac_adapter( char *, size_t );
void get_acpi_fan( char *, size_t ); void get_acpi_fan( char *, size_t );
void get_battery_stuff(char *buf, unsigned int n, const char *bat); void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item);
void get_ibm_acpi_fan(char *buf, size_t client_buffer_size); void get_ibm_acpi_fan(char *buf, size_t client_buffer_size);
void get_ibm_acpi_temps(void); void get_ibm_acpi_temps(void);
void get_ibm_acpi_volume(char *buf, size_t client_buffer_size); void get_ibm_acpi_volume(char *buf, size_t client_buffer_size);

View File

@ -352,9 +352,11 @@ get_acpi_temperature(int fd)
} }
void void
get_battery_stuff(char *buf, unsigned int n, const char *bat) get_battery_stuff(char *buf, unsigned int n, const char *bat, int item)
{ {
int battime, batcapacity, batstate, ac; int battime, batcapacity, batstate, ac;
char battery_status[64];
char battery_time[64];
if (GETSYSCTL("hw.acpi.battery.time", battime)) if (GETSYSCTL("hw.acpi.battery.time", battime))
(void) fprintf(stderr, (void) fprintf(stderr,
@ -372,23 +374,53 @@ get_battery_stuff(char *buf, unsigned int n, const char *bat)
"Cannot read sysctl \"hw.acpi.acline\"\n"); "Cannot read sysctl \"hw.acpi.acline\"\n");
if (batstate == 1) { if (batstate == 1) {
if (battime != -1) if (battime != -1) {
snprintf (battery_status, sizeof(battery_status)-1,
"remaining %d%%", batcapacity);
snprintf (battery_time, sizeof(battery_time)-1,
"%d:%2.2d", battime / 60, battime % 60);
/*
snprintf(buf, n, "remaining %d%% (%d:%2.2d)", snprintf(buf, n, "remaining %d%% (%d:%2.2d)",
batcapacity, battime / 60, battime % 60); batcapacity, battime / 60, battime % 60);
*/
}
else else
/* no time estimate available yet */ /* no time estimate available yet */
snprintf(battery_status, sizeof(battery_status)-1,
"remaining %d%%", batcapacity);
/*
snprintf(buf, n, "remaining %d%%", snprintf(buf, n, "remaining %d%%",
batcapacity); batcapacity);
*/
if (ac == 1) if (ac == 1)
(void) fprintf(stderr, "Discharging while on AC!\n"); (void) fprintf(stderr, "Discharging while on AC!\n");
} else { } else {
snprintf (battery_status, sizeof(battery_status)-1,
batstate == 2 ? "charging (%d%%)" : "charged (%d%%)", batcapacity);
/*
snprintf(buf, n, batstate == 2 ? "charging (%d%%)" : "charged (%d%%)", batcapacity); snprintf(buf, n, batstate == 2 ? "charging (%d%%)" : "charged (%d%%)", batcapacity);
*/
if (batstate != 2 && batstate != 0) if (batstate != 2 && batstate != 0)
(void) fprintf(stderr, "Unknow battery state %d!\n", batstate); (void) fprintf(stderr, "Unknown battery state %d!\n", batstate);
if (ac == 0) if (ac == 0)
(void) fprintf(stderr, "Charging while not on AC!\n"); (void) fprintf(stderr, "Charging while not on AC!\n");
} }
switch (item) {
case BATTERY_STATUS:
{
snprintf(buf, n, "%s", battery_status);
break;
}
case BATTERY_TIME:
{
snprintf(buf, n, "%s", battery_time);
break;
}
default:
break;
}
return;
} }
int int

View File

@ -383,7 +383,7 @@ int peek_tcp_port_monitor(
case REMOTEHOST: case REMOTEHOST:
p_hostent = gethostbyaddr( &p_monitor->p_peek[ connection_index ]->remote_addr, p_hostent = gethostbyaddr( (const char *)&p_monitor->p_peek[ connection_index ]->remote_addr,
sizeof(in_addr_t), AF_INET); sizeof(in_addr_t), AF_INET);
/* if no host name found, just use ip address. */ /* if no host name found, just use ip address. */
if ( !p_hostent || !p_hostent->h_name ) if ( !p_hostent || !p_hostent->h_name )
@ -419,7 +419,7 @@ int peek_tcp_port_monitor(
case LOCALHOST: case LOCALHOST:
p_hostent = gethostbyaddr( &p_monitor->p_peek[ connection_index ]->local_addr, p_hostent = gethostbyaddr( (const char *)&p_monitor->p_peek[ connection_index ]->local_addr,
sizeof(in_addr_t), AF_INET); sizeof(in_addr_t), AF_INET);
/* if no host name found, just use ip address. */ /* if no host name found, just use ip address. */
if ( !p_hostent || !p_hostent->h_name ) if ( !p_hostent || !p_hostent->h_name )

View File

@ -23,6 +23,7 @@
#ifndef LIBTCP_PORTMON_H #ifndef LIBTCP_PORTMON_H
#define LIBTCP_PORTMON_H #define LIBTCP_PORTMON_H
#include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <arpa/inet.h> #include <arpa/inet.h>

View File

@ -1192,24 +1192,26 @@ static FILE *apm_bat_fp;
static int acpi_last_full; static int acpi_last_full;
static char last_battery_str[64]; 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 double last_battery_time;
void get_battery_stuff(char *buf, unsigned int n, const char *bat) void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item)
{ {
static int rep, rep2; static int rep, rep2;
char acpi_path[128]; char acpi_path[128];
char tmp_battery[64], tmp_time_left[64];
snprintf(acpi_path, 127, ACPI_BATTERY_BASE_PATH "/%s/state", bat); snprintf(acpi_path, 127, ACPI_BATTERY_BASE_PATH "/%s/state", bat);
/* don't update battery too often */ /* don't update battery too often */
if (current_update_time - last_battery_time < 29.5) { if (current_update_time - last_battery_time < 29.5)
snprintf(buf, n, "%s", last_battery_str); goto set_return_value;
return;
}
last_battery_time = current_update_time; last_battery_time = current_update_time;
memset (last_battery_str, 0, sizeof (last_battery_str));
memset (last_battery_time_str, 0, sizeof (last_battery_time_str));
/* first try ACPI */ /* first try ACPI */
if (acpi_bat_fp == NULL && apm_bat_fp == NULL) if (acpi_bat_fp == NULL && apm_bat_fp == NULL)
@ -1275,16 +1277,12 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat)
else if (strcmp(charging_state, "charging") == 0) { else if (strcmp(charging_state, "charging") == 0) {
if (acpi_last_full != 0 && present_rate > 0) { if (acpi_last_full != 0 && present_rate > 0) {
/* e.g. charging 75% */ /* e.g. charging 75% */
snprintf(tmp_battery, sizeof(tmp_battery)-1, "charging %i%%", snprintf(last_battery_str, sizeof(last_battery_str)-1, "charging %i%%",
(int) ((remaining_capacity * 100) / acpi_last_full)); (int) ((remaining_capacity * 100) / acpi_last_full));
/* e.g. 2h 37m */ /* e.g. 2h 37m */
format_seconds(tmp_time_left, sizeof(tmp_time_left)-1, format_seconds(last_battery_time_str, sizeof(last_battery_time_str)-1,
(long) (((acpi_last_full - remaining_capacity) * 3600) / (long) (((acpi_last_full - remaining_capacity) * 3600) /
present_rate)); present_rate));
/* e.g. charging 75% (2h 37m) */
snprintf (last_battery_str, sizeof(last_battery_str)-1,
"%s (%s)", tmp_battery, tmp_time_left);
} else if (acpi_last_full != 0 && present_rate <= 0) { } else if (acpi_last_full != 0 && present_rate <= 0) {
snprintf(last_battery_str, sizeof(last_battery_str)-1, "charging %d%%", snprintf(last_battery_str, sizeof(last_battery_str)-1, "charging %d%%",
(int) ((remaining_capacity * 100) / acpi_last_full)); (int) ((remaining_capacity * 100) / acpi_last_full));
@ -1296,14 +1294,11 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat)
else if (strncmp(charging_state, "discharging", 64) == 0) { else if (strncmp(charging_state, "discharging", 64) == 0) {
if (present_rate > 0) { if (present_rate > 0) {
/* e.g. discharging 35% */ /* e.g. discharging 35% */
snprintf(tmp_battery, sizeof(tmp_battery)-1, "discharging %i%%", snprintf(last_battery_str, sizeof(last_battery_str)-1, "discharging %i%%",
(int) ((remaining_capacity * 100) / acpi_last_full)); (int) ((remaining_capacity * 100) / acpi_last_full));
/* e.g. 1h 12m */ /* e.g. 1h 12m */
format_seconds(tmp_time_left, sizeof(tmp_time_left)-1, format_seconds(last_battery_time_str, sizeof(last_battery_time_str)-1,
(long) ((remaining_capacity * 3600) / present_rate)); (long) ((remaining_capacity * 3600) / present_rate));
/* e.g. discharging 35% (1h 12m) */
snprintf (last_battery_str, sizeof(last_battery_str)-1,
"%s (%s)", tmp_battery, tmp_time_left);
} else if (present_rate == 0) { /* Thanks to Nexox for this one */ } 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, sizeof(last_battery_str)-1, "full");
} else { } else {
@ -1356,7 +1351,22 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat)
} }
} }
set_return_value:
switch (item) {
case BATTERY_STATUS:
{
snprintf(buf, n, "%s", last_battery_str); snprintf(buf, n, "%s", last_battery_str);
break;
}
case BATTERY_TIME:
{
snprintf(buf, n, "%s", last_battery_time_str);
break;
}
default:
break;
}
return;
} }
/* On Apple powerbook and ibook: /* On Apple powerbook and ibook:

View File

@ -328,7 +328,7 @@ double get_acpi_temperature(int fd)
return -1; return -1;
} }
void get_battery_stuff(char *buf, unsigned int n, const char *bat) void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item)
{ {
} }