Do not run timeout callbacks when panel is hidden. This will prevent reading cpu or memory status when their widgets are not visible.

This commit is contained in:
Sanel Zukan
2012-04-11 16:15:01 +00:00
parent 6ef8fead33
commit 7d884242bd
8 changed files with 90 additions and 22 deletions

View File

@@ -10,7 +10,7 @@
EDELIB_NS_USING(color_rgb_to_fltk)
#define UPDATE_INTERVAL .5f
#define UPDATE_INTERVAL 1.0f
#define STR_CMP(first, second, n) (strncmp(first, second, n) == 0)
static int height_from_perc(int perc, int h) {
@@ -36,7 +36,6 @@ static void mem_timeout_cb(void *d) {
MemMonitor::MemMonitor() : Fl_Box(0, 0, 45, 25), mem_usedp(0), swap_usedp(0) {
box(FL_THIN_DOWN_BOX);
Fl::add_timeout(UPDATE_INTERVAL, mem_timeout_cb, this);
}
void MemMonitor::update_status(void) {
@@ -87,6 +86,22 @@ void MemMonitor::draw(void) {
fl_rectf(X + W2, Y + H - sh, W2, sh, (Fl_Color)color_rgb_to_fltk(54, 136, 79));
}
int MemMonitor::handle(int e) {
switch(e) {
case FL_SHOW: {
int ret = Fl_Box::handle(e);
Fl::add_timeout(UPDATE_INTERVAL, mem_timeout_cb, this);
return ret;
}
case FL_HIDE:
Fl::remove_timeout(mem_timeout_cb);
/* fallthrough */
}
return Fl_Box::handle(e);
}
EDE_PANEL_APPLET_EXPORT (
MemMonitor,
EDE_PANEL_APPLET_OPTION_ALIGN_RIGHT,