Skip to content

Commit

Permalink
Merge pull request elementary#182 from stsdc/dev
Browse files Browse the repository at this point in the history
Adds basic info in the System tab
  • Loading branch information
Stanisław authored Jul 18, 2020
2 parents f25b3eb + b97706d commit 7398b55
Show file tree
Hide file tree
Showing 20 changed files with 384 additions and 104 deletions.
5 changes: 2 additions & 3 deletions data/com.github.stsdc.monitor.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
<url type="help">https://github.com/stsdc/monitor/issues</url>

<releases>
<release version="0.7.3" date="2020-06-22">
<release version="0.8.0" date="2020-07-19">
​ <description>
​ <ul>
<li>Small bugfix</li>
<li>Added tooltips (Ryo Nakano)</li>
<li>System resources tab</li>
</ul>
​ </description>
​ </release>
Expand Down
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
com.github.stsdc.monitor (0.8.0) bionic; urgency=low

* System resources tab

-- Stanisław Dac <[email protected]> Sun, 19 Jul 2020 00:30:43 +0200

com.github.stsdc.monitor (0.7.3) bionic; urgency=low

* Added tooltips to process state label (Ryo Nakano)
Expand Down
12 changes: 10 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project('com.github.stsdc.monitor', 'vala', 'c', version: '0.7.3')
project('com.github.stsdc.monitor', 'vala', 'c', version: '0.8.0')

