diff --git a/src/Views/SystemView/SystemCPUView.vala b/src/Views/SystemView/SystemCPUView.vala index dd9e6d21..84556836 100644 --- a/src/Views/SystemView/SystemCPUView.vala +++ b/src/Views/SystemView/SystemCPUView.vala @@ -12,45 +12,7 @@ public class Monitor.SystemCPUView : Monitor.WidgetResource { private LabelRoundy cpu_frequency_label; private LabelRoundy cpu_temperature_label; - private Gtk.Grid grid_temperature_info = new Gtk.Grid (); - - private Gee.ArrayList core_label_list; - - construct { - core_label_list = new Gee.ArrayList (); - - cpu_frequency_label = new LabelRoundy (_("Frequency")); - cpu_frequency_label.margin = 6; - cpu_frequency_label.margin_top = 2; - - cpu_temperature_label = new LabelRoundy (_("Temperature")); - cpu_temperature_label.margin = 6; - cpu_temperature_label.margin_top = 2; - - cpu_frequency_chart = new Chart (1); - cpu_frequency_chart.set_serie_color (0, Utils.Colors.get_rgba_color (Utils.Colors.LIME_500)); - cpu_frequency_chart.height_request = -1; - cpu_frequency_chart.config.y_axis.fixed_max = 5.0; - - var grid_frequency_info = new Gtk.Grid (); - grid_frequency_info.attach (cpu_frequency_label, 0, 0, 1, 1); - grid_frequency_info.attach (cpu_frequency_chart, 0, 0, 1, 1); - - grid_temperature_info.attach (cpu_temperature_label, 0, 0, 1, 1); - - - - var smol_charts_container = new Gtk.Grid (); - smol_charts_container.width_request = 200; - smol_charts_container.hexpand = false; - smol_charts_container.halign = Gtk.Align.START; - smol_charts_container.attach (grid_frequency_info, 0, 0, 1, 1); - smol_charts_container.attach (grid_temperature_info, 0, 1, 1, 1); - smol_charts_container.row_spacing = 6; - smol_charts_container.margin_start = 6; - - add_charts_container (smol_charts_container); - } + private Gee.ArrayList core_label_list; public SystemCPUView (CPU _cpu) { cpu = _cpu; @@ -61,33 +23,68 @@ public class Monitor.SystemCPUView : Monitor.WidgetResource { cpu_utilization_chart = new Chart (cpu.core_list.size, MonitorApp.settings.get_boolean ("smooth-lines-state"), 1.0); cpu_utilization_chart.config.y_axis.tick_interval = 100; cpu_utilization_chart.config.y_axis.fixed_max = 100.0 * cpu.core_list.size; - set_main_chart (cpu_utilization_chart); + set_main_chart (cpu_utilization_chart); set_main_chart_overlay (grid_core_labels ()); + } - cpu_temperature_chart = new Chart (1); + construct { + cpu_temperature_chart = new Chart (1) { + height_request = -1 + }; cpu_temperature_chart.set_serie_color (0, Utils.Colors.get_rgba_color (Utils.Colors.LIME_500)); - cpu_temperature_chart.height_request = -1; - grid_temperature_info.attach (cpu_temperature_chart, 0, 0, 1, 1); + core_label_list = new Gee.ArrayList (); + + cpu_frequency_label = new LabelRoundy (_("Frequency")) { + margin_top = 2, + margin_end = 6, + margin_bottom = 6, + margin_start = 6 + }; + + cpu_temperature_label = new LabelRoundy (_("Temperature")) { + margin_top = 2, + margin_end = 6, + margin_bottom = 6, + margin_start = 6 + }; + + cpu_frequency_chart = new Chart (1) { + height_request = -1 + }; + cpu_frequency_chart.set_serie_color (0, Utils.Colors.get_rgba_color (Utils.Colors.LIME_500)); + cpu_frequency_chart.config.y_axis.fixed_max = 5.0; + + var freq_info_overlay = new Gtk.Overlay () { + child = cpu_frequency_chart + }; + freq_info_overlay.add_overlay (cpu_frequency_label); + + var temp_info_overlay = new Gtk.Overlay () { + child = cpu_temperature_chart + }; + temp_info_overlay.add_overlay (cpu_temperature_label); + + var small_charts_box = new Gtk.Box (VERTICAL, 6) { + hexpand = false, + width_request = 200 + }; + small_charts_box.add (freq_info_overlay); + small_charts_box.add (temp_info_overlay); + + add_charts_container (small_charts_box); } public void update () { cpu_frequency_chart.update (0, cpu.frequency); - // int temperature_index = 0; - // foreach (var temperature in cpu.paths_temperatures.values) { - // debug (temperature.input); - // cpu_temperature_chart.update (temperature_index, int.parse (temperature.input) / 1000); - // temperature_index++; - // }] cpu_temperature_chart.update (0, cpu.temperature_mean); cpu_temperature_label.text = ("%.2f %s").printf (cpu.temperature_mean, _("℃")); double cpu_prev_util = 0; for (int i = 0; i < cpu.core_list.size; i++) { - // must reverse to render layers in the right order int reversed_i = cpu.core_list.size - i - 1; @@ -109,12 +106,12 @@ public class Monitor.SystemCPUView : Monitor.WidgetResource { core_label_list[i].get_style_context ().remove_class ("core_badge-strong-warning"); core_label_list[i].get_style_context ().remove_class ("core_badge-critical-warning"); - if (core_percentage > 75.0) { core_label_list[i].get_style_context ().add_class ("core_badge-mild-warning"); core_label_list[i].get_style_context ().remove_class ("core_badge-strong-warning"); core_label_list[i].get_style_context ().remove_class ("core_badge-critical-warning"); } + if (core_percentage > 85.0) { core_label_list[i].get_style_context ().add_class ("core_badge-strong-warning"); core_label_list[i].get_style_context ().remove_class ("core_badge-mild-warning"); @@ -127,6 +124,7 @@ public class Monitor.SystemCPUView : Monitor.WidgetResource { core_label_list[i].get_style_context ().remove_class ("core_badge-strong-warning"); } } + label_vertical_main_metric = ("%d%%").printf (cpu.percentage); cpu_frequency_label.text = ("%.2f %s").printf (cpu.frequency, _("GHz")); } @@ -135,14 +133,18 @@ public class Monitor.SystemCPUView : Monitor.WidgetResource { Gtk.Grid grid = new Gtk.Grid () { column_spacing = 8, row_spacing = 4, - margin = 6 + margin_top = 6, + margin_bottom = 6, + margin_start = 6, + margin_end = 6, }; int column = 0; int row = 0; for (int i = 0; i < cpu.core_list.size; i++) { - var core_label = new Gtk.Label (Utils.NO_DATA); - core_label.set_width_chars (4); + var core_label = new Gtk.Label (Utils.NO_DATA) { + width_chars = 4 + }; core_label.get_style_context ().add_class ("core_badge"); // core_label.set_text (Utils.NO_DATA); core_label_list.add (core_label); diff --git a/src/Widgets/WidgetResource/WidgetResource.vala b/src/Widgets/WidgetResource/WidgetResource.vala index 86020a88..48c54c3b 100644 --- a/src/Widgets/WidgetResource/WidgetResource.vala +++ b/src/Widgets/WidgetResource/WidgetResource.vala @@ -21,7 +21,7 @@ public class Monitor.WidgetResource : Gtk.Box { } } - private Gtk.Box charts_container = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); + private Gtk.Box charts_container = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6); private Gtk.Grid grid_main_chart_container; private Gtk.Grid grid_main_onchart_info_container;