From 48f7a85a5b18b4c112757f470bcced2498951d70 Mon Sep 17 00:00:00 2001 From: Bruno Dantas Date: Wed, 16 Oct 2019 11:49:46 -0400 Subject: add handling for custom icons --- mktrayicon.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/mktrayicon.c b/mktrayicon.c index f4deb10..8c8dad0 100644 --- a/mktrayicon.c +++ b/mktrayicon.c @@ -13,6 +13,7 @@ GtkStatusIcon *icon; char *onclick = NULL; +char *icon_type; /* stock (name only) vs. custom (full path) */ void tray_icon_on_click(GtkStatusIcon *status_icon, gpointer user_data) @@ -55,7 +56,14 @@ gboolean set_icon(gpointer data) #ifdef DEBUG printf("Setting icon to '%s'\n", p); #endif - gtk_status_icon_set_from_icon_name(icon, p); + if (strcmp(icon_type, "custom") == 0) + { + gtk_status_icon_set_from_file(icon, p); + } + else + { + gtk_status_icon_set_from_icon_name(icon, p); + } free(data); return FALSE; } @@ -142,6 +150,14 @@ gpointer watch_fifo(gpointer argv) gdk_threads_add_idle(set_tooltip, param); break; case 'i': /* icon */ + if (strchr(param, '/')) + { + icon_type="custom"; + } + else + { + icon_type="stock"; + } gdk_threads_add_idle(set_icon, param); break; case 'h': /* hide */ @@ -189,7 +205,14 @@ static GtkStatusIcon *create_tray_icon(char *start_icon) { GtkStatusIcon *tray_icon; - tray_icon = gtk_status_icon_new_from_icon_name(start_icon); + if (strchr(start_icon, '/')) + { + tray_icon = gtk_status_icon_new_from_file(start_icon); + } + else + { + tray_icon = gtk_status_icon_new_from_icon_name(start_icon); + } g_signal_connect(G_OBJECT(tray_icon), "activate", G_CALLBACK(tray_icon_on_click), NULL); g_signal_connect(G_OBJECT(tray_icon), "popup-menu", G_CALLBACK(tray_icon_on_menu), NULL); gtk_status_icon_set_visible(tray_icon, TRUE); -- cgit From 97384dc09263c4bd3afb76e2755645538727dc7f Mon Sep 17 00:00:00 2001 From: GNUser Date: Wed, 16 Oct 2019 12:18:07 -0400 Subject: Update mktrayicon.c --- mktrayicon.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/mktrayicon.c b/mktrayicon.c index 8c8dad0..d793c89 100644 --- a/mktrayicon.c +++ b/mktrayicon.c @@ -13,7 +13,6 @@ GtkStatusIcon *icon; char *onclick = NULL; -char *icon_type; /* stock (name only) vs. custom (full path) */ void tray_icon_on_click(GtkStatusIcon *status_icon, gpointer user_data) @@ -56,7 +55,7 @@ gboolean set_icon(gpointer data) #ifdef DEBUG printf("Setting icon to '%s'\n", p); #endif - if (strcmp(icon_type, "custom") == 0) + if (strchr(p, '/')) { gtk_status_icon_set_from_file(icon, p); } @@ -150,14 +149,6 @@ gpointer watch_fifo(gpointer argv) gdk_threads_add_idle(set_tooltip, param); break; case 'i': /* icon */ - if (strchr(param, '/')) - { - icon_type="custom"; - } - else - { - icon_type="stock"; - } gdk_threads_add_idle(set_icon, param); break; case 'h': /* hide */ -- cgit From a687cb010ea589a8379060cf3db4286d8ee9b389 Mon Sep 17 00:00:00 2001 From: GNUser Date: Wed, 16 Oct 2019 12:23:14 -0400 Subject: Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dc9bba8..db15ad8 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ command. Each command should be terminated by a newline. The following commands are supported: - `q`: Terminate `mktrayicon` and remove the tray icon - - `i `: Set the graphic to use for the tray icon (see `/usr/share/icons`) + - `i `: Set the graphic to use for the tray icon; it can be a stock icon name (see `/usr/share/icons`) or path to a custom icon - `t `: Set the text to display in the icon tooltip - `t`: Remove the icon tooltip - `c `: Set the command to be execute when the user clicks the icon (`cmnd` is passed to `/bin/sh -c`) @@ -22,7 +22,7 @@ are supported: - `s`: Show the tray icon By default, the `none` tooltip icon is used. To change this, pass `-i -` when running `mktrayicon`. +` or `-i ` when running `mktrayicon`. Note that any script communicating with `mktrayicon` **must**, for the time being, send `q` when they are done. Just removing the FIFO file will **not** -- cgit