aboutsummaryrefslogtreecommitdiff
path: root/bat_tray.c
diff options
context:
space:
mode:
authorDavid Phillips <dbphillipsnz@gmail.com>2015-08-28 23:54:00 +1200
committerDavid Phillips <dbphillipsnz@gmail.com>2015-08-29 00:54:30 +1200
commitb71fdc1baa7aa1f6a8099e6c90929718e282b899 (patch)
tree9cef0630db9c8af5ee1bb776c51abbe2a5e234e5 /bat_tray.c
parentb3e88dca9e4574b8aec8028a8edeca1df1d19843 (diff)
downloadparamano-b71fdc1baa7aa1f6a8099e6c90929718e282b899.tar.xz
Made tooltip texts cached, fixes GitHub issue #4
Diffstat (limited to 'bat_tray.c')
-rw-r--r--bat_tray.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/bat_tray.c b/bat_tray.c
index e044630..cdedf86 100644
--- a/bat_tray.c
+++ b/bat_tray.c
@@ -20,6 +20,7 @@
#include "paramano.h"
static GtkStatusIcon* tray;
+static char tooltip_text[1024];
int bat_num; // Shortcoming: we only detect one battery
char *CHARGE_VALUE_PATH, *CHARGE_STATE_PATH;
@@ -103,17 +104,23 @@ long get_bat_seconds_left()
/***********************************************************************
- * Updates the battery tray tooltip text
+ * Shows/updates the battery tray tooltip
**********************************************************************/
-static gboolean update_tooltip(GtkStatusIcon* status_icon,gint x,gint y,gboolean keyboard_mode,GtkTooltip* tooltip,gpointer data)
+static gboolean show_tooltip(GtkStatusIcon* status_icon, gint x, gint y, gboolean keyboard_mode, GtkTooltip* tooltip, gpointer data)
+{
+ gtk_tooltip_set_text(tooltip, tooltip_text);
+ return true;
+}
+
+/***********************************************************************
+ * Updates the battery tray tooltip's cached text
+ **********************************************************************/
+static void update_tooltip_cache()
{
char* msg;
int seconds_left = get_bat_seconds_left();
-
char* time_left;
- fprintf(stderr, "%d seconds left on bat\n", seconds_left);
-
if (seconds_left == -1)
{
asprintf(&time_left, _("Unknown time left"));
@@ -143,20 +150,19 @@ static gboolean update_tooltip(GtkStatusIcon* status_icon,gint x,gint y,gboolean
asprintf(&msg, _("Unknown status") );
break;
}
- debug("Setting tooltip text to '%s'\n",msg);
- gtk_tooltip_set_text(tooltip, msg);
+ debug("Setting cached tooltip text to '%s'\n",msg);
+ strncpy(tooltip_text, msg, sizeof(tooltip_text));
free(time_left);
free(msg);
-
- return true;
}
/***********************************************************************
* Updates the battery tray icon based upon battery percent
+ * Also updates the cached tooltip text
**********************************************************************/
-static gboolean update_icon(gpointer user_data)
+static gboolean update()
{
char *icon_file;
unsigned int rounded;
@@ -180,6 +186,8 @@ static gboolean update_icon(gpointer user_data)
break;
}
+
+ update_tooltip_cache();
debug("Setting tray icon to '%s'\n",icon_file);
gtk_status_icon_set_from_file(tray, icon_file);
@@ -209,8 +217,12 @@ void bat_tray_init()
gtk_status_icon_set_from_file(tray, icon_file);
free(icon_file);
gtk_status_icon_set_has_tooltip (tray, TRUE);
- g_signal_connect(G_OBJECT(tray), "query-tooltip", GTK_SIGNAL_FUNC(update_tooltip), NULL);
- g_timeout_add(5000, update_icon, NULL);
+ g_signal_connect(G_OBJECT(tray), "query-tooltip", GTK_SIGNAL_FUNC(show_tooltip), NULL);
+ g_timeout_add(5000, update, NULL);
+
+ /* Force something useful to be in the cached tooltip text,
+ * force meaningful icon */
+ update();
}