X-Git-Url: https://git.wpitchoune.net/gitweb/?p=psensor.git;a=blobdiff_plain;f=src%2Fui_unity.c;h=2b949c8a65a0f074e4010b2ddb97a8d67464b7ec;hp=6040facd9408bc726ed778be2d0ad2858bfc415c;hb=e02abf054eace73a51d1f5713b86f6be85d8d61b;hpb=6f8560319706bacf5a24e2a01de2cdb9d2ae9b35 diff --git a/src/ui_unity.c b/src/ui_unity.c index 6040fac..2b949c8 100644 --- a/src/ui_unity.c +++ b/src/ui_unity.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2012 jeanfi@gmail.com + * Copyright (C) 2010-2014 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,22 +18,45 @@ */ #include -#include "psensor.h" +#include +#include +#include static int initialized; static UnityLauncherEntry *psensor_entry; static unsigned int last_visible = -1; +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 ((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++; + } + + return m; +} + void ui_unity_launcher_entry_update(struct psensor **sensors, unsigned int show, - int use_celcius) + int use_celsius) { double v; - if (!initialized) { psensor_entry = unity_launcher_entry_get_for_desktop_file - ("psensor.desktop"); + (PSENSOR_DESKTOP_FILE); unity_launcher_entry_set_count(psensor_entry, 0); initialized = 1; @@ -49,12 +72,14 @@ void ui_unity_launcher_entry_update(struct psensor **sensors, last_visible = show; } - if (sensors && *sensors) { - v = psensor_get_max_current_value(sensors, SENSOR_TYPE_TEMP); + if (show && sensors && *sensors) { + v = get_max_current_value(sensors, SENSOR_TYPE_TEMP); - if (!use_celcius) - v = celcius_to_fahrenheit(v); + if (v != UNKNOWN_DBL_VALUE) { + if (!use_celsius) + v = celsius_to_fahrenheit(v); - unity_launcher_entry_set_count(psensor_entry, v); + unity_launcher_entry_set_count(psensor_entry, v); + } } }