Panel Size

(Note: this is not included in versions of the panel prior to 1.2)

One new feature of the panel is the size support. The panel supports the following sizes:

It would be nice to let your applet pick it's layout so that it doesn't stretch the panel out of it's preffered size (the panel is always as thick as the thickest applet)

The way this works is very similiar to the way orientation works. You bind the "change_pixel_size" signal to the applet, so to modify our original hello applet, we'd do:

Example 11. The Sizes, The Keep A-Changin'

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

#ifdef HAVE_PANEL_PIXEL_SIZE
/*this is when the panel size changes*/
static void
applet_change_pixel_size(GtkWidget *w, int size, gpointer data)
{
        printf("Got size of %d pixels\n",size);
}
#endif

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);

#ifdef HAVE_PANEL_PIXEL_SIZE
        /*we have to bind change_pixel_size before we do applet_widget_add 
          since we need to get an initial change_pixel_size signal to set our
          initial size, and we get that during the _add call*/
        gtk_signal_connect(GTK_OBJECT(applet),"change_pixel_size",
                           GTK_SIGNAL_FUNC(applet_change_pixel_size),
                           NULL);
#endif

        /* 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;
}
	    

Notice the "#ifdef HAVE_PANEL_PIXEL_SIZE" line, this will make sure your applet compiles correctly even on a panel from gnome-core 1.0 which doesn't have support for multiple sizes. Note that in gnome-core 1.1.0 release there was another implementation of panel sizes which is now deprecated, so you should use the method above.

If you want to say compare to the standard sizes (You shouldn't assume that they are the only ones that exist!), you can use the PIXEL_SIZE_TINY, PIXEL_SIZE_STANDARD, PIXEL_SIZE_LARGE and PIXEL_SIZE_HUGE constants as in:

Example 12. Using Standard Pixel Sizes

if(size < PIXEL_SIZE_STANDARD) {
        ... do something for very small applet ...
} else {
        ... do something else for standard size applet ...
}