# these are Meson modules
gnome = import('gnome')
Expand Down Expand Up @@ -66,6 +66,11 @@ executable(
'src/Views/ProcessView/ProcessInfoView/ProcessInfoView.vala',
'src/Views/ProcessView/ProcessTreeView/CPUProcessTreeView.vala',

'src/Views/SystemView/SystemView.vala',
'src/Views/SystemView/SystemCPUChart.vala',
'src/Views/SystemView/SystemCPUView.vala',
'src/Views/SystemView/SystemMemoryView.vala',

# Widgets related only to ProcessInfoView
'src/Views/ProcessView/ProcessInfoView/Preventor.vala',
'src/Views/ProcessView/ProcessInfoView/RoundyLabel.vala',
Expand Down Expand Up @@ -93,8 +98,10 @@ executable(

'src/Services/Shortcuts.vala',
'src/Services/DBusServer.vala',
'src/Services/Updater.vala',

# Resources
'src/Resources/Resources.vala',
'src/Resources/ResourcesSerialized.vala',
'src/Resources/CPU.vala',
'src/Resources/Core.vala',
'src/Resources/Memory.vala',
Expand Down Expand Up @@ -125,6 +132,7 @@ shared_module(
'monitor',
'src/Indicator/Indicator.vala',
'src/Utils.vala',
'src/Resources/ResourcesSerialized.vala',

'src/Indicator/Widgets/DisplayWidget.vala',
'src/Indicator/Widgets/PopoverWidget.vala',
Expand Down
2 changes: 1 addition & 1 deletion src/Indicator/Services/DBusClient.vala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
public interface Monitor.DBusClientInterface : Object {
public abstract void quit_monitor () throws Error;
public abstract void show_monitor () throws Error;
public signal void update (Utils.SystemResources data);
public signal void update (ResourcesSerialized data);
public signal void indicator_state (bool state);
}

Expand Down
46 changes: 23 additions & 23 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
// application reference
private Shortcuts shortcuts;

private Resources resources;

// Widgets
public Headerbar headerbar;
// private Gtk.Button process_info_button;

public ProcessView process_view;
public SystemView system_view;

private Statusbar statusbar;

public DBusServer dbusserver;

private Updater updater;


// Constructs a main window
public MainWindow (MonitorApp app) {
Expand All @@ -23,47 +24,46 @@

get_style_context ().add_class ("rounded");

resources = new Resources ();

// button_box.get_style_context ().add_class (Gtk.STYLE_CLASS_LINKED);

// setup process info button
// process_info_button = new Gtk.Button.from_icon_name ("dialog-information-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
// process_info_button.get_style_context ().remove_class ("image-button");
// button_box.add (process_info_button);

// setup kill process button

process_view = new ProcessView ();
system_view = new SystemView (resources);

// TODO: Granite.Widgets.ModeButton to switch between view modes
Gtk.Stack stack = new Gtk.Stack ();
stack.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT_RIGHT);
stack.add_titled (process_view, "process_view", "Processes");
stack.add_titled (system_view, "system_view", "System");

// process_manager = new ProcessManager();
process_view = new ProcessView ();
Gtk.StackSwitcher stack_switcher = new Gtk.StackSwitcher ();
stack_switcher.set_stack(stack);

headerbar = new Headerbar (this);
headerbar.set_custom_title (stack_switcher);
set_titlebar (headerbar);

statusbar = new Statusbar ();

var main_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
main_box.pack_start (process_view, true, true, 0);
main_box.pack_start (stack, true, true, 0);
main_box.pack_start (statusbar, false, true, 0);
this.add (main_box);

updater = Updater.get_default ();
dbusserver = DBusServer.get_default ();



updater.update.connect ((sysres) => {
statusbar.update (sysres);
dbusserver.update (sysres);
dbusserver.indicator_state (MonitorApp.settings.get_boolean ("indicator-state"));
});

// updating processes every 2 seconds
Timeout.add_seconds (2, () => {
resources.update();
var res = resources.serialize ();
statusbar.update (res);
dbusserver.update (res);
process_view.update();
system_view.update();
dbusserver.indicator_state (MonitorApp.settings.get_boolean ("indicator-state"));
return true;
});


dbusserver.quit.connect (() => app.quit());
dbusserver.show.connect (() => {
this.deiconify ();
Expand Down
21 changes: 18 additions & 3 deletions src/Resources/CPU.vala
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ public class Monitor.CPU : Object {

public int percentage {
get {
update_percentage ();
return (int)(Math.round (load * 100));
}
}

public Gee.ArrayList<Core> core_list;

private double _frequency;
public double frequency {
get {
update_frequency ();
// Convert kH to GHz
return (double)(_frequency / 1000000);
}
Expand All @@ -24,9 +24,24 @@ public class Monitor.CPU : Object {
construct {
last_used = 0;
last_total = 0;

core_list = new Gee.ArrayList<Core> ();


debug ("Number of cores: %d", (int) get_num_processors ());
for (int i = 0; i < (int) get_num_processors (); i++) {
var core = new Core(i);
core_list.add (core);
}
}

public CPU () {
public void update () {
update_percentage();
update_frequency();

foreach (var core in core_list) {
core.update();
}
}

private void update_percentage () {
Expand Down
6 changes: 4 additions & 2 deletions src/Resources/Core.vala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Monitor {

public int number { get; set; }
public float percentage_used {
get { update_percentage_used (); return _percentage_used; }
get { return _percentage_used; }
}

public Core (int number) {
Expand All @@ -17,7 +17,7 @@ namespace Monitor {
last_total = 0;
}

private void update_percentage_used () {
public void update () {
GTop.Cpu cpu;
GTop.get_cpu (out cpu);

Expand All @@ -31,6 +31,8 @@ namespace Monitor {

last_used = (float) used;
last_total = (float) cpu.xcpu_total[number];

// debug("Core %d: %f%%", number, _percentage_used);
}
}
}
16 changes: 12 additions & 4 deletions src/Resources/Memory.vala
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ namespace Monitor {
public class Memory : Object {
public double total;
public double used;
public double shared;
public double buffer;
public double cached;
public double locked;

private GTop.Memory mem;

public int percentage {
get {
update ();
return (int) (Math.round ((used / total) * 100));
}
}
Expand All @@ -20,10 +23,15 @@ namespace Monitor {

public Memory () { }

private void update () {
public void update () {
GTop.get_mem (out mem);
total = (double) (mem.total / 1024 / 1024) / 1000;
used = (double) (mem.user / 1024 / 1024) / 1000;
total = (double) (mem.total );
used = (double) mem.user;
shared = (double) (mem.shared);
buffer = (double) (mem.buffer);
cached = (double) (mem.cached);
locked = (double) (mem.locked);

}
}
}
29 changes: 29 additions & 0 deletions src/Resources/Resources.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
public class Monitor.Resources : Object {
public CPU cpu;
public Memory memory;
public Swap swap;

construct {
memory = new Memory ();
cpu = new CPU ();
swap = new Swap ();
}

public void update() {
cpu.update();
memory.update();
}
public ResourcesSerialized serialize () {
return ResourcesSerialized () {
cpu_percentage = cpu.percentage,
cpu_frequency = cpu.frequency,
memory_percentage = memory.percentage,
memory_used = memory.used,
memory_total = memory.total,
swap_percentage = swap.percentage,
swap_used = swap.used,
swap_total = swap.total
};
}

}
10 changes: 10 additions & 0 deletions src/Resources/ResourcesSerialized.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public struct ResourcesSerialized {
public int cpu_percentage;
public double cpu_frequency;
public int memory_percentage;
public double memory_used;
public double memory_total;
public int swap_percentage;
public double swap_used;
public double swap_total;
}
2 changes: 1 addition & 1 deletion src/Services/DBusServer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Monitor.DBusServer : Object {
return instance.once (() => { return new DBusServer (); });
}

public signal void update (Utils.SystemResources data);
public signal void update (ResourcesSerialized data);
public signal void indicator_state (bool state);
public signal void quit ();
public signal void show ();
Expand Down
41 changes: 0 additions & 41 deletions src/Services/Updater.vala

This file was deleted.

Loading

0 comments on commit 7398b55

Please sign in to comment.