X-Git-Url: http://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Fui_status.c;h=22ba5c0123356aca7a800f82af73e1835f1f67b3;hb=a2bce14963ee379e9f5b5e745304129b651e7352;hp=517ab271eb2d929b5c473a49ee98ed44e2b74dfe;hpb=bd79e2e58e6988ba9ba57a9cbc8613aff2b1bb32;p=psensor.git diff --git a/src/ui_status.c b/src/ui_status.c index 517ab27..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,19 +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 ui_status_cleanup(void) { - log_printf(LOG_DEBUG, "ui_status_cleanup()"); + log_debug("ui_status_cleanup()"); - g_object_unref(G_OBJECT(status)); + if (status) { + g_object_unref(G_OBJECT(status)); + status = NULL; + } } void ui_status_update(struct ui_psensor *ui, unsigned int attention) { - log_printf(LOG_DEBUG, "ui_status_update()"); + 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_set_visible(unsigned int visible) +{ + log_debug("ui_status_set_visible(%d)", visible); + + if (status) { + if (visible) + gtk_status_icon_set_visible(status, TRUE); + else + gtk_status_icon_set_visible(status, FALSE); + } }