Header de l'objet trayicon
L'objet trayicon
Programme appelant
/* System Tray Example */
#include <gtk/gtk.h>
#include "eggtrayicon.h"
static gboolean tray_clicked (GtkWidget *event_box, GdkEventButton *event, gpointer data)
{
gtk_main_quit();
}
int main(int argc, char *argv[])
{
static EggTrayIcon *tray_icon;
/* This variable will contain the actual image to be displayed in the tray. */
static GtkWidget *tray_icon_image;
/* This variable will contain the tooltip to be attached to the tray icon. */
static GtkTooltips *tray_icon_tooltip;
/* This variable will contain the eventbox for the tray icon.
* check http://developer.gnome.org/doc/API/gtk/gtkeventbox.html*/
GtkWidget *eventbox;
GdkPixbuf *pixbuf;
gtk_init(&argc, &argv);
/* Creation of the tray icon */
tray_icon = egg_tray_icon_new ("MySystemTray");
/* Loads the image */
pixbuf = gdk_pixbuf_new_from_file ("../../gtk.png", NULL);
/* Copies the image to the tray_icon_image variable */
tray_icon_image = gtk_image_new_from_pixbuf (pixbuf);
eventbox = gtk_event_box_new ();
/* Display the eventbox on the screen */
gtk_widget_show (eventbox);
/* Adds the tray icon image onto the event box */
gtk_container_add (GTK_CONTAINER (eventbox), tray_icon_image);
/* Adds the eventbox to the tray icon */
gtk_container_add (GTK_CONTAINER (tray_icon), eventbox);
/* Connect a function to the user clicking on the tray icon */
g_signal_connect (G_OBJECT (eventbox), "button_press_event",
G_CALLBACK (tray_clicked), NULL );
/* Create the tooltip for the tray icon */
tray_icon_tooltip = gtk_tooltips_new ();
/* Attaching the tooltip to the tray icon and giving it a text */
gtk_tooltips_set_tip (tray_icon_tooltip, GTK_WIDGET (tray_icon),
"This is my system tray icon", NULL);
gtk_widget_show_all (GTK_WIDGET (tray_icon));
gtk_main();
return 0;
}
Script de compilation
#!/bin/sh
gcc -c *.c `pkg-config --cflags gtk+-2.0`
gcc -o app *.o `pkg-config --libs gtk+-2.0`