Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions po/POTFILES
Original file line number Diff line number Diff line change
@@ -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
Expand Down
39 changes: 6 additions & 33 deletions src/Indicator/Indicator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@

// TODO: Change namespace
public class Monitor.Indicator : Wingpanel.Indicator {
public static Settings settings;

private Widgets.DisplayWidget ? display_widget = null;
private Widgets.PopoverWidget ? popover_widget = null;
private Settings settings;
private DBusClient dbusclient;

static construct {
settings = new Settings ("io.elementary.monitor.settings");
}

construct {
Gtk.IconTheme.get_default ().add_resource_path ("/io/elementary/monitor/icons");
settings = new Settings ("io.elementary.monitor.settings");
this.visible = false;
display_widget = new Widgets.DisplayWidget ();
popover_widget = new Widgets.PopoverWidget ();
Expand All @@ -28,40 +32,9 @@ public class Monitor.Indicator : Wingpanel.Indicator {
dbusclient.monitor_vanished.connect (() => this.visible = false);
dbusclient.monitor_appeared.connect (() => {
this.visible = settings.get_boolean ("indicator-state");
display_widget.cpu_widget.visible = settings.get_boolean ("indicator-cpu-state");
display_widget.cpu_frequency_widget.visible = settings.get_boolean ("indicator-cpu-frequency-state");
display_widget.cpu_temperature_widget.visible = settings.get_boolean ("indicator-cpu-temperature-state");
display_widget.memory_widget.visible = settings.get_boolean ("indicator-memory-state");
display_widget.network_up_widget.visible = settings.get_boolean ("indicator-network-upload-state");
display_widget.network_down_widget.visible = settings.get_boolean ("indicator-network-download-state");
display_widget.gpu_widget.visible = settings.get_boolean ("indicator-gpu-state");
display_widget.gpu_memory_widget.visible = settings.get_boolean ("indicator-gpu-memory-state");
display_widget.gpu_temperature_widget.visible = settings.get_boolean ("indicator-gpu-temperature-state");

});

dbusclient.interface.indicator_state.connect ((state) => this.visible = state);
dbusclient.interface.indicator_cpu_state.connect ((state) => display_widget.cpu_widget.visible = state);
dbusclient.interface.indicator_cpu_frequency_state.connect ((state) => display_widget.cpu_frequency_widget.visible = state);
dbusclient.interface.indicator_cpu_temperature_state.connect ((state) => display_widget.cpu_temperature_widget.visible = state);
dbusclient.interface.indicator_memory_state.connect ((state) => display_widget.memory_widget.visible = state);
dbusclient.interface.indicator_network_up_state.connect ((state) => display_widget.network_up_widget.visible = state);
dbusclient.interface.indicator_network_down_state.connect ((state) => display_widget.network_down_widget.visible = state);
dbusclient.interface.indicator_gpu_state.connect ((state) => display_widget.gpu_widget.visible = state);
dbusclient.interface.indicator_gpu_memory_state.connect ((state) => display_widget.gpu_memory_widget.visible = state);
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);
});

popover_widget.quit_monitor.connect (() => {
try {
Expand Down
84 changes: 73 additions & 11 deletions src/Indicator/Widgets/DisplayWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,83 @@
*/

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");
construct {
valign = Gtk.Align.CENTER;

public IndicatorWidget memory_widget = new IndicatorWidget ("ram-symbolic");
var cpu_widget = new IndicatorWidgetPercentage ("cpu-symbolic");
var cpu_frequency_widget = new IndicatorWidgetFrequency ("cpu-symbolic");
var cpu_temperature_widget = new IndicatorWidgetTemperature ("temperature-sensor-symbolic");

public IndicatorWidget network_up_widget = new IndicatorWidget ("go-up-symbolic");
public IndicatorWidget network_down_widget = new IndicatorWidget ("go-down-symbolic");
var memory_widget = new IndicatorWidgetPercentage ("ram-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");
var network_up_widget = new IndicatorWidgetBandwidth ("go-up-symbolic");
var network_down_widget = new IndicatorWidgetBandwidth ("go-down-symbolic");

construct {
valign = Gtk.Align.CENTER;
var gpu_widget = new IndicatorWidgetPercentage ("gpu-symbolic");
var gpu_memory_widget = new IndicatorWidgetPercentage ("gpu-vram-symbolic");
var gpu_temperature_widget = new IndicatorWidgetTemperature ("temperature-gpu-symbolic");

unowned var dbusclient = DBusClient.get_default ();

dbusclient.monitor_appeared.connect (() => {
cpu_widget.visible = Indicator.settings.get_boolean ("indicator-cpu-state");
cpu_frequency_widget.visible = Indicator.settings.get_boolean ("indicator-cpu-frequency-state");
cpu_temperature_widget.visible = Indicator.settings.get_boolean ("indicator-cpu-temperature-state");
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");
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");
});

dbusclient.interface.indicator_cpu_state.connect ((state) => cpu_widget.visible = state);
dbusclient.interface.indicator_cpu_frequency_state.connect ((state) => cpu_frequency_widget.visible = state);
dbusclient.interface.indicator_cpu_temperature_state.connect ((state) => cpu_temperature_widget.visible = state);
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_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);

dbusclient.interface.update.connect ((sysres) => {
var cpu_percentage = Value (typeof (uint));
cpu_percentage.set_uint (sysres.cpu_percentage);
cpu_widget.update_label (cpu_percentage);

var cpu_frequency = Value (typeof (double));
cpu_frequency.set_double (sysres.cpu_frequency);
cpu_frequency_widget.update_label (cpu_frequency);

var cpu_temperature = Value (typeof (int));
cpu_temperature.set_int ((int) Math.round (sysres.cpu_temperature));
cpu_temperature_widget.update_label (cpu_temperature);

var memory_percentage = Value (typeof (uint));
memory_percentage.set_uint (sysres.memory_percentage);
memory_widget.update_label (memory_percentage);

var network_up = Value (typeof (uint64));
network_up.set_uint64 (sysres.network_up);
network_up_widget.update_label (network_up);

var network_down = Value (typeof (uint64));
network_down.set_uint64 (sysres.network_down);
network_down_widget.update_label (network_down);

var gpu_percentage = Value (typeof (uint));
gpu_percentage.set_uint (sysres.gpu_percentage);
gpu_widget.update_label (gpu_percentage);

var gpu_memory_percentage = Value (typeof (uint));
gpu_memory_percentage.set_uint (sysres.gpu_memory_percentage);
gpu_memory_widget.update_label (gpu_memory_percentage);

var gpu_temperature = Value (typeof (int));
gpu_temperature.set_int ((int) Math.round (sysres.gpu_temperature));
gpu_temperature_widget.update_label (gpu_temperature);
});

add (cpu_widget);
add (cpu_frequency_widget);
Expand Down
47 changes: 11 additions & 36 deletions src/Indicator/Widgets/IndicatorWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
}
}
16 changes: 16 additions & 0 deletions src/Indicator/Widgets/IndicatorWidgetBandwidth.vala
Original file line number Diff line number Diff line change
@@ -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);
}
}
16 changes: 16 additions & 0 deletions src/Indicator/Widgets/IndicatorWidgetFrequency.vala
Original file line number Diff line number Diff line change
@@ -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"));
}
}
26 changes: 26 additions & 0 deletions src/Indicator/Widgets/IndicatorWidgetPercentage.vala
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
16 changes: 16 additions & 0 deletions src/Indicator/Widgets/IndicatorWidgetTemperature.vala
Original file line number Diff line number Diff line change
@@ -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);
}
}
4 changes: 4 additions & 0 deletions src/Indicator/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down