X-Git-Url: http://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Fui_status.c;h=22ba5c0123356aca7a800f82af73e1835f1f67b3;hb=4270c903e8007017b80c6c817dd41cf699f00df1;hp=d9781de5511542816e413476a086328ed261ab07;hpb=a83ca848ba834defb5bc54fe03ffb7409964846b;p=psensor.git diff --git a/src/ui_status.c b/src/ui_status.c index d9781de..22ba5c0 100644 --- a/src/ui_status.c +++ b/src/ui_status.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011 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 @@ -16,23 +16,20 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301 USA */ - -#include - -#include "log.h" +#include #include "ui_status.h" -GtkStatusIcon *status; +static const char *ICON = "psensor_normal"; +static const char *ATTENTION_ICON = "psensor_hot"; + +static GtkStatusIcon *status; +static unsigned int status_attention; static void cb_activate(GtkStatusIcon *icon, gpointer data) { - struct ui_psensor *ui; - - log_printf(LOG_DEBUG, "cb_activate()"); - - ui = (struct ui_psensor *)data; - gtk_window_present(GTK_WINDOW(ui->main_window)); + log_debug("cb_activate()"); + ui_window_show((struct ui_psensor *)data); } static void cb_popup_menu(GtkStatusIcon *icon, @@ -40,16 +37,19 @@ static void cb_popup_menu(GtkStatusIcon *icon, guint activate_time, gpointer data) { - log_printf(LOG_DEBUG, "cb_popup_menu()"); + log_debug("cb_popup_menu()"); } void ui_status_init(struct ui_psensor *ui) { - log_printf(LOG_DEBUG, "ui_status_create()"); + if (status) + return; + + log_debug("ui_status_create()"); status = gtk_status_icon_new(); - gtk_status_icon_set_from_icon_name(status, "psensor"); - gtk_status_icon_set_visible(status, TRUE); + gtk_status_icon_set_from_icon_name(status, ICON); + ui_status_set_visible(0); g_signal_connect(G_OBJECT(status), "popup-menu", @@ -62,14 +62,49 @@ void ui_status_init(struct ui_psensor *ui) ui); } -int is_status_supported() +int is_status_supported(void) { - return gtk_status_icon_is_embedded(status); + return status && gtk_status_icon_is_embedded(status); +} + +void ui_status_cleanup(void) +{ + log_debug("ui_status_cleanup()"); + + if (status) { + g_object_unref(G_OBJECT(status)); + status = NULL; + } +} + +void ui_status_update(struct ui_psensor *ui, unsigned int attention) +{ + log_debug("ui_status_update()"); + + if (status_attention && !attention) + gtk_status_icon_set_from_icon_name(status, ICON); + else if (!status_attention && attention) + gtk_status_icon_set_from_icon_name(status, ATTENTION_ICON); + + status_attention = attention; +} + +GtkStatusIcon *ui_status_get_icon(struct ui_psensor *ui) +{ + if (!status) + ui_status_init(ui); + + return status; } -void ui_status_cleanup() +void ui_status_set_visible(unsigned int visible) { - log_printf(LOG_DEBUG, "ui_status_cleanup()"); + log_debug("ui_status_set_visible(%d)", visible); - g_object_unref(G_OBJECT(status)); + if (status) { + if (visible) + gtk_status_icon_set_visible(status, TRUE); + else + gtk_status_icon_set_visible(status, FALSE); + } }