diff options
author | B Stack <bgstack15@gmail.com> | 2020-02-06 16:16:50 -0500 |
---|---|---|
committer | B Stack <bgstack15@gmail.com> | 2020-02-06 16:16:50 -0500 |
commit | 9e0b07908dda249de6ce115ed32a36a7d5d13ffe (patch) | |
tree | 1498ab262b842af84f5351f54112c72d1364e8ad | |
parent | add mouse scroll events on R and r (diff) | |
download | mktrayicon-9e0b07908dda249de6ce115ed32a36a7d5d13ffe.tar.gz mktrayicon-9e0b07908dda249de6ce115ed32a36a7d5d13ffe.tar.bz2 mktrayicon-9e0b07908dda249de6ce115ed32a36a7d5d13ffe.zip |
add middleclick, and documentationscrollevents
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | mktrayicon.c | 72 |
2 files changed, 70 insertions, 8 deletions
@@ -31,6 +31,12 @@ newline. The following commands are supported: - `m`: Remove the menu handler - `h`: Hide the tray icon - `s`: Show the tray icon + - `R <cmnd>`: Set the command to execute when the user scrolls the + mouse wheel up + - `r <cmnd>`: Set the command to execute when the user scrolls the + mouse wheel down + - `S <cmnd>`: Set the command to execute when the user middle-clicks + the tray icon By default, the `none` tooltip icon is used. To change this, pass `-i <stock_icon_name>` or `-i <path_to_custom_icon>` when running diff --git a/mktrayicon.c b/mktrayicon.c index 8584783..21f1432 100644 --- a/mktrayicon.c +++ b/mktrayicon.c @@ -54,6 +54,7 @@ struct item { } * onmenu; char *onscrollup = NULL; char *onscrolldown = NULL; +char *onmiddleclick = NULL; int menusize = 0; // number of menu entries GtkWidget *menu = NULL; @@ -66,6 +67,24 @@ void tray_icon_on_click(GtkStatusIcon *status_icon, gpointer user_data) { } } +void tray_icon_on_middleclick(GtkStatusIcon *status_icon, GdkEventButton *event, + gpointer user_data) { + if (2 == event->button) { + if (onmiddleclick == NULL) { +#ifdef DEBUG + printf("middleclick, but no command specified\n"); +#endif + } else { +#ifdef DEBUG + printf("middleclick\n"); +#endif + if (onmiddleclick != NULL && fork() == 0) { + execl("/bin/sh", "sh", "-c", onmiddleclick, (char *)NULL); + } + } + } +} + /* * Callback function for when an entry is selected from the menu * We loop over all entry names to find what action to execute @@ -104,12 +123,10 @@ void tray_icon_on_scroll(GtkStatusIcon *status_icon, GdkEventScroll *event, execl("/bin/sh", "sh", "-c", onscrolldown, (char *)NULL); break; } - if (i != NULL) { - #ifdef DEBUG +#ifdef DEBUG printf("scroll %s\n",i); - #endif - +#endif } } @@ -433,15 +450,52 @@ outer: if (onscrollup != NULL) { free(onscrollup); } - onscrollup = malloc(strlen(param)); - strncpy(onscrollup, param, len + 1); + if (!param || (*param == '\0')) { +#ifdef DEBUG + printf("Removing scrollup command\n"); + onscrollup = NULL; +#endif + } else { +#ifdef DEBUG + printf("Setting scrollup command\n"); +#endif + onscrollup = malloc(strlen(param)); + strncpy(onscrollup, param, len + 1); + } break; case 'r': /* mouse scroll down */ if (onscrolldown != NULL) { free(onscrolldown); } - onscrolldown = malloc(strlen(param)); - strncpy(onscrolldown, param, len + 1); + if (!param || (*param == '\0')) { +#ifdef DEBUG + printf("Removing scrolldown command\n"); + onscrolldown = NULL; +#endif + } else { +#ifdef DEBUG + printf("Setting scrolldown command\n"); +#endif + onscrolldown = malloc(strlen(param)); + strncpy(onscrolldown, param, len + 1); + } + break; + case 'S': /* mouse middle click */ + if (onmiddleclick != NULL) { + free(onmiddleclick); + } + if (!param || (*param == '\0')) { +#ifdef DEBUG + printf("Removing middle click command\n"); + onmiddleclick = NULL; +#endif + } else { +#ifdef DEBUG + printf("Setting middleclick command\n"); +#endif + onmiddleclick = malloc(strlen(param)); + strncpy(onmiddleclick, param, len + 1); + } break; default: fprintf(stderr, "Unknown command: '%c'\n", *buf); @@ -470,6 +524,8 @@ static GtkStatusIcon *create_tray_icon(char *start_icon) { G_CALLBACK(tray_icon_on_menu), NULL); g_signal_connect(G_OBJECT(tray_icon), "scroll-event", G_CALLBACK(tray_icon_on_scroll), NULL); + g_signal_connect(G_OBJECT(tray_icon), "button-release-event", + G_CALLBACK(tray_icon_on_middleclick), NULL); gtk_status_icon_set_visible(tray_icon, TRUE); return tray_icon; |