Added support for Linux (via sysinfo() like in Network/Probe)
This commit is contained in:
parent
e1664a0463
commit
3c7fd53251
|
@ -19,7 +19,9 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#ifdef __NetBSD__
|
#if defined(__linux__)
|
||||||
|
# include <sys/sysinfo.h>
|
||||||
|
#elif defined(__NetBSD__)
|
||||||
# include <sys/sysctl.h>
|
# include <sys/sysctl.h>
|
||||||
#endif
|
#endif
|
||||||
#include "Panel.h"
|
#include "Panel.h"
|
||||||
|
@ -30,6 +32,7 @@
|
||||||
/* types */
|
/* types */
|
||||||
typedef struct _Memory
|
typedef struct _Memory
|
||||||
{
|
{
|
||||||
|
PanelAppletHelper * helper;
|
||||||
GtkWidget * scale;
|
GtkWidget * scale;
|
||||||
guint timeout;
|
guint timeout;
|
||||||
} Memory;
|
} Memory;
|
||||||
|
@ -40,7 +43,7 @@ static GtkWidget * _memory_init(PanelApplet * applet);
|
||||||
static void _memory_destroy(PanelApplet * applet);
|
static void _memory_destroy(PanelApplet * applet);
|
||||||
|
|
||||||
/* callbacks */
|
/* callbacks */
|
||||||
#ifdef __NetBSD__
|
#if defined(__linux__) || defined(__NetBSD__)
|
||||||
static gboolean _on_timeout(gpointer data);
|
static gboolean _on_timeout(gpointer data);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -64,7 +67,7 @@ PanelApplet applet =
|
||||||
/* memory_init */
|
/* memory_init */
|
||||||
static GtkWidget * _memory_init(PanelApplet * applet)
|
static GtkWidget * _memory_init(PanelApplet * applet)
|
||||||
{
|
{
|
||||||
#ifdef __NetBSD__
|
#if defined(__linux__) || defined(__NetBSD__)
|
||||||
GtkWidget * ret;
|
GtkWidget * ret;
|
||||||
Memory * memory;
|
Memory * memory;
|
||||||
PangoFontDescription * desc;
|
PangoFontDescription * desc;
|
||||||
|
@ -76,6 +79,7 @@ static GtkWidget * _memory_init(PanelApplet * applet)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
applet->priv = memory;
|
applet->priv = memory;
|
||||||
|
memory->helper = applet->helper;
|
||||||
ret = gtk_hbox_new(FALSE, 0);
|
ret = gtk_hbox_new(FALSE, 0);
|
||||||
desc = pango_font_description_new();
|
desc = pango_font_description_new();
|
||||||
pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD);
|
pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD);
|
||||||
|
@ -111,7 +115,21 @@ static void _memory_destroy(PanelApplet * applet)
|
||||||
|
|
||||||
/* callbacks */
|
/* callbacks */
|
||||||
/* on_timeout */
|
/* on_timeout */
|
||||||
#ifdef __NetBSD__
|
#if defined(__linux__)
|
||||||
|
static gboolean _on_timeout(gpointer data)
|
||||||
|
{
|
||||||
|
Memory * memory = data;
|
||||||
|
struct sysinfo sy;
|
||||||
|
gdouble value;
|
||||||
|
|
||||||
|
if(sysinfo(&sy) != 0)
|
||||||
|
return memory->helper->error(memory->helper->priv, "sysinfo", TRUE);
|
||||||
|
value = sy.sharedram;
|
||||||
|
value /= sy.totalram;
|
||||||
|
gtk_range_set_value(GTK_RANGE(memory->scale), value);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
#elif defined(__NetBSD__)
|
||||||
static gboolean _on_timeout(gpointer data)
|
static gboolean _on_timeout(gpointer data)
|
||||||
{
|
{
|
||||||
Memory * memory = data;
|
Memory * memory = data;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user