From 1dc945c6869c36d9f967d67ad7cad81c5a8f214d Mon Sep 17 00:00:00 2001 From: Grazvydas Ignotas Date: Sat, 14 May 2016 17:02:07 +0300 Subject: [PATCH] xfce4-battery-plugin: tune the pandora hack - avoid reading the battery when not needed - report time_to_full_now when charging --- ...e4-battery-plugin-0.5.1-pandora-hack.patch | 118 ++++++++++++------ .../xfce-extras/xfce4-battery-plugin_0.5.1.bb | 2 +- 2 files changed, 84 insertions(+), 36 deletions(-) diff --git a/recipes/xfce-extras/xfce4-battery-plugin/xfce4-battery-plugin-0.5.1-pandora-hack.patch b/recipes/xfce-extras/xfce4-battery-plugin/xfce4-battery-plugin-0.5.1-pandora-hack.patch index 5fc7ff0157..0164bf4806 100644 --- a/recipes/xfce-extras/xfce4-battery-plugin/xfce4-battery-plugin-0.5.1-pandora-hack.patch +++ b/recipes/xfce-extras/xfce4-battery-plugin/xfce4-battery-plugin-0.5.1-pandora-hack.patch @@ -1,6 +1,6 @@ -diff -ur xfce4-battery-plugin-0.5.1_orig/panel-plugin/battery.c xfce4-battery-plugin-0.5.1/panel-plugin/battery.c ---- xfce4-battery-plugin-0.5.1_orig/panel-plugin/battery.c 2008-09-04 23:53:40.000000000 +0300 -+++ xfce4-battery-plugin-0.5.1/panel-plugin/battery.c 2010-03-01 15:59:38.620912872 +0200 +diff -ur xfce4-battery-plugin-0.5.1_/panel-plugin/battery.c xfce4-battery-plugin-0.5.1/panel-plugin/battery.c +--- xfce4-battery-plugin-0.5.1_/panel-plugin/battery.c 2016-05-14 03:22:01.216877780 +0300 ++++ xfce4-battery-plugin-0.5.1/panel-plugin/battery.c 2016-05-14 15:56:18.937740189 +0300 @@ -269,6 +269,7 @@ return labels_size <= plugin_size; } @@ -16,7 +16,7 @@ diff -ur xfce4-battery-plugin-0.5.1_orig/panel-plugin/battery.c xfce4-battery-pl +#endif + +static gboolean -+battmon_update_graph(t_battmon *battmon, int charge, int time_remaining, int acline, const char *temp) ++battmon_update_status(t_battmon *battmon, int charge, int time_remaining, int acline, const char *temp) +{ + gchar buffer[128]; + gboolean fan = FALSE; @@ -25,7 +25,17 @@ diff -ur xfce4-battery-plugin-0.5.1_orig/panel-plugin/battery.c xfce4-battery-pl gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(battmon->battstatus), charge / 100.0); if(battmon->options.display_label){ -@@ -515,7 +525,7 @@ +@@ -481,7 +491,8 @@ + } + + gtk_widget_show((GtkWidget *)active_label); +- g_snprintf(buffer, sizeof(buffer),"%02d:%02d ",time_remaining/60,time_remaining%60); ++ g_snprintf(buffer, sizeof(buffer), "%s%02d:%02d ", ++ acline ? "-" : "", time_remaining / 60, time_remaining % 60); + gtk_label_set_text(active_label,buffer); + + } else { +@@ -515,7 +526,7 @@ gtk_widget_show((GtkWidget *)battmon->acfan); gtk_widget_show((GtkWidget *)battmon->temp); @@ -34,60 +44,98 @@ diff -ur xfce4-battery-plugin-0.5.1_orig/panel-plugin/battery.c xfce4-battery-pl if(acline && fan) gtk_label_set_text(battmon->acfan,"AC FAN"); else if(acline && !fan) -@@ -527,7 +537,7 @@ +@@ -527,9 +538,9 @@ gtk_widget_hide((GtkWidget *)battmon->acfan); } - temp=get_temperature(); + //temp=get_temperature(); DBG ("Temp: %s", temp); - if(temp) +- if(temp) ++ if(temp && temp[0]) gtk_label_set_text(battmon->temp,temp); -@@ -600,6 +610,49 @@ + else { + gtk_label_set_text(battmon->temp,""); +@@ -600,6 +611,84 @@ return TRUE; } ++static gboolean ++battmon_should_update(void) ++{ ++ static gboolean was_active; ++ static int counter; ++ gboolean active; ++ gboolean ret; ++ char buf[10]; ++ FILE *f; ++ ++ // update every 15 minutes anyway ++ if (counter++ == 0) ++ return TRUE; ++ if (counter == 15) ++ counter = 0; ++ ++ // is the display off? ++ f = fopen("/sys/devices/platform/omapdss_dispc/power/runtime_status", "r"); ++ if (f == NULL) ++ return TRUE; ++ buf[0] = 0; ++ fread(buf, 1, 9, f); ++ fclose(f); ++ ++ ret = active = (strncmp(buf, "suspended", 9) != 0); ++ ret |= was_active; // additional read to get values of idle system ++ was_active = active; ++ return ret; ++} ++ +#define SYS_DIR "/sys/class/power_supply/bq27500-0/" + +static gboolean +update_apm_status(t_battmon *battmon) +{ -+ FILE *f; -+ int charge = 0; -+ int time_remaining = 0; -+ int acline = 0; ++ static int charge; ++ static int time_remaining; ++ static int acline; ++ static char temp_s[16]; ++ char buf[16] = ""; + int temp = 0; -+ char temp_s[16]; ++ FILE *f; + + -+ f = fopen(SYS_DIR "capacity", "r"); -+ if (f) { -+ fscanf(f, "%d", &charge); -+ fclose(f); -+ } ++ if (battmon_should_update()) { ++ f = fopen(SYS_DIR "capacity", "r"); ++ if (f) { ++ fscanf(f, "%d", &charge); ++ fclose(f); ++ } + -+ f = fopen(SYS_DIR "time_to_empty_now", "r"); -+ if (f) { -+ fscanf(f, "%d", &time_remaining); -+ fclose(f); -+ } ++ f = fopen(SYS_DIR "status", "r"); ++ if (f) { ++ fscanf(f, "%8s", buf); ++ fclose(f); ++ acline = strncmp(buf, "Charging", 8) == 0; ++ } + -+ f = fopen(SYS_DIR "current_now", "r"); -+ if (f) { -+ fscanf(f, "%d", &acline); -+ fclose(f); -+ acline = acline < -14000 ? 0 : 1; -+ } ++ f = fopen(acline ? SYS_DIR "time_to_full_now" : SYS_DIR "time_to_empty_now", "r"); ++ if (f) { ++ fscanf(f, "%d", &time_remaining); ++ fclose(f); ++ } + -+ f = fopen(SYS_DIR "temp", "r"); -+ if (f) { -+ fscanf(f, "%d", &temp); -+ fclose(f); -+ snprintf(temp_s, sizeof(temp_s), "%d.%d°C", temp / 10, temp % 10); ++ if (battmon->options.display_power) { ++ f = fopen(SYS_DIR "temp", "r"); ++ if (f) { ++ fscanf(f, "%d", &temp); ++ fclose(f); ++ snprintf(temp_s, sizeof(temp_s), "%d.%d°C", temp / 10, temp % 10); ++ } ++ } + } + + battmon->method = BM_USE_APM; -+ return battmon_update_graph(battmon, charge, time_remaining / 60, acline, temp_s); ++ return battmon_update_status(battmon, charge, time_remaining / 60, acline, temp_s); +} + static GdkPixbuf * diff --git a/recipes/xfce-extras/xfce4-battery-plugin_0.5.1.bb b/recipes/xfce-extras/xfce4-battery-plugin_0.5.1.bb index f56db5e70b..7d02f109a7 100644 --- a/recipes/xfce-extras/xfce4-battery-plugin_0.5.1.bb +++ b/recipes/xfce-extras/xfce4-battery-plugin_0.5.1.bb @@ -3,7 +3,7 @@ DEPENDS = "libxfcegui4 xfce4-panel" RDEPENDS = "libxfcegui4 xfce4-panel" SECTION = "x11" -PR = "r3" +PR = "r4" inherit xfce46 -- 2.39.5