From e09566298bb2c44bed1d1401252fb7863c8d2de0 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Sat, 12 Nov 2011 21:53:55 +0000 Subject: [PATCH] status icon --- src/main.c | 24 +++++++++++++++--------- src/ui.c | 1 + src/ui_appindicator.c | 5 ++--- src/ui_status.c | 10 ++++++++-- src/ui_status.h | 2 ++ 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/main.c b/src/main.c index 19a01e6..f5ff0b3 100644 --- a/src/main.c +++ b/src/main.c @@ -355,10 +355,16 @@ static gboolean initial_window_show(gpointer data) { struct ui_psensor *ui; + log_printf(LOG_DEBUG, "initial_window_show()"); + ui = (struct ui_psensor *)data; log_printf(LOG_DEBUG, - "is_status_supported: %d\n", is_status_supported()); + "is_status_supported: %d", is_status_supported()); + log_printf(LOG_DEBUG, + "is_appindicator_supported: %d", is_appindicator_supported()); + log_printf(LOG_DEBUG, + "hide_on_startup: %d", ui->config->hide_on_startup); if (!ui->config->hide_on_startup || (!is_appindicator_supported() && !is_status_supported())) @@ -470,14 +476,6 @@ int main(int argc, char **argv) /* sensor list */ ui_sensorlist_create(&ui); - /* - * show the window as soon as all gtk events have been processed - * in order to ensure that the status icon is attempted to be - * drawn before. If not, there is no way to detect that it is - * visible. - */ - g_idle_add((GSourceFunc)initial_window_show, &ui); - thread = g_thread_create((GThreadFunc) update_psensor_measures, &ui, TRUE, &error); @@ -492,6 +490,14 @@ int main(int argc, char **argv) ui_appindicator_init(&ui); #endif + /* + * show the window as soon as all gtk events have been processed + * in order to ensure that the status icon is attempted to be + * drawn before. If not, there is no way to detect that it is + * visible. + */ + g_idle_add((GSourceFunc)initial_window_show, &ui); + gdk_notify_startup_complete(); /* main loop */ diff --git a/src/ui.c b/src/ui.c index aef453b..9a78a86 100644 --- a/src/ui.c +++ b/src/ui.c @@ -344,5 +344,6 @@ void ui_window_update(struct ui_psensor *ui) void ui_window_show(struct ui_psensor *ui) { + log_printf(LOG_DEBUG, "ui_window_show()"); gtk_window_present(GTK_WINDOW(ui->main_window)); } diff --git a/src/ui_appindicator.c b/src/ui_appindicator.c index 6607e43..08ef670 100644 --- a/src/ui_appindicator.c +++ b/src/ui_appindicator.c @@ -28,6 +28,7 @@ #include "ui.h" #include "ui_appindicator.h" #include "ui_sensorpref.h" +#include "ui_status.h" #include "ui_pref.h" static GtkMenuItem **sensor_menu_items; @@ -216,11 +217,9 @@ static GtkStatusIcon *unity_fallback(AppIndicator *indicator) { log_printf(LOG_DEBUG, "ui_appindicator#unity_fallback"); - gtk_widget_show_all(main_window); - appindicator_supported = 0; - return NULL; + return ui_status_get_icon(); } static void diff --git a/src/ui_status.c b/src/ui_status.c index a316e90..39fe77d 100644 --- a/src/ui_status.c +++ b/src/ui_status.c @@ -17,8 +17,6 @@ * 02110-1301 USA */ -#include - #include "log.h" #include "ui_status.h" @@ -43,6 +41,9 @@ static void cb_popup_menu(GtkStatusIcon *icon, void ui_status_init(struct ui_psensor *ui) { + if (status) + return ; + log_printf(LOG_DEBUG, "ui_status_create()"); status = gtk_status_icon_new(); @@ -83,3 +84,8 @@ void ui_status_update(struct ui_psensor *ui, unsigned int attention) status_attention = attention; } + +GtkStatusIcon *ui_status_get_icon() +{ + return status; +} diff --git a/src/ui_status.h b/src/ui_status.h index 7b6c6de..40cc3c5 100644 --- a/src/ui_status.h +++ b/src/ui_status.h @@ -20,6 +20,7 @@ #ifndef _PSENSOR_UI_STATUS_H_ #define _PSENSOR_UI_STATUS_H_ +#include #include void ui_status_init(struct ui_psensor *ui); @@ -27,5 +28,6 @@ void ui_status_cleanup(); void ui_status_update(struct ui_psensor *ui, unsigned int attention); /* Whether status icon is supported i.e. visible. */ int is_status_supported(); +GtkStatusIcon *ui_status_get_icon(); #endif -- 2.7.4