From 30280f0093e8aea4bc8af8a46c2e529e8ec61ac9 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Sat, 15 Nov 2014 14:49:34 +0100 Subject: [PATCH] made count visible setting change dynamic --- src/cfg.c | 10 +++++++ src/cfg.h | 3 ++ src/glade/psensor-pref.glade | 1 + src/main.c | 5 ++-- src/ui_pref.c | 5 ++++ src/ui_unity.c | 67 +++++++++++++++++++++++++------------------- src/ui_unity.h | 6 ++-- 7 files changed, 61 insertions(+), 36 deletions(-) diff --git a/src/cfg.c b/src/cfg.c index fb24085..14267dc 100644 --- a/src/cfg.c +++ b/src/cfg.c @@ -951,3 +951,13 @@ void config_set_menu_bar_enabled(bool enabled) { set_bool(KEY_INTERFACE_MENU_BAR_DISABLED, !enabled); } + +bool config_is_count_visible(void) +{ + return !get_bool(KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED); +} + +void config_set_count_visible(bool visible) +{ + set_bool(KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED, !visible); +} diff --git a/src/cfg.h b/src/cfg.h index 2ca0fbf..bde8af4 100644 --- a/src/cfg.h +++ b/src/cfg.h @@ -154,6 +154,9 @@ void config_set_window_keep_below_enabled(bool); bool config_is_menu_bar_enabled(void); void config_set_menu_bar_enabled(bool); +bool config_is_count_visible(void); +void config_set_count_visible(bool); + /* * Returns the user directory containing psensor data (configuration * and log). diff --git a/src/glade/psensor-pref.glade b/src/glade/psensor-pref.glade index fa164dd..eb05a71 100644 --- a/src/glade/psensor-pref.glade +++ b/src/glade/psensor-pref.glade @@ -194,6 +194,7 @@ 4 0 True + 0 diff --git a/src/main.c b/src/main.c index 484addd..defc60d 100644 --- a/src/main.c +++ b/src/main.c @@ -203,9 +203,7 @@ static gboolean ui_refresh_thread(gpointer data) use_celsius = 1; else use_celsius = 0; - ui_unity_launcher_entry_update(ui->sensors, - !cfg->unity_launcher_count_disabled, - use_celsius); + ui_unity_launcher_entry_update(ui->sensors); if (ui->graph_update_interval != cfg->graph_update_interval) { ui->graph_update_interval = cfg->graph_update_interval; @@ -538,6 +536,7 @@ int main(int argc, char **argv) g_timeout_add(1000 * ui.graph_update_interval, ui_refresh_thread, &ui); ui_appindicator_init(&ui); + ui_unity_init(); gdk_notify_startup_complete(); diff --git a/src/ui_pref.c b/src/ui_pref.c index 40c4dcc..3a181c3 100644 --- a/src/ui_pref.c +++ b/src/ui_pref.c @@ -55,6 +55,11 @@ void ui_pref_menu_toggled_cbk(GtkToggleButton *btn, gpointer data) config_set_menu_bar_enabled(gtk_toggle_button_get_active(btn)); } +void ui_pref_count_visible_toggled_cbk(GtkToggleButton *btn, gpointer data) +{ + config_set_count_visible(gtk_toggle_button_get_active(btn)); +} + GdkRGBA color_to_GdkRGBA(struct color *color) { GdkRGBA c; diff --git a/src/ui_unity.c b/src/ui_unity.c index 9f9bd04..570567d 100644 --- a/src/ui_unity.c +++ b/src/ui_unity.c @@ -22,9 +22,21 @@ #include #include -static int initialized; static UnityLauncherEntry *psensor_entry; -static unsigned int last_visible = -1; +static bool count_visible; + +static void +count_visible_changed_cbk(GSettings *settings, gchar *key, gpointer data) +{ + 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); + } +} static double get_max_current_value(struct psensor **sensors, unsigned int type) { @@ -48,42 +60,39 @@ static double get_max_current_value(struct psensor **sensors, unsigned int type) return m; } -void ui_unity_launcher_entry_update(struct psensor **sensors, - unsigned int show, - int use_celsius) +void ui_unity_launcher_entry_update(struct psensor **sensors) { double v; - if (!initialized) { - psensor_entry = unity_launcher_entry_get_for_desktop_file - (PSENSOR_DESKTOP_FILE); + if (!count_visible || !sensors || !*sensors) + return; - unity_launcher_entry_set_count(psensor_entry, 0); - initialized = 1; - } + v = get_max_current_value(sensors, SENSOR_TYPE_TEMP); - 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 (v != UNKNOWN_DBL_VALUE) { + if (config_get_temperature_unit() == FAHRENHEIT) + v = celsius_to_fahrenheit(v); - if (show && sensors && *sensors) { - v = get_max_current_value(sensors, SENSOR_TYPE_TEMP); - - 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); } } 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); } diff --git a/src/ui_unity.h b/src/ui_unity.h index 50ffa1d..641c7ea 100644 --- a/src/ui_unity.h +++ b/src/ui_unity.h @@ -26,7 +26,7 @@ static inline bool ui_unity_is_supported(void) { return true; } -void ui_unity_launcher_entry_update(struct psensor **, unsigned int, int); +void ui_unity_launcher_entry_update(struct psensor **); void ui_unity_init(void); @@ -35,9 +35,7 @@ void ui_unity_init(void); static inline bool ui_unity_is_supported(void) { return false; } static inline void -ui_unity_launcher_entry_update(struct psensor **s, - unsigned int show, - int use_celsius) {} +ui_unity_launcher_entry_update(struct psensor **s) {} static inline void ui_unity_init(void) {} -- 2.7.4