mirror of
https://github.com/edeproject/ede.git
synced 2023-08-10 21:13:03 +03:00
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:
parent
6ef8fead33
commit
7d884242bd
@ -27,15 +27,16 @@
|
|||||||
#undef MAX
|
#undef MAX
|
||||||
#define MAX(x,y) ((x) > (y) ? (x) : (y))
|
#define MAX(x,y) ((x) > (y) ? (x) : (y))
|
||||||
|
|
||||||
EDELIB_NS_USING(list)
|
EDELIB_NS_USING_LIST(10, (list,
|
||||||
EDELIB_NS_USING(Resource)
|
Resource,
|
||||||
EDELIB_NS_USING(String)
|
String,
|
||||||
EDELIB_NS_USING(window_xid_create)
|
window_xid_create,
|
||||||
EDELIB_NS_USING(build_filename)
|
build_filename,
|
||||||
EDELIB_NS_USING(netwm_window_set_strut)
|
netwm_window_set_strut,
|
||||||
EDELIB_NS_USING(netwm_window_set_type)
|
netwm_window_remove_strut,
|
||||||
EDELIB_NS_USING(netwm_workarea_get_size)
|
netwm_window_set_type,
|
||||||
EDELIB_NS_USING(NETWM_WINDOW_TYPE_DOCK)
|
netwm_workarea_get_size,
|
||||||
|
NETWM_WINDOW_TYPE_DOCK))
|
||||||
|
|
||||||
typedef list<Fl_Widget*> WidgetList;
|
typedef list<Fl_Widget*> WidgetList;
|
||||||
typedef list<Fl_Widget*>::iterator WidgetListIt;
|
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;
|
screen_x = screen_y = screen_w = screen_h = screen_h_half = 0;
|
||||||
width_perc = 100;
|
width_perc = 100;
|
||||||
can_move_widgets = false;
|
can_move_widgets = false;
|
||||||
|
can_drag = true;
|
||||||
|
|
||||||
box(FL_UP_BOX);
|
box(FL_UP_BOX);
|
||||||
read_config();
|
read_config();
|
||||||
@ -330,7 +332,6 @@ void Panel::show(void) {
|
|||||||
if(!netwm_workarea_get_size(X, Y, W, H))
|
if(!netwm_workarea_get_size(X, Y, W, H))
|
||||||
Fl::screen_xywh(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_x = X;
|
||||||
screen_y = Y;
|
screen_y = Y;
|
||||||
screen_w = W;
|
screen_w = W;
|
||||||
@ -340,7 +341,7 @@ void Panel::show(void) {
|
|||||||
/* calculate panel percentage width if given */
|
/* calculate panel percentage width if given */
|
||||||
if(width_perc < 100) {
|
if(width_perc < 100) {
|
||||||
W = (width_perc * screen_w) / 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 */
|
/* 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 */
|
/* position it, this is done after XID was created */
|
||||||
if(vpos == PANEL_POSITION_BOTTOM) {
|
if(vpos == PANEL_POSITION_BOTTOM) {
|
||||||
position(screen_x, screen_h - h());
|
position(X, screen_h - h());
|
||||||
if(width_perc >= 100)
|
if(width_perc >= 100)
|
||||||
netwm_window_set_strut(fl_xid(this), 0, 0, 0, h());
|
netwm_window_set_strut(fl_xid(this), 0, 0, 0, h());
|
||||||
} else {
|
} else {
|
||||||
/* FIXME: this does not work well with edewm (nor pekwm). kwin do it correctly. */
|
/* 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)
|
if(width_perc >= 100)
|
||||||
netwm_window_set_strut(fl_xid(this), 0, 0, h(), 0);
|
netwm_window_set_strut(fl_xid(this), 0, 0, h(), 0);
|
||||||
}
|
}
|
||||||
@ -382,19 +383,21 @@ int Panel::handle(int e) {
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case FL_DRAG: {
|
case FL_DRAG: {
|
||||||
|
if(!can_drag) return 1;
|
||||||
|
|
||||||
/* are moving the panel; only vertical moving is supported */
|
/* are moving the panel; only vertical moving is supported */
|
||||||
cursor(FL_CURSOR_MOVE);
|
cursor(FL_CURSOR_MOVE);
|
||||||
|
|
||||||
/* snap it to the top or bottom, depending on pressed mouse location */
|
/* snap it to the top or bottom, depending on pressed mouse location */
|
||||||
if(Fl::event_y_root() <= screen_h_half && y() > screen_h_half) {
|
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)
|
if(width_perc >= 100)
|
||||||
netwm_window_set_strut(fl_xid(this), 0, 0, h(), 0);
|
netwm_window_set_strut(fl_xid(this), 0, 0, h(), 0);
|
||||||
vpos = PANEL_POSITION_TOP;
|
vpos = PANEL_POSITION_TOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Fl::event_y_root() > screen_h_half && y() < screen_h_half) {
|
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)
|
if(width_perc >= 100)
|
||||||
netwm_window_set_strut(fl_xid(this), 0, 0, 0, h());
|
netwm_window_set_strut(fl_xid(this), 0, 0, 0, h());
|
||||||
vpos = PANEL_POSITION_BOTTOM;
|
vpos = PANEL_POSITION_BOTTOM;
|
||||||
@ -430,6 +433,7 @@ void Panel::load_applets(void) {
|
|||||||
"start_menu.so",
|
"start_menu.so",
|
||||||
"quick_launch.so",
|
"quick_launch.so",
|
||||||
"pager.so",
|
"pager.so",
|
||||||
|
"hider.so",
|
||||||
"clock.so",
|
"clock.so",
|
||||||
"taskbar.so",
|
"taskbar.so",
|
||||||
"keyboard_layout.so",
|
"keyboard_layout.so",
|
||||||
@ -456,6 +460,7 @@ void Panel::load_applets(void) {
|
|||||||
mgr.load("./applets/start-menu/start_menu.so");
|
mgr.load("./applets/start-menu/start_menu.so");
|
||||||
mgr.load("./applets/quick-launch/quick_launch.so");
|
mgr.load("./applets/quick-launch/quick_launch.so");
|
||||||
mgr.load("./applets/pager/pager.so");
|
mgr.load("./applets/pager/pager.so");
|
||||||
|
mgr.load("./applets/hider/hider.so");
|
||||||
mgr.load("./applets/clock/clock.so");
|
mgr.load("./applets/clock/clock.so");
|
||||||
mgr.load("./applets/taskbar/taskbar.so");
|
mgr.load("./applets/taskbar/taskbar.so");
|
||||||
mgr.load("./applets/keyboard-layout/keyboard_layout.so");
|
mgr.load("./applets/keyboard-layout/keyboard_layout.so");
|
||||||
@ -465,3 +470,17 @@ void Panel::load_applets(void) {
|
|||||||
mgr.fill_group(this);
|
mgr.fill_group(this);
|
||||||
#endif
|
#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);
|
||||||
|
}
|
||||||
|
@ -21,7 +21,7 @@ private:
|
|||||||
int sx, sy;
|
int sx, sy;
|
||||||
int screen_x, screen_y, screen_w, screen_h, screen_h_half;
|
int screen_x, screen_y, screen_w, screen_h, screen_h_half;
|
||||||
int width_perc; /* user specified panel width */
|
int width_perc; /* user specified panel width */
|
||||||
bool can_move_widgets;
|
bool can_move_widgets, can_drag;
|
||||||
|
|
||||||
AppletManager mgr;
|
AppletManager mgr;
|
||||||
|
|
||||||
@ -40,6 +40,17 @@ public:
|
|||||||
int panel_w(void) { return w(); }
|
int panel_w(void) { return w(); }
|
||||||
int panel_h(void) { return h(); }
|
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(); }
|
void relayout(void) { do_layout(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ SubDir TOP ede-panel applets ;
|
|||||||
# SubInclude TOP ede-panel applets demo ;
|
# SubInclude TOP ede-panel applets demo ;
|
||||||
SubInclude TOP ede-panel applets clock ;
|
SubInclude TOP ede-panel applets clock ;
|
||||||
SubInclude TOP ede-panel applets cpu-monitor ;
|
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 mem-monitor ;
|
||||||
SubInclude TOP ede-panel applets keyboard-layout ;
|
SubInclude TOP ede-panel applets keyboard-layout ;
|
||||||
SubInclude TOP ede-panel applets pager ;
|
SubInclude TOP ede-panel applets pager ;
|
||||||
|
@ -34,7 +34,6 @@ public:
|
|||||||
static void clock_refresh(void *o) {
|
static void clock_refresh(void *o) {
|
||||||
Clock *c = (Clock *)o;
|
Clock *c = (Clock *)o;
|
||||||
c->update_time();
|
c->update_time();
|
||||||
|
|
||||||
Fl::repeat_timeout(1.0, clock_refresh, o);
|
Fl::repeat_timeout(1.0, clock_refresh, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,13 +56,19 @@ void Clock::update_time(void) {
|
|||||||
|
|
||||||
int Clock::handle(int e) {
|
int Clock::handle(int e) {
|
||||||
switch(e) {
|
switch(e) {
|
||||||
case FL_SHOW:
|
case FL_SHOW: {
|
||||||
|
int ret = Fl_Box::handle(e);
|
||||||
Fl::add_timeout(0, clock_refresh, this);
|
Fl::add_timeout(0, clock_refresh, this);
|
||||||
break;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
case FL_RELEASE:
|
case FL_RELEASE:
|
||||||
run_async("ede-timedate");
|
run_async("ede-timedate");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case FL_HIDE:
|
||||||
|
Fl::remove_timeout(clock_refresh);
|
||||||
|
/* fallthrough */
|
||||||
}
|
}
|
||||||
|
|
||||||
return Fl_Box::handle(e);
|
return Fl_Box::handle(e);
|
||||||
|
@ -142,7 +142,6 @@ CPUMonitor::CPUMonitor() : Fl_Box(0, 0, 45, 25)
|
|||||||
colors[IWM_IDLE] = FL_BACKGROUND_COLOR;
|
colors[IWM_IDLE] = FL_BACKGROUND_COLOR;
|
||||||
|
|
||||||
layout();
|
layout();
|
||||||
Fl::add_timeout(UPDATE_INTERVAL, cpu_timeout_cb, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPUMonitor::clear()
|
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() {
|
void CPUMonitor::update_status() {
|
||||||
if(!cpu) return;
|
if(!cpu) return;
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ public:
|
|||||||
|
|
||||||
void draw();
|
void draw();
|
||||||
void layout();
|
void layout();
|
||||||
|
int handle(int e);
|
||||||
|
|
||||||
int samples() const { return m_samples; }
|
int samples() const { return m_samples; }
|
||||||
};
|
};
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
EDELIB_NS_USING(color_rgb_to_fltk)
|
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)
|
#define STR_CMP(first, second, n) (strncmp(first, second, n) == 0)
|
||||||
|
|
||||||
static int height_from_perc(int perc, int h) {
|
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) {
|
MemMonitor::MemMonitor() : Fl_Box(0, 0, 45, 25), mem_usedp(0), swap_usedp(0) {
|
||||||
box(FL_THIN_DOWN_BOX);
|
box(FL_THIN_DOWN_BOX);
|
||||||
Fl::add_timeout(UPDATE_INTERVAL, mem_timeout_cb, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemMonitor::update_status(void) {
|
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));
|
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 (
|
EDE_PANEL_APPLET_EXPORT (
|
||||||
MemMonitor,
|
MemMonitor,
|
||||||
EDE_PANEL_APPLET_OPTION_ALIGN_RIGHT,
|
EDE_PANEL_APPLET_OPTION_ALIGN_RIGHT,
|
||||||
|
@ -11,6 +11,7 @@ public:
|
|||||||
MemMonitor();
|
MemMonitor();
|
||||||
void update_status(void);
|
void update_status(void);
|
||||||
void draw(void);
|
void draw(void);
|
||||||
|
int handle(int e);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user