Writing Applets

Hello World Applet
UkuiComponent Activation .server Files For Applets
Defining a Popup Context Menu
Detecting Changes in the Panel.
Session/Preference Saving.
Multiple 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 <ukui-panel-applet.h>
#include <gtk/gtklabel.h>

static gboolean
hello_applet_fill (UkuiPanelApplet *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;
}


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

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

libukui-panel-applet automatically creates a #UkuiPanelApplet 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.