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.
This commit is contained in:
Sanel Zukan 2013-06-03 17:39:50 +00:00
parent b24b859a4f
commit 05f7fc15e1
3 changed files with 19 additions and 7 deletions

View File

@ -62,7 +62,7 @@ bool AppletManager::load(const char *path) {
void *a = dlopen(path, RTLD_LAZY); void *a = dlopen(path, RTLD_LAZY);
if(!a) { if(!a) {
dl_err = dlerror(); 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; return false;
} }

View File

@ -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) { 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; Fl_Widget *o;
while(it != it_end) { while(it != ite) {
o = *it; o = *it;
/* 'inc == false' means we are going from right to left */ /* '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, * 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 * 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(); o = resizable_h.front();
X = o->x(); X = o->x();
while(it != it_end) { while(it != ite) {
o = *it; o = *it;
W = o->w() + free_w; W = o->w() + free_w;

View File

@ -59,6 +59,10 @@ EDELIB_NS_USING(EDBUS_SYSTEM)
#define UPOWER_INTERFACE "org.freedesktop.UPower.Device" #define UPOWER_INTERFACE "org.freedesktop.UPower.Device"
#define UPOWER_PATH "/org/freedesktop/UPower" #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<EdbusObjectPath> BatteryList; typedef list<EdbusObjectPath> BatteryList;
typedef list<EdbusObjectPath>::iterator BatteryListIt; typedef list<EdbusObjectPath>::iterator BatteryListIt;
@ -70,12 +74,14 @@ typedef list<EdbusObjectPath>::iterator BatteryListIt;
*/ */
class BatteryMonitor : public Fl_Box { class BatteryMonitor : public Fl_Box {
private: private:
const char *bimg;
char tip[128]; char tip[128];
EdbusConnection con; EdbusConnection con;
BatteryList batts; BatteryList batts;
public: 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; } EdbusConnection &connection() { return con; }
void tooltip_printf(const char *fmt, ...); void tooltip_printf(const char *fmt, ...);
@ -243,6 +249,8 @@ int BatteryMonitor::update_icon_and_tooltip(void) {
return 1; return 1;
} }
#define BATTERY_MIN 10
void BatteryMonitor::set_icon(double percentage) { void BatteryMonitor::set_icon(double percentage) {
if(E_UNLIKELY(IconLoader::inited() == false)) { if(E_UNLIKELY(IconLoader::inited() == false)) {
char buf[8]; char buf[8];
@ -252,8 +260,12 @@ void BatteryMonitor::set_icon(double percentage) {
return; 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); IconLoader::set(this, icon, ICON_SIZE_SMALL);
bimg = icon;
} }
#else /* EDELIB_HAVE_DBUS */ #else /* EDELIB_HAVE_DBUS */