summaryrefslogtreecommitdiff
path: root/mktrayicon.c
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2020-02-06 16:16:50 -0500
committerB Stack <bgstack15@gmail.com>2020-02-06 16:16:50 -0500
commit9e0b07908dda249de6ce115ed32a36a7d5d13ffe (patch)
tree1498ab262b842af84f5351f54112c72d1364e8ad /mktrayicon.c
parentadd mouse scroll events on R and r (diff)
downloadmktrayicon-scrollevents.tar.gz
mktrayicon-scrollevents.tar.bz2
mktrayicon-scrollevents.zip
add middleclick, and documentationscrollevents
Diffstat (limited to 'mktrayicon.c')
-rw-r--r--mktrayicon.c72
1 files changed, 64 insertions, 8 deletions
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;
bgstack15