Skip to content
5 changes: 5 additions & 0 deletions data/io.elementary.monitor.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
<summary>To show network down bandwidth in Monitor Indicator or not</summary>
<description>To show network down bandwidth in Monitor Indicator or not</description>
</key>
<key type='b' name="indicator-network-use-bits-state">
<default>false</default>
<summary>To show network bandwidth in in bits instead of bytes per second</summary>
<description>To show network bandwidth in in bits instead of bytes per second</description>
</key>
<key type='b' name="indicator-gpu-state">
<default>false</default>
<summary>To show GPU used percentage in Monitor Indicator or not</summary>
Expand Down
1 change: 1 addition & 0 deletions src/Indicator/Services/DBusClient.vala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public interface Monitor.DBusClientInterface : Object {
public signal void indicator_memory_state (bool state);
public signal void indicator_network_up_state (bool state);
public signal void indicator_network_down_state (bool state);
public signal void indicator_network_use_bits_state (bool state);
public signal void indicator_gpu_state (bool state);
public signal void indicator_gpu_memory_state (bool state);
public signal void indicator_gpu_temperature_state (bool state);
Expand Down
9 changes: 8 additions & 1 deletion src/Indicator/Widgets/DisplayWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class Monitor.Widgets.DisplayWidget : Gtk.Box {
memory_widget.visible = Indicator.settings.get_boolean ("indicator-memory-state");
network_up_widget.visible = Indicator.settings.get_boolean ("indicator-network-upload-state");
network_down_widget.visible = Indicator.settings.get_boolean ("indicator-network-download-state");
bool use_bits = Indicator.settings.get_boolean ("indicator-network-use-bits-state");
network_up_widget.use_bits = use_bits;
network_down_widget.use_bits = use_bits;
gpu_widget.visible = Indicator.settings.get_boolean ("indicator-gpu-state");
gpu_memory_widget.visible = Indicator.settings.get_boolean ("indicator-gpu-memory-state");
gpu_temperature_widget.visible = Indicator.settings.get_boolean ("indicator-gpu-temperature-state");
Expand All @@ -40,6 +43,10 @@ public class Monitor.Widgets.DisplayWidget : Gtk.Box {
dbusclient.interface.indicator_memory_state.connect ((state) => memory_widget.visible = state);
dbusclient.interface.indicator_network_up_state.connect ((state) => network_up_widget.visible = state);
dbusclient.interface.indicator_network_down_state.connect ((state) => network_down_widget.visible = state);
dbusclient.interface.indicator_network_use_bits_state.connect ((state) => {
network_up_widget.use_bits = state;
network_down_widget.use_bits = state;
});
dbusclient.interface.indicator_gpu_state.connect ((state) => gpu_widget.visible = state);
dbusclient.interface.indicator_gpu_memory_state.connect ((state) => gpu_memory_widget.visible = state);
dbusclient.interface.indicator_gpu_temperature_state.connect ((state) => gpu_temperature_widget.visible = state);
Expand Down Expand Up @@ -89,7 +96,7 @@ public class Monitor.Widgets.DisplayWidget : Gtk.Box {
append (gpu_widget);
append (gpu_memory_widget);
append (gpu_temperature_widget);
append (network_up_widget);
append (network_down_widget);
append (network_up_widget);
}
}
8 changes: 7 additions & 1 deletion src/Indicator/Widgets/IndicatorWidgetBandwidth.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
*/

public class Monitor.IndicatorWidgetBandwidth : Monitor.IndicatorWidget {
public bool use_bits = false;

public IndicatorWidgetBandwidth (string icon_name) {
base (icon_name);
}

construct {
label.width_chars = 8;
}

public override void update_label (Value value) {
uint64 bandwidth = value.get_uint64 ();

label.label = format_size (bandwidth);
label.label = Utils.Strings.format_network_speed (bandwidth, use_bits);
}
}
6 changes: 5 additions & 1 deletion src/Indicator/Widgets/IndicatorWidgetFrequency.vala
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ public class Monitor.IndicatorWidgetFrequency : Monitor.IndicatorWidget {
base (icon_name);
}

construct {
label.width_chars = 8;
}

public override void update_label (Value value) {
double frequency = value.get_double ();

label.label = ("%.2f %s").printf (frequency, _("GHz"));
label.label = Utils.Strings.format_frequency (frequency);
}
}
4 changes: 2 additions & 2 deletions src/Resources/CPU.vala
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public class Monitor.CPU : Object {
private double _frequency;
public double frequency {
get {
// Convert kHz to GHz
return (double) (_frequency / 1000000);
// Convert kHz to MHz
return (double) (_frequency / 1000);
}
}
public double temperature_mean {
Expand Down
1 change: 1 addition & 0 deletions src/Services/DBusServer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Monitor.DBusServer : Object {
public signal void indicator_memory_state (bool state);
public signal void indicator_network_up_state (bool state);
public signal void indicator_network_down_state (bool state);
public signal void indicator_network_use_bits_state (bool state);
public signal void indicator_gpu_state (bool state);
public signal void indicator_gpu_memory_state (bool state);
public signal void indicator_gpu_temperature_state (bool state);
Expand Down
23 changes: 23 additions & 0 deletions src/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@ public class Monitor.Utils.Strings {
return pretty;
}

public static string format_network_speed (uint64 bandwidth, bool use_bits = false) {
const int SCALE = 1000;
bandwidth = bandwidth * (use_bits ? 8 : 1);
string unit_suffix = use_bits ? "bps" : "Bps";
string[] units = { "", "K", "M", "G", "T" };

int unit_index = 0;

while (bandwidth >= SCALE && unit_index < units.length - 1) {
bandwidth /= SCALE;
unit_index++;
}

return "%llu %s%s".printf (bandwidth, units[unit_index], unit_suffix);
}

public static string format_frequency (double mhz) {
if (mhz >= 1000.0) {
return "%.2f %s".printf (mhz / 1000.0, _("GHz"));
}

return "%.0f %s".printf (mhz, _("MHz"));
}
}

public class Monitor.Utils.Colors : Object {
Expand Down
9 changes: 8 additions & 1 deletion src/Views/PreferencesView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public class Monitor.PreferencesView : Granite.Bin {
dbusserver.indicator_network_down_state (network_download_check.active);
});

var network_use_bits_check = new Gtk.CheckButton.with_label (_("Network use bits"));
network_use_bits_check.toggled.connect (() => {
dbusserver.indicator_network_use_bits_state (network_use_bits_check.active);
});

var gpu_check = new Gtk.CheckButton.with_label (_("GPU percentage"));
gpu_check.toggled.connect (() => {
dbusserver.indicator_gpu_state (gpu_check.active);
Expand Down Expand Up @@ -122,8 +127,9 @@ public class Monitor.PreferencesView : Granite.Bin {
indicator_options_box.append (gpu_memory_check);
indicator_options_box.append (gpu_temp_check);
indicator_options_box.append (new Gtk.Separator (HORIZONTAL));
indicator_options_box.append (network_upload_check);
indicator_options_box.append (network_download_check);
indicator_options_box.append (network_upload_check);
indicator_options_box.append (network_use_bits_check);

var indicator_options_revealer = new Gtk.Revealer () {
child = indicator_options_box
Expand Down Expand Up @@ -158,5 +164,6 @@ public class Monitor.PreferencesView : Granite.Bin {
settings.bind ("indicator-gpu-state", gpu_check, "active", DEFAULT);
settings.bind ("indicator-network-download-state", network_download_check, "active", DEFAULT);
settings.bind ("indicator-network-upload-state", network_upload_check, "active", DEFAULT);
settings.bind ("indicator-network-use-bits-state", network_use_bits_check, "active", DEFAULT);
}
}
2 changes: 1 addition & 1 deletion src/Views/SystemView/SystemCPUView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public class Monitor.SystemCPUView : Monitor.WidgetResource {
}

main_metric_value = ("%d%%").printf (cpu.percentage);
cpu_frequency_label.text = ("%.2f %s").printf (cpu.frequency, _("GHz"));
cpu_frequency_label.text = Utils.Strings.format_frequency (cpu.frequency);
}

private Gtk.Grid grid_core_labels () {
Expand Down
6 changes: 4 additions & 2 deletions src/Views/SystemView/SystemNetworkView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class Monitor.SystemNetworkView : Gtk.Grid {
private LabelRoundy network_upload_label;
private LabelRoundy network_download_label;

public bool use_bits = false;

construct {
margin_top = 12;
margin_bottom = 12;
Expand Down Expand Up @@ -60,8 +62,8 @@ public class Monitor.SystemNetworkView : Gtk.Grid {
double up_bytes = network.bytes_out;
double down_bytes = network.bytes_in;
if (up_bytes >= 0 && down_bytes >= 0) {
network_download_label.text = ("%s/s").printf (format_size ((uint64) down_bytes, IEC_UNITS));
network_upload_label.text = ("%s/s").printf (format_size ((uint64) up_bytes, IEC_UNITS));
network_download_label.text = Utils.Strings.format_network_speed ((uint64) down_bytes, use_bits);
network_upload_label.text = Utils.Strings.format_network_speed ((uint64) up_bytes, use_bits);
network_chart.update (0, up_bytes);
network_chart.update (1, down_bytes);
}
Expand Down
7 changes: 7 additions & 0 deletions src/Views/SystemView/SystemView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public class Monitor.SystemView : Gtk.Box {
}

append (scrolled_window);

unowned var dbusclient = DBusClient.get_default ();
dbusclient.interface.indicator_network_use_bits_state.connect ((state) => {
network_view.use_bits = state;
});
Settings settings = new Settings ("io.elementary.monitor.settings");
network_view.use_bits = settings.get_boolean ("indicator-network-use-bits-state");
}

public void update () {
Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ source_app_files = [
# Services
'Services/DBusServer.vala',
'Services/Appearance.vala',
'Indicator/Services/DBusClient.vala',

# Resources
'Resources/Resources.vala',
Expand Down
Loading