mirror of
https://github.com/edeproject/ede.git
synced 2023-08-10 21:13:03 +03:00
Initial import of memory monitor applet
This commit is contained in:
@@ -404,6 +404,7 @@ int Panel::handle(int e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Panel::load_applets(void) {
|
void Panel::load_applets(void) {
|
||||||
|
#if 0
|
||||||
/* FIXME: hardcoded order */
|
/* FIXME: hardcoded order */
|
||||||
static const char *applets[] = {
|
static const char *applets[] = {
|
||||||
"start_menu.so",
|
"start_menu.so",
|
||||||
@@ -427,8 +428,8 @@ void Panel::load_applets(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mgr.fill_group(this);
|
mgr.fill_group(this);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if 0
|
|
||||||
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");
|
||||||
@@ -436,6 +437,6 @@ void Panel::load_applets(void) {
|
|||||||
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");
|
||||||
mgr.load("./applets/cpu-monitor/cpu_monitor.so");
|
mgr.load("./applets/cpu-monitor/cpu_monitor.so");
|
||||||
|
mgr.load("./applets/mem-monitor/mem_monitor.so");
|
||||||
mgr.fill_group(this);
|
mgr.fill_group(this);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
@@ -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 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 ;
|
||||||
SubInclude TOP ede-panel applets quick-launch ;
|
SubInclude TOP ede-panel applets quick-launch ;
|
||||||
|
13
ede-panel/applets/mem-monitor/Jamfile
Normal file
13
ede-panel/applets/mem-monitor/Jamfile
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#
|
||||||
|
# $Id: Jamfile 2922 2009-11-05 15:18:51Z karijes $
|
||||||
|
#
|
||||||
|
# Part of Equinox Desktop Environment (EDE).
|
||||||
|
# Copyright (c) 2009 EDE Authors.
|
||||||
|
#
|
||||||
|
# This program is licensed under terms of the
|
||||||
|
# GNU General Public License version 2 or newer.
|
||||||
|
# See COPYING for details.
|
||||||
|
|
||||||
|
SubDir TOP ede-panel applets mem-monitor ;
|
||||||
|
|
||||||
|
PanelApplet mem_monitor : MemMonitor.cpp ;
|
67
ede-panel/applets/mem-monitor/MemMonitor.cpp
Normal file
67
ede-panel/applets/mem-monitor/MemMonitor.cpp
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
#include <FL/Fl.H>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <edelib/Missing.h>
|
||||||
|
#include "Applet.h"
|
||||||
|
#include "MemMonitor.h"
|
||||||
|
|
||||||
|
#define UPDATE_INTERVAL .5f
|
||||||
|
#define STR_CMP(first, second, n) (strncmp(first, second, n) == 0)
|
||||||
|
|
||||||
|
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)
|
||||||
|
return atol(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(s);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mem_timeout_cb(void *d) {
|
||||||
|
((MemMonitor*)d)->update_status();
|
||||||
|
Fl::repeat_timeout(UPDATE_INTERVAL, mem_timeout_cb, 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) {
|
||||||
|
FILE *fd = fopen("/proc/meminfo", "r");
|
||||||
|
if(!fd) return;
|
||||||
|
|
||||||
|
long mem_total, mem_free, swap_total, swap_free;
|
||||||
|
mem_total = mem_free = swap_total = swap_free = 0;
|
||||||
|
|
||||||
|
char buf[128];
|
||||||
|
while(fgets(buf, 128, fd) != 0) {
|
||||||
|
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);
|
||||||
|
swap_usedp = 100 - (int)(((float)swap_total / (float)swap_free) * 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
EDE_PANEL_APPLET_EXPORT (
|
||||||
|
MemMonitor,
|
||||||
|
EDE_PANEL_APPLET_OPTION_ALIGN_RIGHT,
|
||||||
|
"Memory monitor",
|
||||||
|
"0.1",
|
||||||
|
"empty",
|
||||||
|
"Sanel Zukan"
|
||||||
|
)
|
15
ede-panel/applets/mem-monitor/MemMonitor.h
Normal file
15
ede-panel/applets/mem-monitor/MemMonitor.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef __MEMMONITOR_H__
|
||||||
|
#define __MEMMONITOR_H__
|
||||||
|
|
||||||
|
#include <FL/Fl_Box.H>
|
||||||
|
|
||||||
|
class MemMonitor : public Fl_Box {
|
||||||
|
private:
|
||||||
|
int mem_usedp, swap_usedp;
|
||||||
|
|
||||||
|
public:
|
||||||
|
MemMonitor();
|
||||||
|
void update_status(void);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Reference in New Issue
Block a user