Writing Applets: Panel Applet Library Reference Manual

# Writing Applets

Writing applets is very simple. You take some boiler plate code like below, change a couple of things and write the code that implements your widgetry. The hardest part is writing your widgetry - and its completely up to yourself how hard that should be.

## Hello World Applet

As usual, following the pointless tradition of starting with an example of how get 'Hello World' on the screen in some form, here's just about the simplest applet you could write.

    #include <string.h>

    #include <mate-panel-applet.h>
    #include <gtk/gtklabel.h>

    static gboolean
    hello_applet_fill (MatePanelApplet *applet,
    		   const gchar *iid,
    		   gpointer     data)
    {
            GtkWidget *label;

            if (strcmp (iid, "OAFIID:My_HelloApplet") != 0)
    		return FALSE;

            label = gtk_label_new ("Hello World");
    	gtk_container_add (GTK_CONTAINER (applet), label);

    	gtk_widget_show_all (GTK_WIDGET (applet));

            return TRUE;
    }

    MATE_PANEL_APPLET_MATECOMPONENT_FACTORY ("OAFIID:My_HelloApplet_Factory",
                                 PANEL_TYPE_APPLET,
                                 "TheHelloWorldApplet",
                                 "0",
                                 hello_applet_fill,
                                 NULL);

The code here is very similar to writing a normal MateComponent control. You define a factory using MATE_PANEL_APPLET_MATECOMPONENT_FACTORY(), passing it a factory function like hello_applet_fill().

libmate-panel-applet automatically creates a #MatePanelApplet object for you, passing this to your factory method. Here, you should fill the applet with your widgets just like a #GtkBin. For example, if you were writing a cdplayer applet you would create a #GtkHBox, pack the hbox with the cdplayer buttons and in turn add the hbox to the applet.