summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2020-02-05 22:17:44 -0500
committerB Stack <bgstack15@gmail.com>2020-02-05 22:17:44 -0500
commit1a6892ff1d8e842ab0e59a28707f7f182129961e (patch)
tree3c67f22ed5163cb82e9013d044be8d15112ef0c4
parentclang-format (diff)
downloadmktrayicon-1a6892ff1d8e842ab0e59a28707f7f182129961e.tar.gz
mktrayicon-1a6892ff1d8e842ab0e59a28707f7f182129961e.tar.bz2
mktrayicon-1a6892ff1d8e842ab0e59a28707f7f182129961e.zip
add mouse scroll events on R and r
-rw-r--r--Makefile2
-rw-r--r--mktrayicon.c42
2 files changed, 43 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index d5b434c..099d986 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
mktrayicon: mktrayicon.c
- ${CC} `pkg-config --cflags gtk+-3.0` -o $@ $< `pkg-config --libs gtk+-3.0` `pkg-config --cflags --libs x11`
+ ${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
diff --git a/mktrayicon.c b/mktrayicon.c
index a0fed9a..8584783 100644
--- a/mktrayicon.c
+++ b/mktrayicon.c
@@ -52,6 +52,8 @@ struct item {
char *name;
char *action;
} * onmenu;
+char *onscrollup = NULL;
+char *onscrolldown = NULL;
int menusize = 0; // number of menu entries
GtkWidget *menu = NULL;
@@ -87,6 +89,30 @@ void tray_icon_on_menu(GtkStatusIcon *status_icon, guint button,
}
}
+void tray_icon_on_scroll(GtkStatusIcon *status_icon, GdkEventScroll *event,
+ gpointer user_data) {
+ char *i = NULL;
+ switch (event->direction) {
+ case GDK_SCROLL_UP:
+ i = "up";
+ if (onscrollup != NULL && fork() == 0)
+ execl("/bin/sh", "sh", "-c", onscrollup, (char *)NULL);
+ break;
+ case GDK_SCROLL_DOWN:
+ i = "down";
+ if (onscrolldown != NULL && fork() == 0)
+ execl("/bin/sh", "sh", "-c", onscrolldown, (char *)NULL);
+ break;
+ }
+
+ if (i != NULL) {
+ #ifdef DEBUG
+ printf("scroll %s\n",i);
+ #endif
+
+ }
+}
+
gboolean set_tooltip(gpointer data) {
char *p = (char *)data;
if (*p == '\0') {
@@ -403,6 +429,20 @@ outer:
gtk_widget_show_all(menu);
free(param);
break;
+ case 'R': /* mouse scroll up */
+ if (onscrollup != NULL) {
+ free(onscrollup);
+ }
+ 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);
+ break;
default:
fprintf(stderr, "Unknown command: '%c'\n", *buf);
if (param != NULL) {
@@ -428,6 +468,8 @@ static GtkStatusIcon *create_tray_icon(char *start_icon) {
G_CALLBACK(tray_icon_on_click), NULL);
g_signal_connect(G_OBJECT(tray_icon), "popup-menu",
G_CALLBACK(tray_icon_on_menu), NULL);
+ g_signal_connect(G_OBJECT(tray_icon), "scroll-event",
+ G_CALLBACK(tray_icon_on_scroll), NULL);
gtk_status_icon_set_visible(tray_icon, TRUE);
return tray_icon;
bgstack15