Your average GTK application looks something like this:
Example 1. Non-panel application
#include <gtk/gtk.h>
int main(int argc, char **argv)
{
/* ... we build the user interface ... */
gtk_init(&argc, &argv); /* #1 */
GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL); /* #2 */
gtk_window_set_title(GTK_WINDOW(window), PACKAGE);
/* controls is the name of the container all our widgets are in */
gtk_container_add(GTK_CONTAINER(window), controls); /* #3 */
gtk_widget_show(window);
/* Everything's ready to begin our main loop */
gtk_main(); /* #4 */
return 0;
}
|
All we need now is to change the numbered lines to their GNOME panel applet equivalents:
Example 2. Panel version
#include <applet-widget.h>
int main(int argc, char **argv)
{
applet_widget_init(PACKAGE, VERSION, argc, argv,
NULL, 0, NULL); /* #1 */
GtkWidget* applet = applet_widget_new(PACKAGE); /* #2 */
applet_widget_add(APPLET_WIDGET(applet), controls); /* #3 */
gtk_widget_show(applet);
applet_widget_gtk_main(); /* #4 */
return 0;
}
|
Line #2 and #3 are pretty self-explanatory: we use the applet container instead of a GTK window to pack our widgets into it. #1 needs the PACKAGE and VERSION information for registration purposes. argc and argv are parsed for command-line options used by the applet registration mechanism (see any_applet --help for a full list). The last three arguments (unused in our example) are described in the popt documentation.
When using GTK--, since there's no wrapper for Applet_Widget yet, you'll have to use something like this: