aboutsummaryrefslogtreecommitdiffstats
path: root/x11
diff options
context:
space:
mode:
authorkmoore <kmoore@FreeBSD.org>2011-09-17 00:25:30 +0800
committerkmoore <kmoore@FreeBSD.org>2011-09-17 00:25:30 +0800
commit50f2a268e44aeb7c0d07458dcf8b96e3300ad834 (patch)
treef2c65a56b9cf9032fccb0dd680f5ed4bb6d834c6 /x11
parent33b7bf8c275df432e7838e965c2c12700f7995ae (diff)
downloadfreebsd-ports-gnome-50f2a268e44aeb7c0d07458dcf8b96e3300ad834.tar.gz
freebsd-ports-gnome-50f2a268e44aeb7c0d07458dcf8b96e3300ad834.tar.zst
freebsd-ports-gnome-50f2a268e44aeb7c0d07458dcf8b96e3300ad834.zip
- Add patches to fix the battery monitor
- Bump PORTREV
Diffstat (limited to 'x11')
-rw-r--r--x11/lxpanel/Makefile3
-rw-r--r--x11/lxpanel/files/patch-src__plugins__batt__batt.c101
-rw-r--r--x11/lxpanel/files/patch-src__plugins__batt__batt_sys.c271
-rw-r--r--x11/lxpanel/files/patch-src__plugins__batt__batt_sys.h26
-rw-r--r--x11/lxpanel/pkg-plist1
5 files changed, 401 insertions, 1 deletions
diff --git a/x11/lxpanel/Makefile b/x11/lxpanel/Makefile
index b9ef093fbdd0..ee4538c267ce 100644
--- a/x11/lxpanel/Makefile
+++ b/x11/lxpanel/Makefile
@@ -7,6 +7,7 @@
PORTNAME= lxpanel
PORTVERSION= 0.5.8
+PORTREVISION= 1
CATEGORIES= x11
MASTER_SITES= SF/lxde/LXPanel%20%28desktop%20panel%29/LXPanel%20${PORTVERSION}
@@ -24,7 +25,7 @@ USE_GNOME= gnomehack gtk20 pkgconfig
GNU_CONFIGURE= yes
USE_AUTOTOOLS= automake:env
CONFIGURE_ARGS= --prefix=${PREFIX} \
- --with-plugins=volume,deskno,kbled,xkb\
+ --with-plugins=volume,deskno,kbled,xkb,batt\
CPPFLAGS="-I${LOCALBASE}/include" \
LDFLAGS="-L${LOCALBASE}/lib"
CFLAGS+= -I${WRKSRC}
diff --git a/x11/lxpanel/files/patch-src__plugins__batt__batt.c b/x11/lxpanel/files/patch-src__plugins__batt__batt.c
new file mode 100644
index 000000000000..c8b41e632e70
--- /dev/null
+++ b/x11/lxpanel/files/patch-src__plugins__batt__batt.c
@@ -0,0 +1,101 @@
+--- src/plugins/batt/batt.c.o 2011-09-16 11:13:43.000000000 -0400
++++ src/plugins/batt/batt.c 2011-09-16 11:36:21.000000000 -0400
+@@ -71,7 +71,7 @@
+ GdkPixmap *pixmap;
+ GtkWidget *drawingArea;
+ int orientation;
+- unsigned int alarmTime,
++ unsigned int alarmPercentage,
+ border,
+ height,
+ length,
+@@ -120,15 +120,15 @@
+ char tooltip[ 256 ];
+ battery *b = lx_b->b;
+ /* unit: mW */
+- int rate = lx_b->b->present_rate;
+
+ if (! lx_b->pixmap )
+ return;
+
+ /* no battery is found */
+- if( b == NULL )
++ if( b == NULL || b->percentage < 0 )
+ {
+ gtk_widget_set_tooltip_text( lx_b->drawingArea, _("No batteries found") );
++ gdk_draw_rectangle(lx_b->pixmap, lx_b->bg, TRUE, 0, 0, lx_b->width, lx_b->height);
+ return;
+ }
+
+@@ -145,8 +145,8 @@
+ isCharging = battery_is_charging ( b );
+
+ /* Consider running the alarm command */
+- if (! isCharging && rate &&
+- ( ( battery_get_remaining( b ) / 60 ) < lx_b->alarmTime ) )
++ if (! isCharging &&
++ ( ( b->percentage ) < lx_b->alarmPercentage ) )
+ {
+ /* Shrug this should be done using glibs process functions */
+ /* Alarms should not run concurrently; determine whether an alarm is
+@@ -176,7 +176,7 @@
+ int left_seconds = b->seconds -= 3600 * hours;
+ int minutes = left_seconds / 60;
+ snprintf(tooltip, 256,
+- _("Battery: %d%% charged, %d:%02d until full"),
++ _("Battery: %d%% charged"),
+ lx_b->b->percentage,
+ hours,
+ minutes );
+@@ -187,10 +187,10 @@
+ int left_seconds = b->seconds -= 3600 * hours;
+ int minutes = left_seconds / 60;
+ snprintf(tooltip, 256,
+- _("Battery: %d%% charged, %d:%02d left"),
++ _("Battery: %d%% charged, %d:%02dh left"),
+ lx_b->b->percentage,
+- hours,
+- minutes );
++ lx_b->b->minutes / 60,
++ lx_b->b->minutes % 60 );
+ } else {
+ snprintf(tooltip, 256,
+ _("Battery: %d%% charged"),
+@@ -374,7 +374,7 @@
+ = lx_b->dischargingColor1 = lx_b->dischargingColor2 = NULL;
+
+ /* Set default values for integers */
+- lx_b->alarmTime = 5;
++ lx_b->alarmPercentage = 10;
+ lx_b->requestedBorder = 1;
+
+ line s;
+@@ -403,8 +403,8 @@
+ lx_b->dischargingColor1 = g_strdup(s.t[1]);
+ else if (!g_ascii_strcasecmp(s.t[0], "DischargingColor2"))
+ lx_b->dischargingColor2 = g_strdup(s.t[1]);
+- else if (!g_ascii_strcasecmp(s.t[0], "AlarmTime"))
+- lx_b->alarmTime = atoi(s.t[1]);
++ else if (!g_ascii_strcasecmp(s.t[0], "AlarmPercentage"))
++ lx_b->alarmPercentage = atoi(s.t[1]);
+ else if (!g_ascii_strcasecmp(s.t[0], "BorderWidth"))
+ lx_b->requestedBorder = atoi(s.t[1]);
+ else if (!g_ascii_strcasecmp(s.t[0], "Size")) {
+@@ -580,7 +580,7 @@
+ _("Hide if there is no battery"), &b->hide_if_no_battery, CONF_TYPE_BOOL,
+ #endif
+ _("Alarm command"), &b->alarmCommand, CONF_TYPE_STR,
+- _("Alarm time (minutes left)"), &b->alarmTime, CONF_TYPE_INT,
++ _("Alarm percentage (percentage left)"), &b->alarmPercentage, CONF_TYPE_INT,
+ _("Background color"), &b->backgroundColor, CONF_TYPE_STR,
+ _("Charging color 1"), &b->chargingColor1, CONF_TYPE_STR,
+ _("Charging color 2"), &b->chargingColor2, CONF_TYPE_STR,
+@@ -600,7 +600,7 @@
+
+ lxpanel_put_bool(fp, "HideIfNoBattery",lx_b->hide_if_no_battery);
+ lxpanel_put_str(fp, "AlarmCommand", lx_b->alarmCommand);
+- lxpanel_put_int(fp, "AlarmTime", lx_b->alarmTime);
++ lxpanel_put_int(fp, "AlarmPercentage", lx_b->alarmPercentage);
+ lxpanel_put_str(fp, "BackgroundColor", lx_b->backgroundColor);
+ lxpanel_put_int(fp, "BorderWidth", lx_b->requestedBorder);
+ lxpanel_put_str(fp, "ChargingColor1", lx_b->chargingColor1);
diff --git a/x11/lxpanel/files/patch-src__plugins__batt__batt_sys.c b/x11/lxpanel/files/patch-src__plugins__batt__batt_sys.c
new file mode 100644
index 000000000000..4ed46c325bba
--- /dev/null
+++ b/x11/lxpanel/files/patch-src__plugins__batt__batt_sys.c
@@ -0,0 +1,271 @@
+--- src/plugins/batt/batt_sys.c.o 2011-09-16 11:13:37.000000000 -0400
++++ src/plugins/batt/batt_sys.c 2011-09-16 11:40:08.000000000 -0400
+@@ -46,15 +46,6 @@
+
+ void battery_reset( battery * b) {
+ b->type_battery = TRUE;
+- b->capacity_unit = "mAh";
+- b->last_capacity_unit = -1;
+- b->last_capacity = -1;
+- b->voltage = -1;
+- b->design_capacity_unit = -1;
+- b->design_capacity = -1;
+- b->remaining_energy = -1;
+- b->remaining_capacity = -1;
+- b->present_rate = -1;
+ b->state = NULL;
+ }
+
+@@ -79,7 +70,7 @@
+ return n;
+ }
+
+-void battery_print(battery *b, int show_capacity)
++void battery_print(battery *b)
+ {
+ if ( b->type_battery )
+ {
+@@ -93,195 +84,65 @@
+ b->seconds -= 3600 * b->hours;
+ b->minutes = b->seconds / 60;
+ b->seconds -= 60 * b->minutes;
+- printf(", %02d:%02d:%02d%s", b->hours, b->minutes, b->seconds, b->poststr);
++ printf(", %02d:%02d:%02d", b->hours, b->minutes, b->seconds);
+ } else if (b->poststr != NULL) {
+ printf(", %s", b->poststr);
+ }
+
+-
+ printf("\n");
+
+- if (show_capacity && b->design_capacity > 0) {
+- if (b->last_capacity <= 100) {
+- /* some broken systems just give a percentage here */
+- b->percentage = b->last_capacity;
+- b->last_capacity = b->percentage * b->design_capacity / 100;
+- } else {
+- b->percentage = b->last_capacity * 100 / b->design_capacity;
+- }
+- if (b->percentage > 100)
+- b->percentage = 100;
+-
+- printf ("%s %d: design capacity %d %s, last full capacity %d %s = %d%%\n",
+- BATTERY_DESC, b->battery_num - 1, b->design_capacity, b->capacity_unit, b->last_capacity, b->capacity_unit, b->percentage);
+- }
+ }
+ }
+ }
+
+
+ void battery_update( battery *b ) {
+- int i = 0;
+- const gchar *sys_list[] = {
+- "current_now",
+- "charge_now",
+- "energy_now",
+- "voltage_now",
+- "voltage_min_design",
+- "charge_full",
+- "energy_full",
+- "charge_full_design",
+- "energy_full_design",
+- "online",
+- "status",
+- "type",
+- NULL
+- };
+- const gchar *sys_file;
++
++ char sstmp[ 100 ];
++ int c, state;
++ size_t intlen = sizeof c;
++
++ snprintf(sstmp, sizeof(sstmp), "hw.acpi.battery.life");
++ sysctlbyname(sstmp, &c, &intlen, NULL, 0);
++ b->percentage = c;
+
+ battery_reset(b);
+
+- while ( (sys_file = sys_list[i]) != NULL ) {
+-
+- gchar *file_content;
+- GString *filename = g_string_new( ACPI_PATH_SYS_POWER_SUPPY );
+- g_string_append_printf ( filename, "/%s/%s", b->path,
+- sys_file );
+- if ((file_content = parse_info_file(filename->str)) != NULL) {
+-
+- if ( strcmp("charge_now", sys_file ) == 0 ) {
+- b->remaining_capacity = get_unit_value((gchar*) file_content) / 1000;
+- if (!b->state)
+- b->state = "available";
+- }
+- else if ( strcmp("energy_now", sys_file ) == 0 ) {
+- b->remaining_energy = get_unit_value((gchar*) file_content) / 1000;
+- if (!b->state)
+- b->state = "available";
+- }
+- else if ( strcmp("current_now", sys_file ) == 0 ) {
+- b->present_rate = get_unit_value((gchar*) file_content) / 1000;
+- }
+- else if ( strcmp("charge_full", sys_file ) == 0 ) {
+- b->last_capacity = get_unit_value((gchar*) file_content) / 1000;
+- if (!b->state)
+- b->state = ("available");
+- }
+- else if ( strcmp("energy_full", sys_file ) == 0 ) {
+- b->last_capacity_unit = get_unit_value((gchar*) file_content) / 1000;
+- if (!b->state)
+- b->state = ("available");
+- }
+- else if ( strcmp("charge_full_design", sys_file ) == 0 ) {
+- b->design_capacity = get_unit_value((gchar*) file_content) / 1000;
+- }
+- else if ( strcmp("energy_full_design", sys_file ) == 0 ) {
+- b->design_capacity_unit = get_unit_value((gchar*) file_content) / 1000;
+- }
+- else if ( strcmp("type", sys_file ) == 0 ) {
+- b->type_battery = (strcasecmp(file_content, "battery") == 0 );
+- }
+- else if ( ( strcmp("status", sys_file ) == 0 ) || strcmp("state", sys_file ) == 0 )
+- b->state = file_content;
+- else if ( strcmp("voltage_now", sys_file ) == 0 ) {
+- b->voltage = get_unit_value((gchar*) file_content) / 1000;
+- }
+-
+- g_string_free( filename, TRUE );
+- }
+- i++;
+- }
+-
+- /* convert energy values (in mWh) to charge values (in mAh) if needed and possible */
+- if (b->last_capacity_unit != -1 && b->last_capacity == -1) {
+- if (b->voltage != -1) {
+- b->last_capacity = b->last_capacity_unit * 1000 / b->voltage;
+- } else {
+- b->last_capacity = b->last_capacity_unit;
+- b->capacity_unit = "mWh";
+- }
+- }
+- if (b->design_capacity_unit != -1 && b->design_capacity == -1) {
+- if (b->voltage != -1) {
+- b->design_capacity = b->design_capacity_unit * 1000 / b->voltage;
+- } else {
+- b->design_capacity = b->design_capacity_unit;
+- b->capacity_unit = "mWh";
+- }
+- }
+- if (b->remaining_energy != -1 && b->remaining_capacity == -1) {
+- if (b->voltage != -1) {
+- b->remaining_capacity = b->remaining_energy * 1000 / b->voltage;
+- b->present_rate = b->present_rate * 1000 / b->voltage;
+- } else {
+- b->remaining_capacity = b->remaining_energy;
+- }
+- }
+- if (b->last_capacity < MIN_CAPACITY)
+- b->percentage = 0;
+- else
+- b->percentage = ((float) b->remaining_energy * 100.0) / (float) b->last_capacity_unit;
+-
+- if (b->percentage > 100)
+- b->percentage = 100;
++ snprintf(sstmp, sizeof(sstmp), "hw.acpi.battery.state");
++ sysctlbyname(sstmp, &state, &intlen, NULL, 0);
+
++ switch(state) {
++ case BATT_FULL:
++ b->state = "Full";
++ break;
++ case BATT_DISCHARGING:
++ b->state = "Discharging";
++ break;
++ case BATT_CHARGING:
++ b->state = "Charging";
++ break;
++ case BATT_CRITICAL:
++ b->state = "Critical";
++ break;
++ case BATT_NONE:
++ b->state = "Unavailable";
++ break;
++ default:
++ b->state = "Unknown";
++ break;
+
+-
+- if (b->present_rate == -1) {
+- b->poststr = "rate information unavailable";
+- b->seconds = -1;
+- } else if (!strcasecmp(b->state, "charging")) {
+- if (b->present_rate > MIN_PRESENT_RATE) {
+- b->seconds = 3600 * (b->last_capacity - b->remaining_capacity) / b->present_rate;
+- b->poststr = " until charged";
+- } else {
+- b->poststr = "charging at zero rate - will never fully charge.";
+- b->seconds = -1;
+- }
+- } else if (!strcasecmp(b->state, "discharging")) {
+- if (b->present_rate > MIN_PRESENT_RATE) {
+- b->seconds = 3600 * b->remaining_capacity / b->present_rate;
+- b->poststr = " remaining";
+- } else {
+- b->poststr = "discharging at zero rate - will never fully discharge.";
+- b->seconds = -1;
+- }
+- } else {
+- b->poststr = NULL;
+- b->seconds = -1;
+ }
+-
+-}
+
+-static battery* acpi_sys_get_battery_from_dir (const gchar *device_name ) {
+- battery *b = battery_new();
+- b->path = g_strdup( device_name );
+- return b;
++ snprintf(sstmp, sizeof(sstmp), "hw.acpi.battery.time");
++ sysctlbyname(sstmp, &c, &intlen, NULL, 0);
++ b->minutes = c;
++ b->seconds = c * 60;
++
+ }
+
+ battery *battery_get() {
+- GError * error = NULL;
+- const gchar *entry;
+- GDir * dir = g_dir_open( ACPI_PATH_SYS_POWER_SUPPY, 0, &error );
+- battery *b = NULL;
+- if ( dir == NULL )
+- {
+- g_warning( "NO ACPI/sysfs support in kernel: %s", error->message );
+- return NULL;
+- }
+- while ( ( entry = g_dir_read_name (dir) ) != NULL )
+- {
+- b = acpi_sys_get_battery_from_dir(entry);
+- battery_update ( b );
+- if ( b->type_battery == TRUE )
+- break;
+- /* ignore non-batteries */
+- else {
+- g_free(b);
+- b = NULL;
+- }
+- }
+- g_dir_close( dir );
++ battery *b = battery_new();
++ battery_update(b);
+ return b;
+ }
+
+@@ -291,10 +152,3 @@
+ strcasecmp( b->state, "Full" ) == 0
+ || strcasecmp( b->state, "Charging" ) == 0 );
+ }
+-
+-gint battery_get_remaining( battery *b )
+-{
+- return b->seconds;
+-}
+-
+-
diff --git a/x11/lxpanel/files/patch-src__plugins__batt__batt_sys.h b/x11/lxpanel/files/patch-src__plugins__batt__batt_sys.h
new file mode 100644
index 000000000000..91e55dfbd18e
--- /dev/null
+++ b/x11/lxpanel/files/patch-src__plugins__batt__batt_sys.h
@@ -0,0 +1,26 @@
+--- src/plugins/batt/batt_sys.h.o 2011-09-16 11:12:42.000000000 -0400
++++ src/plugins/batt/batt_sys.h 2011-09-16 11:39:12.000000000 -0400
+@@ -23,6 +23,12 @@
+ #ifndef BATT_SYS_H
+ #define BATT_SYS_H
+
++/* The states a battery can have */
++#define BATT_FULL 0
++#define BATT_DISCHARGING 1
++#define BATT_CHARGING 2
++#define BATT_CRITICAL 5
++#define BATT_NONE 7
+
+ #define BUF_SIZE 1024
+ #define ACPI_PATH_SYS_POWER_SUPPY "/sys/class/power_supply"
+@@ -53,8 +59,8 @@
+
+ battery *battery_get();
+ void battery_update( battery *b );
+-void battery_print(battery *b, int show_capacity);
++void battery_print(battery *b);
++void battery_reset(battery *b);
+ gboolean battery_is_charging( battery *b );
+-gint battery_get_remaining( battery *b );
+
+ #endif
diff --git a/x11/lxpanel/pkg-plist b/x11/lxpanel/pkg-plist
index 397af789ba59..551ae2247ca8 100644
--- a/x11/lxpanel/pkg-plist
+++ b/x11/lxpanel/pkg-plist
@@ -1,5 +1,6 @@
bin/lxpanel
bin/lxpanelctl
+lib/lxpanel/plugins/batt.so
lib/lxpanel/plugins/deskno.so
lib/lxpanel/plugins/kbled.so
lib/lxpanel/plugins/volume.so