[gnome-shell-extensions] systemMonitor: new extension
- From: Maxim Ermilov <mermilov src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell-extensions] systemMonitor: new extension
- Date: Tue, 10 May 2011 20:44:17 +0000 (UTC)
commit 30273d09df9132d85193159c36130649cc8bb2f2
Author: Maxim Ermilov <zaspire rambler ru>
Date: Tue May 10 01:50:07 2011 +0400
systemMonitor: new extension
https://bugzilla.gnome.org/show_bug.cgi?id=634080
configure.ac | 7 ++-
extensions/systemMonitor/Makefile.am | 3 +
extensions/systemMonitor/extension.js | 133 +++++++++++++++++++++++++++++
extensions/systemMonitor/metadata.json.in | 9 ++
extensions/systemMonitor/stylesheet.css | 16 ++++
5 files changed, 167 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index be59e71..37545dd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -21,7 +21,7 @@ GLIB_GSETTINGS
ADDITIONAL_PACKAGES=
dnl keep this in sync with extensions/Makefile.am
-ALL_EXTENSIONS="example alternate-tab xrandr-indicator windowsNavigator auto-move-windows dock user-theme alternative-status-menu gajim drive-menu places-menu"
+ALL_EXTENSIONS="example systemMonitor alternate-tab xrandr-indicator windowsNavigator auto-move-windows dock user-theme alternative-status-menu gajim drive-menu places-menu"
AC_SUBST(ALL_EXTENSIONS, [$ALL_EXTENSIONS])
DEFAULT_EXTENSIONS="alternate-tab windowsNavigator dock alternative-status-menu drive-menu places-menu"
AC_ARG_ENABLE([extensions],
@@ -39,6 +39,10 @@ ADDITIONAL_PACKAGES=
ENABLED_EXTENSIONS=
for e in $enable_extensions; do
case $e in
+ systemMonitor)
+ ENABLED_EXTENSIONS="$ENABLED_EXTENSIONS $e"
+ ADDITIONAL_PACKAGES="$ADDITIONAL_PAGKAGES libgtop-2.0 >= 2.28.3"
+ ;;
xrandr-indicator)
ENABLED_EXTENSIONS="$ENABLED_EXTENSIONS $e"
ADDITIONAL_PACKAGES="$ADDITIONAL_PAGKAGES gnome-desktop-3.0 >= 2.91.6"
@@ -68,6 +72,7 @@ AC_CONFIG_FILES([
extensions/dock/Makefile
extensions/drive-menu/Makefile
extensions/example/Makefile
+ extensions/systemMonitor/Makefile
extensions/windowsNavigator/Makefile
extensions/gajim/Makefile
extensions/places-menu/Makefile
diff --git a/extensions/systemMonitor/Makefile.am b/extensions/systemMonitor/Makefile.am
new file mode 100644
index 0000000..50ce6d2
--- /dev/null
+++ b/extensions/systemMonitor/Makefile.am
@@ -0,0 +1,3 @@
+EXTENSION_ID = systemMonitor
+
+include ../../extension.mk
diff --git a/extensions/systemMonitor/extension.js b/extensions/systemMonitor/extension.js
new file mode 100644
index 0000000..e9231da
--- /dev/null
+++ b/extensions/systemMonitor/extension.js
@@ -0,0 +1,133 @@
+/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
+
+const Clutter = imports.gi.Clutter;
+const GTop = imports.gi.GTop;
+const Lang = imports.lang;
+const Mainloop = imports.mainloop;
+const St = imports.gi.St;
+const Shell = imports.gi.Shell;
+
+const Main = imports.ui.main;
+
+function Indicator() {
+ this._init();
+}
+
+Indicator.prototype = {
+ _init: function() {
+ this._initValues();
+ this.actor = new St.DrawingArea({ style_class: "extension-systemMonitor-indicator-area",
+ reactive: true});
+ this.actor.connect('repaint', Lang.bind(this, this._draw));
+ this.actor.connect('button-press-event', function() {
+ let app = Shell.AppSystem.get_default().get_app("gnome-system-monitor.desktop");
+ app.open_new_window(-1);
+ });
+
+ Mainloop.timeout_add(250, Lang.bind(this, function () {
+ this._updateValues();
+ this.actor.queue_repaint();
+ return true;
+ }));
+ },
+
+ _initValues: function() {
+ },
+
+ _updateValues: function() {
+ },
+
+ _draw: function(area) {
+ let [width, height] = area.get_surface_size();
+ let themeNode = this.actor.get_theme_node();
+ let cr = area.get_context();
+ for (let i = this.values.length - 1; i >= 0; i--) {
+ let color = themeNode.get_color(this.values[i].color);
+ cr.moveTo(0, height);
+ let k;
+ for (k = 0; k < this.values[i].values.length; k++) {
+ cr.lineTo(k, (1 - this.values[i].values[k]) * height);
+ }
+ if (k > width)
+ this.values[i].values.shift();
+ cr.lineTo(k, height);
+ cr.lineTo(0, height);
+ cr.closePath();
+ Clutter.cairo_set_source_color(cr, color);
+
+ cr.fill();
+ }
+ }
+};
+
+function CpuIndicator() {
+ this._init();
+}
+
+CpuIndicator.prototype = {
+ __proto__: Indicator.prototype,
+
+ _initValues: function() {
+ this._prev = new GTop.glibtop_cpu;
+ GTop.glibtop_get_cpu(this._prev);
+
+ this.values = [];
+ this.values.push({color: "-cpu-user-color", values: []});
+ this.values.push({color: "-cpu-sys-color", values: []});
+ this.values.push({color: "-cpu-iowait-color", values: []});
+ },
+
+ _updateValues: function() {
+ let cpu = new GTop.glibtop_cpu;
+ let t = 0.0;
+ GTop.glibtop_get_cpu(cpu);
+ let total = cpu.total - this._prev.total;
+ let user = cpu.user - this._prev.user;
+ let sys = cpu.sys - this._prev.sys;
+ let iowait = cpu.iowait - this._prev.iowait;
+
+ t = user / total;
+ this.values[0].values.push(t);
+
+ t += sys / total;
+ this.values[1].values.push(t);
+ t += iowait / total;
+ this.values[2].values.push(t);
+
+ this._prev = cpu;
+ }
+};
+
+function MemoryIndicator() {
+ this._init();
+}
+
+MemoryIndicator.prototype = {
+ __proto__: Indicator.prototype,
+
+ _initValues: function() {
+ this.mem = new GTop.glibtop_mem;
+ this.values = [];
+ this.values.push({ color: "-mem-user-color", values: [] });
+ this.values.push({ color: "-mem-other-color", values: [] });
+ this.values.push({ color: "-mem-cached-color", values: [] });
+ },
+
+ _updateValues: function() {
+ GTop.glibtop_get_mem(this.mem);
+
+ let t = this.mem.user / this.mem.total;
+ this.values[0].values.push(t);
+ t += (this.mem.used - this.mem.user - this.mem.cached) / this.mem.total;
+ this.values[1].values.push(t);
+ t += this.mem.cached / this.mem.total;
+ this.values[2].values.push(t);
+ }
+};
+
+function main() {
+ let box = new St.BoxLayout({ style_class: 'extension-systemMonitor-container' });
+ box.add((new CpuIndicator()).actor);
+ box.add((new MemoryIndicator()).actor);
+ Main.messageTray.actor.add_actor(box);
+}
diff --git a/extensions/systemMonitor/metadata.json.in b/extensions/systemMonitor/metadata.json.in
new file mode 100644
index 0000000..8e4ac91
--- /dev/null
+++ b/extensions/systemMonitor/metadata.json.in
@@ -0,0 +1,9 @@
+{
+ "shell-version": ["@shell_current@"],
+ "uuid": "@uuid@",
+ "localedir": "@LOCALEDIR@",
+ "original-author": "zaspire rambler ru",
+ "name": "SystemMonitor",
+ "description": "System Monitor",
+ "url": "@url@"
+}
\ No newline at end of file
diff --git a/extensions/systemMonitor/stylesheet.css b/extensions/systemMonitor/stylesheet.css
new file mode 100644
index 0000000..26aad6b
--- /dev/null
+++ b/extensions/systemMonitor/stylesheet.css
@@ -0,0 +1,16 @@
+.extension-systemMonitor-container {
+ spacing: 5px;
+}
+
+.extension-systemMonitor-indicator-area {
+ border: 1px solid #000;
+ width: 100px;
+ height: 34px;
+ -cpu-user-color: #f00;
+ -cpu-sys-color: #0f0;
+ -cpu-iowait-color: #00f;
+ -mem-user-color: #ff0;
+ -mem-cached-color: #0ff;
+ -mem-other-color: #111;
+ background-color: #fff;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]