aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOndrej Čerman2019-06-19 00:29:40 +0200
committerOndrej Čerman2019-06-19 00:29:40 +0200
commit05d2d2c220423283c0fe5721b314d625496364d1 (patch)
treed1e005ba8a342d85d5ee848c9cc44d084a19474a
parentb1dd2f531524d64357775b6dbcfde9474eb740c4 (diff)
Added option to clear min/max values
-rw-r--r--src/gui.c40
-rw-r--r--src/include/msr.h1
-rw-r--r--src/include/zenmonitor.h2
-rw-r--r--src/include/zenpower.h1
-rw-r--r--src/ss/msr.c10
-rw-r--r--src/ss/zenpower.c9
-rw-r--r--src/zenmonitor.c16
7 files changed, 64 insertions, 15 deletions
diff --git a/src/gui.c b/src/gui.c
index 0b16281..1bd9dff 100644
--- a/src/gui.c
+++ b/src/gui.c
@@ -158,16 +158,28 @@ static void about_btn_clicked(GtkButton *button, gpointer user_data) {
gtk_widget_destroy(dialog);
}
+static void clear_btn_clicked(GtkButton *button, gpointer user_data) {
+ SensorSource *source;
+ const SensorInit *sensorData;
+
+ for (source = sensor_sources; source->drv; source++) {
+ if (!source->enabled)
+ continue;
+
+ source->func_clear_minmax();
+ }
+}
+
int start_gui (SensorSource *ss) {
- GtkWidget *button;
+ GtkWidget *about_btn;
+ GtkWidget *clear_btn;
+ GtkWidget *box;
GtkWidget *header;
GtkWidget *treeview;
GtkWidget *sw;
GtkWidget *vbox;
GtkWidget *dialog;
- GtkWidget *image;
- GIcon *icon;
-
+
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 480, 350);
@@ -179,14 +191,20 @@ int start_gui (SensorSource *ss) {
gtk_header_bar_set_subtitle(GTK_HEADER_BAR (header), cpu_model());
gtk_window_set_titlebar (GTK_WINDOW (window), header);
- button = gtk_button_new();
- icon = g_themed_icon_new("dialog-information");
- image = gtk_image_new_from_gicon(icon, GTK_ICON_SIZE_BUTTON);
- g_object_unref(icon);
- gtk_container_add(GTK_CONTAINER (button), image);
- gtk_header_bar_pack_start(GTK_HEADER_BAR (header), button);
- g_signal_connect (button, "clicked", G_CALLBACK (about_btn_clicked), NULL);
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ gtk_style_context_add_class (gtk_widget_get_style_context (box), "linked");
+
+ about_btn = gtk_button_new();
+ gtk_container_add(GTK_CONTAINER(about_btn), gtk_image_new_from_icon_name("dialog-information", GTK_ICON_SIZE_BUTTON));
+ gtk_container_add(GTK_CONTAINER(box), about_btn);
+
+ clear_btn = gtk_button_new();
+ gtk_container_add(GTK_CONTAINER(clear_btn), gtk_image_new_from_icon_name("edit-clear-all", GTK_ICON_SIZE_BUTTON));
+ gtk_container_add(GTK_CONTAINER(box), clear_btn);
+ gtk_header_bar_pack_start(GTK_HEADER_BAR(header), box);
+ g_signal_connect(about_btn, "clicked", G_CALLBACK(about_btn_clicked), NULL);
+ g_signal_connect(clear_btn, "clicked", G_CALLBACK(clear_btn_clicked), NULL);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
diff --git a/src/include/msr.h b/src/include/msr.h
index 33471ca..664a5ee 100644
--- a/src/include/msr.h
+++ b/src/include/msr.h
@@ -1,3 +1,4 @@
gboolean msr_init();
void msr_update();
+void msr_clear_minmax();
GSList* msr_get_sensors();
diff --git a/src/include/zenmonitor.h b/src/include/zenmonitor.h
index 9f320eb..c0b1f73 100644
--- a/src/include/zenmonitor.h
+++ b/src/include/zenmonitor.h
@@ -15,9 +15,9 @@ typedef struct {
gboolean (*func_init)();
GSList* (*func_get_sensors)();
void (*func_update)();
+ void (*func_clear_minmax)();
gboolean enabled;
GSList *sensors;
-
} SensorSource;
SensorInit* sensor_init_new(void);
diff --git a/src/include/zenpower.h b/src/include/zenpower.h
index 4feeb15..54978d6 100644
--- a/src/include/zenpower.h
+++ b/src/include/zenpower.h
@@ -1,3 +1,4 @@
gboolean zenpower_init();
GSList* zenpower_get_sensors();
void zenpower_update();
+void zenpower_clear_minmax();
diff --git a/src/ss/msr.c b/src/ss/msr.c
index e3c9198..d26f703 100644
--- a/src/ss/msr.c
+++ b/src/ss/msr.c
@@ -155,6 +155,16 @@ void msr_update() {
}
}
+void msr_clear_minmax() {
+ gint i;
+
+ package_power_min = package_power;
+ package_power_max = package_power;
+ for (i = 0; i < cores; i++) {
+ core_power_min[i] = core_power[i];
+ }
+}
+
GSList* msr_get_sensors() {
GSList *list = NULL;
SensorInit *data;
diff --git a/src/ss/zenpower.c b/src/ss/zenpower.c
index e449a3c..d9f8600 100644
--- a/src/ss/zenpower.c
+++ b/src/ss/zenpower.c
@@ -83,6 +83,15 @@ void zenpower_update() {
}
}
+void zenpower_clear_minmax() {
+ HwmonSensor *sensor;
+
+ for (sensor = hwmon_sensors; sensor->label; sensor++) {
+ sensor->min = sensor->current_value;
+ sensor->max = sensor->current_value;
+ }
+}
+
GSList* zenpower_get_sensors() {
GSList *list = NULL;
HwmonSensor *sensor;
diff --git a/src/zenmonitor.c b/src/zenmonitor.c
index b9fee07..4d96cb9 100644
--- a/src/zenmonitor.c
+++ b/src/zenmonitor.c
@@ -63,9 +63,19 @@ gchar *cpu_model() {
}
static SensorSource sensor_sources[] = {
- { "zenpower", zenpower_init, zenpower_get_sensors, zenpower_update, FALSE, NULL },
- { "msr", msr_init, msr_get_sensors, msr_update, FALSE, NULL },
- { NULL }
+ {
+ "zenpower",
+ zenpower_init, zenpower_get_sensors, zenpower_update, zenpower_clear_minmax,
+ FALSE, NULL
+ },
+ {
+ "msr",
+ msr_init, msr_get_sensors, msr_update, msr_clear_minmax,
+ FALSE, NULL
+ },
+ {
+ NULL
+ }
};
SensorInit *sensor_init_new() {