xpra icon
Bug tracker and wiki

This bug tracker and wiki are being discontinued
please use https://github.com/Xpra-org/xpra instead.


Ticket #280: testtray.c

File testtray.c, 1.4 KB (added by Antoine Martin, 9 years ago)

test tray example in C/GTK

Line 
1#include <sys/inotify.h>
2#include <gtk/gtk.h>
3#define EVENT_SIZE  ( sizeof (struct inotify_event) )
4#define EVENT_BUF_LEN     ( 1024 * ( EVENT_SIZE + 16 ) )
5void leftclick(GtkStatusIcon *si, gpointer s){popen(s,"r");} /* exec s */
6void rightclick(GtkStatusIcon *si, guint b,guint a_t, gpointer s){popen(s,"r");}
7void refresh(gpointer si, gint fd, GdkInputCondition c){    char buffer[EVENT_BUF_LEN];
8    read( fd, buffer, EVENT_BUF_LEN ); /* we are just clearing it & don't care what event type */
9    gtk_status_icon_set_from_file(si,gtk_status_icon_get_title(si));} /* redraws */
10int main(int argc, char *argv[]){   GtkStatusIcon *si; int i=1, watch, fd;
11gtk_init (&argc, &argv); /* loop through icon, tooltip, click messages */
12while (i<argc) {    fd = inotify_init(); /* get file descriptor to write on if image changes */
13    si = gtk_status_icon_new_from_file(argv[i]); /* get a status icon widget */
14    gtk_status_icon_set_title(si,argv[i]); /* hack to store the image path */
15    watch = inotify_add_watch( fd, argv[i++], IN_CREATE | IN_MODIFY | IN_MOVED_FROM );
16    gdk_input_add( fd, GDK_INPUT_READ, refresh, si ); /* inotify fd is ready for reading, refresh */
17    gtk_status_icon_set_tooltip_text(si,argv[i++]);
18    g_signal_connect(G_OBJECT(si), "activate", G_CALLBACK(leftclick),(gpointer) argv[i++]);
19    g_signal_connect(G_OBJECT(si), "popup-menu", G_CALLBACK(rightclick), (gpointer) argv[i++]);}
20gtk_main ();}