mirror of
https://github.com/edeproject/ede.git
synced 2023-08-10 21:13:03 +03:00
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:
parent
b24b859a4f
commit
05f7fc15e1
@ -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;
|
||||
|
@ -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<EdbusObjectPath> BatteryList;
|
||||
typedef list<EdbusObjectPath>::iterator BatteryListIt;
|
||||
|
||||
@ -70,12 +74,14 @@ typedef list<EdbusObjectPath>::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 */
|
||||
|
Loading…
Reference in New Issue
Block a user