Skip to content

Commit

Permalink
Adds GPU percentage in the Indicator #326
Browse files Browse the repository at this point in the history
  • Loading branch information
stsdc committed Jan 21, 2023
1 parent d191af7 commit 41e7a0e
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 8 deletions.
5 changes: 5 additions & 0 deletions data/com.github.stsdc.monitor.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
<summary>To show network down bandwith in Monitor Indicator or not</summary>
<description>To show network down bandwith in Monitor Indicator or not</description>
</key>
<key type='b' name="indicator-gpu-state">
<default>false</default>
<summary>To show GPU used percentage in Monitor Indicator or not</summary>
<description>To show GPU used percentage in Monitor Indicator or not</description>
</key>
<key type='b' name="smooth-lines-state">
<default>true</default>
<summary>To enable smooth lines in charts</summary>
Expand Down
157 changes: 157 additions & 0 deletions data/icons/gpu-symbolic.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions data/icons/icons.indicator.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<gresource prefix="/com/github/stsdc/monitor/icons">
<file compressed="true" preprocess="xml-stripblanks">cpu-symbolic.svg</file>
<file compressed="true" preprocess="xml-stripblanks">ram-symbolic.svg</file>
<file compressed="true" preprocess="xml-stripblanks">gpu-symbolic.svg</file>
<file compressed="true" preprocess="xml-stripblanks">swap-symbolic.svg</file>
<file compressed="true" preprocess="xml-stripblanks">file-deleted-symbolic.svg</file>
<file compressed="true" preprocess="xml-stripblanks">temperature-sensor-symbolic.svg</file>
Expand Down
3 changes: 3 additions & 0 deletions src/Indicator/Indicator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Monitor.Indicator : Wingpanel.Indicator {
display_widget.temperature_widget.visible = settings.get_boolean ("indicator-temperature-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");

});

Expand All @@ -37,13 +38,15 @@ public class Monitor.Indicator : Wingpanel.Indicator {
dbusclient.interface.indicator_temperature_state.connect ((state) => display_widget.temperature_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.update.connect ((sysres) => {
display_widget.cpu_widget.state_percentage = sysres.cpu_percentage;
display_widget.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_bandwith = sysres.network_up;
display_widget.network_down_widget.state_bandwith = sysres.network_down;
display_widget.gpu_widget.state_percentage = sysres.gpu_percentage;
});

popover_widget.quit_monitor.connect (() => {
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 @@ -9,6 +9,7 @@ public interface Monitor.DBusClientInterface : Object {
public signal void indicator_temperature_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_gpu_state (bool state);

}

Expand Down
3 changes: 3 additions & 0 deletions src/Indicator/Widgets/DisplayWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ public class Monitor.Widgets.DisplayWidget : Gtk.Grid {
public IndicatorWidget network_up_widget = new IndicatorWidget ("go-up-symbolic");
public IndicatorWidget network_down_widget = new IndicatorWidget ("go-down-symbolic");

public IndicatorWidget gpu_widget = new IndicatorWidget ("gpu-symbolic");

construct {
valign = Gtk.Align.CENTER;

add (cpu_widget);
add (memory_widget);
add (gpu_widget);
add (temperature_widget);
add (network_up_widget);
add (network_down_widget);
Expand Down
5 changes: 3 additions & 2 deletions src/Resources/Resources.vala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class Monitor.Resources : Object {
gpu.session_manager = session_manager;
gpu.hwmon_temperatures = hwmon_path_parser.gpu_paths_parser.temperatures;
} else {
warning ("GPU: Unknown");
warning ("GPU: Unknown: %s", gpu_name);
}

cpu.temperatures = hwmon_path_parser.cpu_paths_parser.temperatures;
Expand Down Expand Up @@ -85,7 +85,8 @@ public class Monitor.Resources : Object {
swap_used = swap.used,
swap_total = swap.total,
network_up = network.bytes_out,
network_down = network.bytes_in
network_down = network.bytes_in,
gpu_percentage = gpu.percentage
};
}
}
1 change: 1 addition & 0 deletions src/Resources/ResourcesSerialized.vala
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public struct ResourcesSerialized {
public double swap_total;
public int network_up;
public int network_down;
public int gpu_percentage;
}
1 change: 1 addition & 0 deletions src/Services/DBusServer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class Monitor.DBusServer : Object {
public signal void indicator_temperature_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_gpu_state (bool state);
public signal void quit ();
public signal void show ();

Expand Down
32 changes: 26 additions & 6 deletions src/Views/PreferencesView/PreferencesIndicatorPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,36 @@
dbusserver.indicator_network_down_state (network_download_switch.state);
});

var gpu_label = new Gtk.Label (_("Display GPU percentage"));
gpu_label.halign = Gtk.Align.START;
gpu_label.xalign = 1;

var gpu_percentage_switch = new Gtk.Switch ();
gpu_percentage_switch.halign = Gtk.Align.END;
gpu_percentage_switch.state = MonitorApp.settings.get_boolean ("indicator-gpu-state");
gpu_percentage_switch.notify["active"].connect (() => {
MonitorApp.settings.set_boolean ("indicator-gpu-state", gpu_percentage_switch.state);
dbusserver.indicator_gpu_state (gpu_percentage_switch.state);
});

content_area.attach (cpu_label, 0, 0, 1, 1);
content_area.attach (cpu_percentage_switch, 1, 0, 1, 1);

content_area.attach (memory_label, 0, 1, 1, 1);
content_area.attach (memory_percentage_switch, 1, 1, 1, 1);
content_area.attach (temperature_label, 0, 2, 1, 1);
content_area.attach (temperature_switch, 1, 2, 1, 1);
content_area.attach (network_upload_label, 0, 3, 1, 1);
content_area.attach (network_upload_switch, 1, 3, 1, 1);
content_area.attach (network_download_label, 0, 4, 1, 1);
content_area.attach (network_download_switch, 1, 4, 1, 1);

content_area.attach (gpu_label, 0, 2, 1, 1);
content_area.attach (gpu_percentage_switch, 1, 2, 1, 1);

content_area.attach (temperature_label, 0, 3, 1, 1);
content_area.attach (temperature_switch, 1, 3, 1, 1);

content_area.attach (network_upload_label, 0, 4, 1, 1);
content_area.attach (network_upload_switch, 1, 4, 1, 1);

content_area.attach (network_download_label, 0, 5, 1, 1);
content_area.attach (network_download_switch, 1, 5, 1, 1);

update_status ();

status_switch.notify["active"].connect (update_status);
Expand Down

0 comments on commit 41e7a0e

Please sign in to comment.