X-Git-Url: http://wpitchoune.net/gitweb/?p=psensor-pkg-debian.git;a=blobdiff_plain;f=src%2Fui_unity.c;h=b2884472afd73f4f6c4ba82c461202c52b0e0f31;hp=2c00403377b4e55bcaedbc48ec4d6ab9b5b88eb8;hb=bd7036af56a4b61b2b473dccbeac5e26f78b57da;hpb=4e6ce51e7afeb7924573c40796910cd003850949 diff --git a/src/ui_unity.c b/src/ui_unity.c index 2c00403..b288447 100644 --- a/src/ui_unity.c +++ b/src/ui_unity.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2014 jeanfi@gmail.com + * Copyright (C) 2010-2016 jeanfi@gmail.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -18,43 +18,81 @@ */ #include +#include #include #include -static int initialized; static UnityLauncherEntry *psensor_entry; -static unsigned int last_visible = -1; +static bool count_visible; -void ui_unity_launcher_entry_update(struct psensor **sensors, - unsigned int show, - int use_celsius) +static void +count_visible_changed_cbk(GSettings *settings, gchar *key, gpointer data) { - double v; - - if (!initialized) { - psensor_entry = unity_launcher_entry_get_for_desktop_file - (PSENSOR_DESKTOP_FILE); + count_visible = config_is_count_visible(); + if (count_visible) { unity_launcher_entry_set_count(psensor_entry, 0); - initialized = 1; + unity_launcher_entry_set_count_visible(psensor_entry, TRUE); + } else { + unity_launcher_entry_set_count_visible(psensor_entry, FALSE); } +} + +static double get_max_current_value(struct psensor **sensors, unsigned int type) +{ + double m, v; + struct psensor *s; + + m = UNKNOWN_DBL_VALUE; + while (*sensors) { + s = *sensors; - if (last_visible != show) { - if (show) - unity_launcher_entry_set_count_visible(psensor_entry, - TRUE); - else - unity_launcher_entry_set_count_visible(psensor_entry, - FALSE); - last_visible = show; + if ((s->type & type) && config_is_sensor_graph_enabled(s->id)) { + v = psensor_get_current_value(s); + + if (m == UNKNOWN_DBL_VALUE || v > m) + m = v; + } + + sensors++; } - if (sensors && *sensors) { - v = psensor_get_max_current_value(sensors, SENSOR_TYPE_TEMP); + return m; +} + +void ui_unity_launcher_entry_update(struct psensor **sensors) +{ + double v; + + if (!count_visible || !sensors || !*sensors) + return; + + v = get_max_current_value(sensors, SENSOR_TYPE_TEMP); - if (!use_celsius) + if (v != UNKNOWN_DBL_VALUE) { + if (config_get_temperature_unit() == FAHRENHEIT) v = celsius_to_fahrenheit(v); unity_launcher_entry_set_count(psensor_entry, v); } } + +void ui_unity_init(void) +{ + psensor_entry = unity_launcher_entry_get_for_desktop_file + (PSENSOR_DESKTOP_FILE); + + count_visible = config_is_count_visible(); + + if (count_visible) { + unity_launcher_entry_set_count(psensor_entry, 0); + unity_launcher_entry_set_count_visible(psensor_entry, TRUE); + } else { + unity_launcher_entry_set_count_visible(psensor_entry, FALSE); + } + + g_signal_connect_after(config_get_GSettings(), + "changed::interface-unity-launcher-count-disabled", + G_CALLBACK(count_visible_changed_cbk), + NULL); +}