diff options
author | B Stack <bgstack15@gmail.com> | 2020-02-13 09:38:40 -0500 |
---|---|---|
committer | B Stack <bgstack15@gmail.com> | 2020-02-13 09:38:40 -0500 |
commit | cea23e87e971f2a8494e2bef0a416d1e41d95e0c (patch) | |
tree | ac765bb5f39dbb388bc45030520e42898788ded4 | |
parent | add middleclick, and documentation (diff) | |
download | mktrayicon-cea23e87e971f2a8494e2bef0a416d1e41d95e0c.tar.gz mktrayicon-cea23e87e971f2a8494e2bef0a416d1e41d95e0c.tar.bz2 mktrayicon-cea23e87e971f2a8494e2bef0a416d1e41d95e0c.zip |
merge scrollevents and menu_separator for new master
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | README.md | 5 | ||||
-rw-r--r-- | examples/menu.sh | 8 | ||||
-rw-r--r-- | mktrayicon.c | 39 |
4 files changed, 38 insertions, 16 deletions
@@ -2,4 +2,4 @@ mktrayicon: mktrayicon.c ${CC} `echo $${DEBUG+-DDEBUG}` `pkg-config --cflags gtk+-3.0` -o $@ $< `pkg-config --libs gtk+-3.0` `pkg-config --cflags --libs x11` clean: - rm mktrayicon + rm mktrayicon || : @@ -56,7 +56,8 @@ The m(enu) command uses `,` as a delimiter between label and command and `|` as a delimiter between entries (label+command). If you want to use these two characters in a label or command, you have to escape them with `\`. You can make a blank label or a label without an action by leaving -out the `label` or `cmd` respectively. For example: +out the `label` or `cmd` respectively. Use `-----` or an empty label to +insert a menu separator. For example: ```console $ echo "m Browser,firefox|Terminal,xterm|Label-only||,chromium" > /tmp/test @@ -68,7 +69,7 @@ Would give you a menu with five entries: - "Browser", which launches `firefox` when clicked - "Terminal", which launches `xterm` when clicked - "Label-only", which does nothing if clicked - - An unlabeled, inactive entry (useful as a separator) + - A separator - An unlabeled entry which launches `chromium` when clicked ## Why? diff --git a/examples/menu.sh b/examples/menu.sh new file mode 100644 index 0000000..2ceb302 --- /dev/null +++ b/examples/menu.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# Set up tray icon +mkfifo /tmp/$$.icon +./mktrayicon /tmp/$$.icon & + +# set menu with a separator and a quit option +echo "m terminal,xterm|-----,true|quit,echo 'q' > /tmp/$$.icon" > /tmp/$$.icon diff --git a/mktrayicon.c b/mktrayicon.c index 21f1432..24110a0 100644 --- a/mktrayicon.c +++ b/mktrayicon.c @@ -1,6 +1,7 @@ /* * @author Jon Gjengset <jon@tsp.io> * @see http://blog.sacaluta.com/2007/08/gtk-system-tray-icon-example.html + * vim: softtabstop=2 shiftwidth=2 tabstop=2 */ #include <X11/Xlib.h> #include <glib.h> @@ -438,10 +439,15 @@ outer: // Now create the menu item widgets and attach them on the menu for (int i = 0; i < menusize; i++) { - GtkWidget *w = gtk_menu_item_new_with_label(onmenu[i].name); + GtkWidget *w; + if (0 == strlen(onmenu[i].name) || (!strncmp(onmenu[i].name, "-----", 5))) { + w = gtk_separator_menu_item_new() ; + } else { + w = gtk_menu_item_new_with_label(onmenu[i].name); + g_signal_connect(G_OBJECT(w), "activate", G_CALLBACK(click_menu_item), + NULL); + } gtk_menu_shell_append(GTK_MENU_SHELL(menu), w); - g_signal_connect(G_OBJECT(w), "activate", G_CALLBACK(click_menu_item), - NULL); } gtk_widget_show_all(menu); free(param); @@ -531,6 +537,19 @@ static GtkStatusIcon *create_tray_icon(char *start_icon) { return tray_icon; } +int print_usage(char **argv) { + printf("Usage: %s [-i ICON] [-t TOOLTIP] [-h] [FIFO]\n", *argv); + printf("Create a system tray icon as specified\n"); + printf("\n"); + printf(" -i ICON\tUse the specified ICON when initializing\n"); + printf(" -t TOOLTIP\tUse the specified TOOLTIP when initializing\n"); + printf(" -h \t\tDisplay this help message\n"); + printf("\n"); + printf("If a FIFO is not provided, mktrayicon will run until killed\n"); + printf("Report bugs at https://github.com/jonhoo/mktrayicon\n"); + return 0; +} + int main(int argc, char **argv) { char *start_icon = "none"; char *tooltip = NULL; @@ -541,19 +560,11 @@ int main(int argc, char **argv) { gtk_init(&argc, &argv); if (argc == 1) { - printf("Usage: %s [-i ICON] [-t TOOLTIP] [FIFO]\n", *argv); - printf("Create a system tray icon as specified\n"); - printf("\n"); - printf(" -i ICON\tUse the specified ICON when initializing\n"); - printf(" -t TOOLTIP\tUse the specified TOOLTIP when initializing\n"); - printf("\n"); - printf("If a FIFO is not provided, mktrayicon will run until killed\n"); - printf("Report bugs at https://github.com/jonhoo/mktrayicon\n"); - return 0; + return print_usage(argv); } int c; - while ((c = getopt(argc, argv, "i:t:")) != -1) + while ((c = getopt(argc, argv, "i:t:h")) != -1) switch (c) { case 'i': start_icon = optarg; @@ -561,6 +572,8 @@ int main(int argc, char **argv) { case 't': tooltip = optarg; break; + case 'h': + return print_usage(argv); case '?': fprintf(stderr, "Unknown option: %c\n", optopt); return 1; |