Panel Orientation

How to tell which way the panel on which your applet sits is fairly simply. You bind the "change_orient" signal of the applet. To modify our original hello applet, we'd do:

Example 10. Freshman Orientation

#include <config.h>
#include <applet-widget.h>

/*this is when the panel orientation changes*/
static void
applet_change_orient(GtkWidget *w, PanelOrientType o, gpointer data)
{
        switch(o) {
                case ORIENT_UP: puts("ORIENT UP"); break;
                case ORIENT_DOWN: puts("ORIENT DOWN"); break;
                case ORIENT_LEFT: puts("ORIENT LEFT"); break;
                case ORIENT_RIGHT: puts("ORIENT RIGHT"); break;
        }
}

int
main(int argc, char **argv)
{
        GtkWidget *applet;
        GtkWidget *label;

        /* Initialize the i18n stuff */
        bindtextdomain (PACKAGE, GNOMELOCALEDIR);
        textdomain (PACKAGE);

        /* intialize, this will basically set up the applet, corba and
           call gnome_init */
        applet_widget_init("hello_applet", NULL, argc, argv, NULL, 0, NULL);

        /* create a new applet_widget */
        applet = applet_widget_new("hello_applet");
        /* in the rare case that the communication with the panel
           failed, error out */
        if (!applet)
                g_error("Can't create applet!\n");

        /* create the widget we are going to put on the applet */
        label = gtk_label_new(_("Hello There!"));
        gtk_widget_show(label);

        /*we have to bind change_orient before we do applet_widget_add 
          since we need to get an initial change_orient signal to set our
          initial oriantation, and we get that during the _add call*/
        gtk_signal_connect(GTK_OBJECT(applet),"change_orient",
                           GTK_SIGNAL_FUNC(applet_change_orient),
                           NULL);

        /* add the widget to the applet-widget, and thereby actually
           putting it "onto" the panel */
        applet_widget_add (APPLET_WIDGET (applet), label);
        gtk_widget_show (applet);

        /* special corba main loop */
        applet_widget_gtk_main ();

        return 0;
}