From 05f7fc15e167fe00d257e55b5f22564d9057a25e Mon Sep 17 00:00:00 2001 From: Sanel Zukan Date: Mon, 3 Jun 2013 17:39:50 +0000 Subject: [PATCH] Inside battery applet, do not load icon on every change event by device. Instead, check if we really need to change icon (e.g. states between 'battery' and 'battery-caution' are changed) then load it. A small formatting inside Panle and AppletManager. --- ede-panel/AppletManager.cpp | 2 +- ede-panel/Panel.cpp | 8 ++++---- .../applets/battery-monitor/BatteryMonitor.cpp | 16 ++++++++++++++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/ede-panel/AppletManager.cpp b/ede-panel/AppletManager.cpp index 7ff73d1..9803cdb 100644 --- a/ede-panel/AppletManager.cpp +++ b/ede-panel/AppletManager.cpp @@ -62,7 +62,7 @@ bool AppletManager::load(const char *path) { void *a = dlopen(path, RTLD_LAZY); if(!a) { dl_err = dlerror(); - E_WARNING(E_STRLOC ": Unable to load '%s' : '%s'\n", path, dl_err); + E_WARNING(E_STRLOC ": Unable to load '%s': '%s'\n", path, dl_err); return false; } diff --git a/ede-panel/Panel.cpp b/ede-panel/Panel.cpp index d50922a..f9c745e 100644 --- a/ede-panel/Panel.cpp +++ b/ede-panel/Panel.cpp @@ -135,10 +135,10 @@ static void fix_widget_h(Fl_Widget *o, Panel *self) { } static void add_from_list(WidgetList &lst, Panel *self, int &X, bool inc) { - WidgetListIt it = lst.begin(), it_end = lst.end(); + WidgetListIt it = lst.begin(), ite = lst.end(); Fl_Widget *o; - while(it != it_end) { + while(it != ite) { o = *it; /* 'inc == false' means we are going from right to left */ @@ -367,11 +367,11 @@ void Panel::do_layout(void) { * since add_from_list() will already reserve some space by current child width and default spacing, * those values will be used again or holes will be made */ - WidgetListIt it = resizable_h.begin(), it_end = resizable_h.end(); + WidgetListIt it = resizable_h.begin(), ite = resizable_h.end(); o = resizable_h.front(); X = o->x(); - while(it != it_end) { + while(it != ite) { o = *it; W = o->w() + free_w; diff --git a/ede-panel/applets/battery-monitor/BatteryMonitor.cpp b/ede-panel/applets/battery-monitor/BatteryMonitor.cpp index b7d214e..7bf4c8d 100644 --- a/ede-panel/applets/battery-monitor/BatteryMonitor.cpp +++ b/ede-panel/applets/battery-monitor/BatteryMonitor.cpp @@ -59,6 +59,10 @@ EDELIB_NS_USING(EDBUS_SYSTEM) #define UPOWER_INTERFACE "org.freedesktop.UPower.Device" #define UPOWER_PATH "/org/freedesktop/UPower" +#define BATTERY_MIN 10 /* minimal time before icon to BATTERY_CAUTION_IMG was changed */ +#define BATTERY_IMG "battery" +#define BATTERY_CAUTION_IMG "battery-caution" + typedef list BatteryList; typedef list::iterator BatteryListIt; @@ -70,12 +74,14 @@ typedef list::iterator BatteryListIt; */ class BatteryMonitor : public Fl_Box { private: + const char *bimg; char tip[128]; + EdbusConnection con; BatteryList batts; public: - BatteryMonitor() : Fl_Box(0, 0, 30, 25) { scan_and_init(); } + BatteryMonitor() : Fl_Box(0, 0, 30, 25), bimg(0) { scan_and_init(); } EdbusConnection &connection() { return con; } void tooltip_printf(const char *fmt, ...); @@ -243,6 +249,8 @@ int BatteryMonitor::update_icon_and_tooltip(void) { return 1; } +#define BATTERY_MIN 10 + void BatteryMonitor::set_icon(double percentage) { if(E_UNLIKELY(IconLoader::inited() == false)) { char buf[8]; @@ -252,8 +260,12 @@ void BatteryMonitor::set_icon(double percentage) { return; } - const char *icon = (percentage >= 10) ? "battery" : "battery-caution"; + const char *icon = (percentage >= BATTERY_MIN) ? BATTERY_IMG : BATTERY_CAUTION_IMG; + /* small check to prevent image loading when not needed */ + if(icon == bimg) return; + IconLoader::set(this, icon, ICON_SIZE_SMALL); + bimg = icon; } #else /* EDELIB_HAVE_DBUS */