diff --git a/po/POTFILES b/po/POTFILES index 10bab163..4c11296c 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -1,6 +1,7 @@ src/Monitor.vala src/MainWindow.vala src/Utils.vala +src/Indicator/Widgets/IndicatorWidgetFrequency.vala src/Indicator/Widgets/PopoverWidget.vala src/Views/ProcessView/ProcessInfoView/ProcessInfoHeader.vala src/Views/ProcessView/ProcessInfoView/ProcessInfoIOStats.vala diff --git a/src/Indicator/Indicator.vala b/src/Indicator/Indicator.vala index 120e90c7..1ff938a3 100644 --- a/src/Indicator/Indicator.vala +++ b/src/Indicator/Indicator.vala @@ -52,15 +52,41 @@ public class Monitor.Indicator : Wingpanel.Indicator { dbusclient.interface.indicator_gpu_temperature_state.connect ((state) => display_widget.gpu_temperature_widget.visible = state); dbusclient.interface.update.connect ((sysres) => { - display_widget.cpu_widget.state_percentage = sysres.cpu_percentage; - display_widget.cpu_frequency_widget.state_frequency = sysres.cpu_frequency; - display_widget.cpu_temperature_widget.state_temperature = (int) Math.round (sysres.cpu_temperature); - display_widget.memory_widget.state_percentage = sysres.memory_percentage; - display_widget.network_up_widget.state_bandwidth = sysres.network_up; - display_widget.network_down_widget.state_bandwidth = sysres.network_down; - display_widget.gpu_widget.state_percentage = sysres.gpu_percentage; - display_widget.gpu_memory_widget.state_percentage = sysres.gpu_memory_percentage; - display_widget.gpu_temperature_widget.state_temperature = (int) Math.round (sysres.gpu_temperature); + var cpu_percentage = Value (typeof (uint)); + cpu_percentage.set_uint (sysres.cpu_percentage); + display_widget.cpu_widget.update_label (cpu_percentage); + + var cpu_frequency = Value (typeof (double)); + cpu_frequency.set_double (sysres.cpu_frequency); + display_widget.cpu_frequency_widget.update_label (cpu_frequency); + + var cpu_temperature = Value (typeof (int)); + cpu_temperature.set_int ((int) Math.round (sysres.cpu_temperature)); + display_widget.cpu_temperature_widget.update_label (cpu_temperature); + + var memory_percentage = Value (typeof (uint)); + memory_percentage.set_uint (sysres.memory_percentage); + display_widget.memory_widget.update_label (memory_percentage); + + var network_up = Value (typeof (uint64)); + network_up.set_uint64 (sysres.network_up); + display_widget.network_up_widget.update_label (network_up); + + var network_down = Value (typeof (uint64)); + network_down.set_uint64 (sysres.network_down); + display_widget.network_down_widget.update_label (network_down); + + var gpu_percentage = Value (typeof (uint)); + gpu_percentage.set_uint (sysres.gpu_percentage); + display_widget.gpu_widget.update_label (gpu_percentage); + + var gpu_memory_percentage = Value (typeof (uint)); + gpu_memory_percentage.set_uint (sysres.gpu_memory_percentage); + display_widget.gpu_memory_widget.update_label (gpu_memory_percentage); + + var gpu_temperature = Value (typeof (int)); + gpu_temperature.set_int ((int) Math.round (sysres.gpu_temperature)); + display_widget.gpu_temperature_widget.update_label (gpu_temperature); }); popover_widget.quit_monitor.connect (() => { diff --git a/src/Indicator/Widgets/DisplayWidget.vala b/src/Indicator/Widgets/DisplayWidget.vala index beeb58c0..37a51354 100644 --- a/src/Indicator/Widgets/DisplayWidget.vala +++ b/src/Indicator/Widgets/DisplayWidget.vala @@ -4,18 +4,18 @@ */ public class Monitor.Widgets.DisplayWidget : Gtk.Grid { - public IndicatorWidget cpu_widget = new IndicatorWidget ("cpu-symbolic"); - public IndicatorWidget cpu_frequency_widget = new IndicatorWidget ("cpu-symbolic"); - public IndicatorWidget cpu_temperature_widget = new IndicatorWidget ("temperature-sensor-symbolic"); + public IndicatorWidgetPercentage cpu_widget = new IndicatorWidgetPercentage ("cpu-symbolic"); + public IndicatorWidgetFrequency cpu_frequency_widget = new IndicatorWidgetFrequency ("cpu-symbolic"); + public IndicatorWidgetTemperature cpu_temperature_widget = new IndicatorWidgetTemperature ("temperature-sensor-symbolic"); - public IndicatorWidget memory_widget = new IndicatorWidget ("ram-symbolic"); + public IndicatorWidgetPercentage memory_widget = new IndicatorWidgetPercentage ("ram-symbolic"); - public IndicatorWidget network_up_widget = new IndicatorWidget ("go-up-symbolic"); - public IndicatorWidget network_down_widget = new IndicatorWidget ("go-down-symbolic"); + public IndicatorWidgetBandwidth network_up_widget = new IndicatorWidgetBandwidth ("go-up-symbolic"); + public IndicatorWidgetBandwidth network_down_widget = new IndicatorWidgetBandwidth ("go-down-symbolic"); - public IndicatorWidget gpu_widget = new IndicatorWidget ("gpu-symbolic"); - public IndicatorWidget gpu_memory_widget = new IndicatorWidget ("gpu-vram-symbolic"); - public IndicatorWidget gpu_temperature_widget = new IndicatorWidget ("temperature-gpu-symbolic"); + public IndicatorWidgetPercentage gpu_widget = new IndicatorWidgetPercentage ("gpu-symbolic"); + public IndicatorWidgetPercentage gpu_memory_widget = new IndicatorWidgetPercentage ("gpu-vram-symbolic"); + public IndicatorWidgetTemperature gpu_temperature_widget = new IndicatorWidgetTemperature ("temperature-gpu-symbolic"); construct { valign = Gtk.Align.CENTER; diff --git a/src/Indicator/Widgets/IndicatorWidget.vala b/src/Indicator/Widgets/IndicatorWidget.vala index 74f3a692..c8ff682b 100644 --- a/src/Indicator/Widgets/IndicatorWidget.vala +++ b/src/Indicator/Widgets/IndicatorWidget.vala @@ -7,40 +7,7 @@ public class Monitor.IndicatorWidget : Gtk.Box { public string icon_name { get; construct; } - public uint state_percentage { - set { - label.label = "%u%%".printf (value); - label.get_style_context ().remove_class ("monitor-indicator-label-warning"); - label.get_style_context ().remove_class ("monitor-indicator-label-critical"); - - if (value > 80) { - label.get_style_context ().add_class ("monitor-indicator-label-warning"); - } - if (value > 90) { - label.get_style_context ().add_class ("monitor-indicator-label-critical"); - } - } - } - - public int state_temperature { - set { - label.label = "%i℃".printf (value); - } - } - - public double state_frequency { - set { - label.label = ("%.2f %s").printf (value, _("GHz")); - } - } - - public uint64 state_bandwidth { - set { - label.label = format_size (value); - } - } - - private Gtk.Label label = new Gtk.Label (Utils.NOT_AVAILABLE); + protected Gtk.Label label; public IndicatorWidget (string icon_name) { Object ( @@ -52,9 +19,17 @@ public class Monitor.IndicatorWidget : Gtk.Box { construct { var icon = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.SMALL_TOOLBAR); - label.margin = 2; - label.width_chars = 4; + + label = new Gtk.Label (Utils.NOT_AVAILABLE) { + margin = 2, + width_chars = 4, + }; + pack_start (icon); pack_start (label); } + + public virtual void update_label (Value value) { + // NOP; should be overridden by child classes + } } diff --git a/src/Indicator/Widgets/IndicatorWidgetBandwidth.vala b/src/Indicator/Widgets/IndicatorWidgetBandwidth.vala new file mode 100644 index 00000000..e58b3a2f --- /dev/null +++ b/src/Indicator/Widgets/IndicatorWidgetBandwidth.vala @@ -0,0 +1,16 @@ +/* + * SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io) + */ + +public class Monitor.IndicatorWidgetBandwidth : Monitor.IndicatorWidget { + public IndicatorWidgetBandwidth (string icon_name) { + base (icon_name); + } + + public override void update_label (Value value) { + uint64 bandwidth = value.get_uint64 (); + + label.label = format_size (bandwidth); + } +} diff --git a/src/Indicator/Widgets/IndicatorWidgetFrequency.vala b/src/Indicator/Widgets/IndicatorWidgetFrequency.vala new file mode 100644 index 00000000..a9b91f13 --- /dev/null +++ b/src/Indicator/Widgets/IndicatorWidgetFrequency.vala @@ -0,0 +1,16 @@ +/* + * SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io) + */ + +public class Monitor.IndicatorWidgetFrequency : Monitor.IndicatorWidget { + public IndicatorWidgetFrequency (string icon_name) { + base (icon_name); + } + + public override void update_label (Value value) { + double frequency = value.get_double (); + + label.label = ("%.2f %s").printf (frequency, _("GHz")); + } +} diff --git a/src/Indicator/Widgets/IndicatorWidgetPercentage.vala b/src/Indicator/Widgets/IndicatorWidgetPercentage.vala new file mode 100644 index 00000000..c4d3331f --- /dev/null +++ b/src/Indicator/Widgets/IndicatorWidgetPercentage.vala @@ -0,0 +1,26 @@ +/* + * SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io) + */ + +public class Monitor.IndicatorWidgetPercentage : Monitor.IndicatorWidget { + public IndicatorWidgetPercentage (string icon_name) { + base (icon_name); + } + + public override void update_label (Value value) { + uint percentage = value.get_uint (); + + label.label = "%u%%".printf (percentage); + label.get_style_context ().remove_class ("monitor-indicator-label-warning"); + label.get_style_context ().remove_class ("monitor-indicator-label-critical"); + + if (percentage > 80) { + label.get_style_context ().add_class ("monitor-indicator-label-warning"); + } + + if (percentage > 90) { + label.get_style_context ().add_class ("monitor-indicator-label-critical"); + } + } +} diff --git a/src/Indicator/Widgets/IndicatorWidgetTemperature.vala b/src/Indicator/Widgets/IndicatorWidgetTemperature.vala new file mode 100644 index 00000000..4580559f --- /dev/null +++ b/src/Indicator/Widgets/IndicatorWidgetTemperature.vala @@ -0,0 +1,16 @@ +/* + * SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io) + */ + +public class Monitor.IndicatorWidgetTemperature : Monitor.IndicatorWidget { + public IndicatorWidgetTemperature (string icon_name) { + base (icon_name); + } + + public override void update_label (Value value) { + int temperature = value.get_int (); + + label.label = "%i℃".printf (temperature); + } +} diff --git a/src/Indicator/meson.build b/src/Indicator/meson.build index 95c64f33..d31d061b 100644 --- a/src/Indicator/meson.build +++ b/src/Indicator/meson.build @@ -3,6 +3,10 @@ source_indicator_files = [ 'Services/DBusClient.vala', 'Widgets/DisplayWidget.vala', 'Widgets/IndicatorWidget.vala', + 'Widgets/IndicatorWidgetPercentage.vala', + 'Widgets/IndicatorWidgetTemperature.vala', + 'Widgets/IndicatorWidgetFrequency.vala', + 'Widgets/IndicatorWidgetBandwidth.vala', 'Widgets/PopoverWidget.vala', meson.project_source_root() / 'src' / 'Resources/ResourcesSerialized.vala',