mirror of
https://github.com/edeproject/ede.git
synced 2023-08-10 21:13:03 +03:00
Moving memory query status code to use sysinfo() instead of /proc.
This commit is contained in:
parent
e01506d58a
commit
465eb7dfe3
@ -112,7 +112,6 @@ bool AppletManager::load(const char *path) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AppletData *data = new AppletData;
|
AppletData *data = new AppletData;
|
||||||
data->dl = a;
|
data->dl = a;
|
||||||
data->awidget = NULL;
|
data->awidget = NULL;
|
||||||
@ -132,11 +131,10 @@ bool AppletManager::load(const char *path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AppletManager::clear(void) {
|
void AppletManager::clear(void) {
|
||||||
if(applet_list.empty())
|
E_RETURN_IF_FAIL(applet_list.size() > 0);
|
||||||
return;
|
|
||||||
|
|
||||||
AListIter it = applet_list.begin(), it_end = applet_list.end();
|
AListIter it = applet_list.begin(), ite = applet_list.end();
|
||||||
while(it != it_end) {
|
while(it != ite) {
|
||||||
clear_applet(*it);
|
clear_applet(*it);
|
||||||
it = applet_list.erase(it);
|
it = applet_list.erase(it);
|
||||||
}
|
}
|
||||||
@ -147,29 +145,29 @@ void AppletManager::clear(void) {
|
|||||||
* added to the group.
|
* added to the group.
|
||||||
*/
|
*/
|
||||||
void AppletManager::fill_group(Panel *p) {
|
void AppletManager::fill_group(Panel *p) {
|
||||||
AListIter it = applet_list.begin(), it_end = applet_list.end();
|
AListIter it = applet_list.begin(), ite = applet_list.end();
|
||||||
AppletData *applet;
|
AppletData *applet;
|
||||||
|
|
||||||
for(; it != it_end; ++it) {
|
for(; it != ite; ++it) {
|
||||||
applet = *it;
|
applet = *it;
|
||||||
|
|
||||||
/* allocate memory for widget and append it to group */
|
/* allocate memory for widget and append it to the group */
|
||||||
applet->awidget = applet->create_func();
|
applet->awidget = applet->create_func();
|
||||||
p->add(applet->awidget);
|
p->add(applet->awidget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletManager::unfill_group(Panel *p) {
|
void AppletManager::unfill_group(Panel *p) {
|
||||||
AListIter it = applet_list.begin(), it_end = applet_list.end();
|
AListIter it = applet_list.begin(), ite = applet_list.end();
|
||||||
|
|
||||||
for(; it != it_end; ++it)
|
for(; it != ite; ++it)
|
||||||
p->remove((*it)->awidget);
|
p->remove((*it)->awidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppletManager::get_applet_options(Fl_Widget *o, unsigned long &opts) {
|
bool AppletManager::get_applet_options(Fl_Widget *o, unsigned long &opts) {
|
||||||
AListIter it = applet_list.begin(), it_end = applet_list.end();
|
AListIter it = applet_list.begin(), ite = applet_list.end();
|
||||||
|
|
||||||
for(; it != it_end; ++it) {
|
for(; it != ite; ++it) {
|
||||||
if(o == (*it)->awidget) {
|
if(o == (*it)->awidget) {
|
||||||
opts = (*it)->ainfo->options;
|
opts = (*it)->ainfo->options;
|
||||||
return true;
|
return true;
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
SubDir TOP ede-panel ;
|
SubDir TOP ede-panel ;
|
||||||
|
|
||||||
EdeProgram ede-panel : Hider.cpp Panel.cpp AppletManager.cpp ede-panel.cpp ;
|
EdeProgram ede-panel : Hider.cpp Panel.cpp AppletManager.cpp ede-panel.cpp ;
|
||||||
#ObjectC++Flags Panel.cpp : -DEDE_PANEL_LOCAL_APPLETS ;
|
ObjectC++Flags Panel.cpp : -DEDE_PANEL_LOCAL_APPLETS ;
|
||||||
|
|
||||||
if $(OS) != "SOLARIS" {
|
if $(OS) != "SOLARIS" {
|
||||||
# also must use this flag (on anything but Solaris) or program will crash
|
# also must use this flag (on anything but Solaris) or program will crash
|
||||||
|
@ -534,8 +534,8 @@ void Panel::load_applets(void) {
|
|||||||
|
|
||||||
mgr.fill_group(this);
|
mgr.fill_group(this);
|
||||||
#else
|
#else
|
||||||
mgr.load("./applets/quick-launch/quick_launch.so");
|
|
||||||
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/pager/pager.so");
|
mgr.load("./applets/pager/pager.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");
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
/* assume Linux here */
|
||||||
|
#include <sys/sysinfo.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <FL/Fl.H>
|
#include <FL/Fl.H>
|
||||||
#include <FL/fl_draw.H>
|
#include <FL/fl_draw.H>
|
||||||
@ -13,25 +15,10 @@ EDELIB_NS_USING(color_rgb_to_fltk)
|
|||||||
#define UPDATE_INTERVAL 1.0f
|
#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) {
|
inline int height_from_perc(int perc, int h) {
|
||||||
return (perc * h) / 100;
|
return (perc * h) / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long get_number(const char *ln) {
|
|
||||||
char *s = edelib_strndup(ln, 128);
|
|
||||||
int i = 1;
|
|
||||||
|
|
||||||
for(char *p = strtok(s, " "); p; p = strtok(NULL, " "), i++) {
|
|
||||||
if(i == 2) {
|
|
||||||
long ret = atol(p);
|
|
||||||
free(s);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
free(s);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
static void mem_timeout_cb(void *d) {
|
static void mem_timeout_cb(void *d) {
|
||||||
((MemMonitor*)d)->update_status();
|
((MemMonitor*)d)->update_status();
|
||||||
Fl::repeat_timeout(UPDATE_INTERVAL, mem_timeout_cb, d);
|
Fl::repeat_timeout(UPDATE_INTERVAL, mem_timeout_cb, d);
|
||||||
@ -42,25 +29,14 @@ MemMonitor::MemMonitor() : Fl_Box(0, 0, 45, 25), mem_usedp(0), swap_usedp(0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MemMonitor::update_status(void) {
|
void MemMonitor::update_status(void) {
|
||||||
FILE *fd = fopen("/proc/meminfo", "r");
|
struct sysinfo sys;
|
||||||
if(!fd) return;
|
if(sysinfo(&sys) != 0) return;
|
||||||
|
|
||||||
long mem_total, mem_free, swap_total, swap_free;
|
long mem_total, mem_free, swap_total, swap_free;
|
||||||
mem_total = mem_free = swap_total = swap_free = 0;
|
mem_total = (float)sys.totalram * (float)sys.mem_unit / 1048576.0f;
|
||||||
|
mem_free = (float)sys.freeram * (float)sys.mem_unit / 1048576.0f;
|
||||||
static char buf[128];
|
swap_total = (float)sys.totalswap * (float)sys.mem_unit / 1048576.0f;
|
||||||
while(fgets(buf, sizeof(buf), fd) != 0) {
|
swap_free = (float)sys.freeswap * (float)sys.mem_unit / 1048576.0f;
|
||||||
if(STR_CMP(buf, "MemTotal:", 9))
|
|
||||||
mem_total = get_number(buf);
|
|
||||||
else if(STR_CMP(buf, "MemFree:", 8))
|
|
||||||
mem_free = get_number(buf);
|
|
||||||
else if(STR_CMP(buf, "SwapTotal:", 10))
|
|
||||||
swap_total = get_number(buf);
|
|
||||||
else if(STR_CMP(buf, "SwapFree:", 9))
|
|
||||||
swap_free = get_number(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(fd);
|
|
||||||
|
|
||||||
mem_usedp = 100 - (int)(((float)mem_free / (float)mem_total) * 100);
|
mem_usedp = 100 - (int)(((float)mem_free / (float)mem_total) * 100);
|
||||||
swap_usedp = 100 - (int)(((float)swap_free / (float)swap_total) * 100);
|
swap_usedp = 100 - (int)(((float)swap_free / (float)swap_total) * 100);
|
||||||
|
Loading…
Reference in New Issue
Block a user