Proper Integration with the Panel

Since the applets appear as part of the panel to users, it is important that they behave in a consistent way. A few steps can be completed to achieve proper integration.

Panel Background

The panel can have different types of background, depending on how the user configures the panel. By default, applets do not respect the background that is configured and can therefore look out of place.

The panel_applet_set_background_widget() function can be used to automatically have the right background drawn for a specific widget. Just using this function on the PanelApplet object itself, or its child is usually enough to have proper background integration.

In some rare cases, though, panel_applet_set_background_widget() will not be enough. The solution is then to connect to the "change-background" signal of the PanelApplet object: it will be emitted when the background has changed, and it will provide the cairo_pattern_t pattern to use as a basis to draw the background.

Panel Lockdown

The panel has proper support for lockdown, and when it is locked down, it is expected that all applets behave consistently in a lockdown mode too. This generally means that the preferences of the applet should not be accessible, but it could also imply a restriction on the behavior of the applet.

The panel_applet_get_locked_down() function can be used to query the state of the panel lockdown. It is also possible to react to changes by monitoring the "locked-down" property of the PanelApplet object. You can achieve this by connecting to the "notify::locked-down" event.

In most cases, the GBinding API is enough to respect the panel lockdown: g_object_bind_property() can be used to automatically update the visiblity of a menu item in the context menu of the applet. In the following example, the "HelloWorldPrefs" action (which is an action from the context menu) will only be displayed if the panel is not locked down.

1
2
3
4
action = gtk_action_group_get_action (action_group, "HelloWorldPrefs");
g_object_bind_property (applet, "locked-down",
                        action, "visible",
                        G_BINDING_DEFAULT|G_BINDING_INVERT_BOOLEAN|G_BINDING_SYNC_CREATE);

Of course it is also possible to use g_object_bind_property() to change the visibility of widgets that appear outside of the context menu, like a button in a window.