forked from PlugaruT/wingpanel-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
edcfea6
commit 3cf5b9e
Showing
11 changed files
with
200 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
*~ | ||
build/ | ||
uncrustify.cfg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/*- | ||
* Copyright (c) 2020 Tudor Plugaru (https://github.com/PlugaruT/wingpanel-monitor) | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the | ||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301 USA. | ||
* | ||
* Authored by: Tudor Plugaru <plugaru.tudor@gmail.com> | ||
*/ | ||
namespace WingpanelMonitor { | ||
public class Disk : GLib.Object { | ||
private int _bytes_write; | ||
private ulong _bytes_write_old; | ||
private bool control; | ||
|
||
private int _bytes_read; | ||
private ulong _bytes_read_old; | ||
|
||
public Disk () { | ||
_bytes_write = 0; | ||
_bytes_write_old = 0; | ||
_bytes_read = 0; | ||
_bytes_read_old = 0; | ||
control = false; | ||
} | ||
|
||
public int[] get_bytes () { | ||
if (control == false) { | ||
control = true; | ||
update_bytes_total (); | ||
} else { | ||
control = false; | ||
} | ||
int[] ret; | ||
ret = {_bytes_read, _bytes_write}; | ||
return ret; | ||
} | ||
|
||
private void update_bytes_total () { | ||
|
||
ulong n_bytes_read = 0; | ||
ulong n_bytes_write = 0; | ||
|
||
try { | ||
string content = null; | ||
FileUtils.get_contents (@"/proc/diskstats", out content); | ||
InputStream input_stream = new MemoryInputStream.from_data (content.data, GLib.g_free); | ||
DataInputStream dis = new DataInputStream (input_stream); | ||
string line; | ||
|
||
while ((line = dis.read_line ()) != null) { | ||
string[] reg_split = Regex.split_simple("[ ]+", line); | ||
if(reg_split[1] == "8" && Regex.match_simple("sd[a-z]{1}$", reg_split[3])) { | ||
n_bytes_read += ulong.parse(reg_split[6]); | ||
n_bytes_write += ulong.parse(reg_split[10]); | ||
} | ||
|
||
} | ||
} catch (Error e) { | ||
warning("Could not retrieve disk data"); | ||
} | ||
|
||
_bytes_read = (int)((n_bytes_read - _bytes_read_old) * 512); | ||
_bytes_write = (int)((n_bytes_write - _bytes_write_old) * 512); | ||
_bytes_read_old = n_bytes_read; | ||
_bytes_write_old = n_bytes_write; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/*- | ||
* Copyright (c) 2020 Tudor Plugaru (https://github.com/PlugaruT/wingpanel-monitor) | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the | ||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301 USA. | ||
* | ||
* Authored by: Tudor Plugaru <plugaru.tudor@gmail.com> | ||
*/ | ||
|
||
namespace WingpanelMonitor { | ||
public class DiskWidget : Gtk.Grid { | ||
private Gtk.Revealer widget_revealer; | ||
private Gtk.Label read_label; | ||
private Gtk.Label write_label; | ||
|
||
public bool display { | ||
set { widget_revealer.reveal_child = value; } | ||
get { return widget_revealer.get_reveal_child () ; } | ||
} | ||
|
||
construct { | ||
orientation = Gtk.Orientation.HORIZONTAL; | ||
|
||
read_label = new Gtk.Label ("N/A"); | ||
read_label.set_width_chars (8); | ||
read_label.halign = Gtk.Align.START; | ||
var read_label_context = read_label.get_style_context (); | ||
read_label_context.add_class ("small-label"); | ||
read_label_context.add_class ("read"); | ||
|
||
write_label = new Gtk.Label ("N/A"); | ||
write_label.set_width_chars (8); | ||
write_label.halign = Gtk.Align.END; | ||
var write_label_context = write_label.get_style_context (); | ||
write_label_context.add_class ("small-label"); | ||
write_label_context.add_class ("write"); | ||
|
||
var group = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); | ||
group.add (read_label); | ||
group.add (write_label); | ||
|
||
widget_revealer = new Gtk.Revealer (); | ||
widget_revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_RIGHT; | ||
widget_revealer.reveal_child = true; | ||
|
||
widget_revealer.add (group); | ||
|
||
add (widget_revealer); | ||
} | ||
|
||
public void update_label_data (string read_speed, string write_speed) { | ||
read_label.label = "↑" + read_speed; | ||
write_label.label = "↓" + write_speed; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters