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

@ -27,15 +27,16 @@
#undef MAX
#define MAX(x,y) ((x) > (y) ? (x) : (y))
EDELIB_NS_USING(list)
EDELIB_NS_USING(Resource)
EDELIB_NS_USING(String)
EDELIB_NS_USING(window_xid_create)
EDELIB_NS_USING(build_filename)
EDELIB_NS_USING(netwm_window_set_strut)
EDELIB_NS_USING(netwm_window_set_type)
EDELIB_NS_USING(netwm_workarea_get_size)
EDELIB_NS_USING(NETWM_WINDOW_TYPE_DOCK)
EDELIB_NS_USING_LIST(10, (list,
Resource,
String,
window_xid_create,
build_filename,
netwm_window_set_strut,
netwm_window_remove_strut,
netwm_window_set_type,
netwm_workarea_get_size,
NETWM_WINDOW_TYPE_DOCK))
typedef list<Fl_Widget*> WidgetList;
typedef list<Fl_Widget*>::iterator WidgetListIt;
@ -180,6 +181,7 @@ Panel::Panel() : PanelWindow(300, 30) {
screen_x = screen_y = screen_w = screen_h = screen_h_half = 0;
width_perc = 100;
can_move_widgets = false;
can_drag = true;
box(FL_UP_BOX);
read_config();
@ -330,7 +332,6 @@ void Panel::show(void) {
if(!netwm_workarea_get_size(X, Y, W, H))
Fl::screen_xywh(X, Y, W, H);
/* TODO: these numbers are also used to calculate panel x,y,w,h so rename it! */
screen_x = X;
screen_y = Y;
screen_w = W;
@ -340,7 +341,7 @@ void Panel::show(void) {
/* calculate panel percentage width if given */
if(width_perc < 100) {
W = (width_perc * screen_w) / 100;
screen_x = (screen_w / 2) - (W / 2);
X = (screen_w / 2) - (W / 2);
}
/* set size as soon as possible, since do_layout() depends on it */
@ -351,12 +352,12 @@ void Panel::show(void) {
/* position it, this is done after XID was created */
if(vpos == PANEL_POSITION_BOTTOM) {
position(screen_x, screen_h - h());
position(X, screen_h - h());
if(width_perc >= 100)
netwm_window_set_strut(fl_xid(this), 0, 0, 0, h());
} else {
/* FIXME: this does not work well with edewm (nor pekwm). kwin do it correctly. */
position(screen_x, screen_y);
position(X, Y);
if(width_perc >= 100)
netwm_window_set_strut(fl_xid(this), 0, 0, h(), 0);
}
@ -382,19 +383,21 @@ int Panel::handle(int e) {
return 1;
case FL_DRAG: {
if(!can_drag) return 1;
/* are moving the panel; only vertical moving is supported */
cursor(FL_CURSOR_MOVE);
/* snap it to the top or bottom, depending on pressed mouse location */
if(Fl::event_y_root() <= screen_h_half && y() > screen_h_half) {
position(screen_x, screen_y);
position(x(), screen_y);
if(width_perc >= 100)
netwm_window_set_strut(fl_xid(this), 0, 0, h(), 0);
vpos = PANEL_POSITION_TOP;
}
if(Fl::event_y_root() > screen_h_half && y() < screen_h_half) {
position(screen_x, screen_h - h());
position(x(), screen_h - h());
if(width_perc >= 100)
netwm_window_set_strut(fl_xid(this), 0, 0, 0, h());
vpos = PANEL_POSITION_BOTTOM;
@ -430,6 +433,7 @@ void Panel::load_applets(void) {
"start_menu.so",
"quick_launch.so",
"pager.so",
"hider.so",
"clock.so",
"taskbar.so",
"keyboard_layout.so",
@ -456,6 +460,7 @@ void Panel::load_applets(void) {
mgr.load("./applets/start-menu/start_menu.so");
mgr.load("./applets/quick-launch/quick_launch.so");
mgr.load("./applets/pager/pager.so");
mgr.load("./applets/hider/hider.so");
mgr.load("./applets/clock/clock.so");
mgr.load("./applets/taskbar/taskbar.so");
mgr.load("./applets/keyboard-layout/keyboard_layout.so");
@ -465,3 +470,17 @@ void Panel::load_applets(void) {
mgr.fill_group(this);
#endif
}
/* TODO: can be better */
void Panel::apply_struts(bool apply) {
if(!(width_perc >= 100)) return;
int bottom = 0, top = 0;
if(vpos == PANEL_POSITION_TOP)
top = !apply ? 1 : h();
else
bottom = !apply ? 1 : h();
netwm_window_set_strut(fl_xid(this), 0, 0, top, bottom);
}

View File

@ -21,7 +21,7 @@ private:
int sx, sy;
int screen_x, screen_y, screen_w, screen_h, screen_h_half;
int width_perc; /* user specified panel width */
bool can_move_widgets;
bool can_move_widgets, can_drag;
AppletManager mgr;
@ -40,6 +40,17 @@ public:
int panel_w(void) { return w(); }
int panel_h(void) { return h(); }
void screen_size(int &x, int &y, int &w, int &h) {
x = screen_x;
y = screen_y;
w = screen_w;
h = screen_h;
}
/* so applets can do something */
void apply_struts(bool apply);
void allow_drag(bool d) { can_drag = d; }
void relayout(void) { do_layout(); }
};

View File

@ -13,6 +13,7 @@ SubDir TOP ede-panel applets ;
# SubInclude TOP ede-panel applets demo ;
SubInclude TOP ede-panel applets clock ;
SubInclude TOP ede-panel applets cpu-monitor ;
SubInclude TOP ede-panel applets hider ;
SubInclude TOP ede-panel applets mem-monitor ;
SubInclude TOP ede-panel applets keyboard-layout ;
SubInclude TOP ede-panel applets pager ;

View File

@ -34,7 +34,6 @@ public:
static void clock_refresh(void *o) {
Clock *c = (Clock *)o;
c->update_time();
Fl::repeat_timeout(1.0, clock_refresh, o);
}
@ -57,13 +56,19 @@ void Clock::update_time(void) {
int Clock::handle(int e) {
switch(e) {
case FL_SHOW:
case FL_SHOW: {
int ret = Fl_Box::handle(e);
Fl::add_timeout(0, clock_refresh, this);
break;
return ret;
}
case FL_RELEASE:
run_async("ede-timedate");
break;
case FL_HIDE:
Fl::remove_timeout(clock_refresh);
/* fallthrough */
}
return Fl_Box::handle(e);

View File

@ -142,7 +142,6 @@ CPUMonitor::CPUMonitor() : Fl_Box(0, 0, 45, 25)
colors[IWM_IDLE] = FL_BACKGROUND_COLOR;
layout();
Fl::add_timeout(UPDATE_INTERVAL, cpu_timeout_cb, this);
}
void CPUMonitor::clear()
@ -247,6 +246,22 @@ void CPUMonitor::layout() {
}
}
int CPUMonitor::handle(int e) {
switch(e) {
case FL_SHOW: {
int ret = Fl_Box::handle(e);
Fl::add_timeout(UPDATE_INTERVAL, cpu_timeout_cb, this);
return ret;
}
case FL_HIDE:
Fl::remove_timeout(cpu_timeout_cb);
/* fallthrough */
}
return Fl_Box::handle(e);
}
void CPUMonitor::update_status() {
if(!cpu) return;

View File

@ -39,6 +39,7 @@ public:
void draw();
void layout();
int handle(int e);
int samples() const { return m_samples; }
};

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,

View File

@ -11,6 +11,7 @@ public:
MemMonitor();
void update_status(void);
void draw(void);
int handle(int e);
};
#endif