1
1
<?xml version="1.0" standalone="no"?>
2
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
3
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
4
<!ENTITY PanelApplet SYSTEM "xml/panel-applet.xml">
5
<!ENTITY PanelAppletGConf SYSTEM "xml/panel-applet-gconf.xml">
2
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
3
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
4
<book id="index" xmlns:xi="http://www.w3.org/2003/XInclude">
8
<book id="libpanel-applet">
10
7
<title>Panel Applet Library Reference Manual</title>
13
<firstname>Mark</firstname>
14
<surname>McLoughlin</surname>
17
<email>mark@skynet.ie</email>
26
<holder>Sun Microsystems, Inc.</holder>
31
This manual documents the interfaces of the panel applet
32
library for GNOME 2.x and a short guide to porting applets from
33
the GNOME 1.x interfaces.
39
<chapter id="applet-writing">
40
<title>Writing Applets</title>
42
<para>Writing applets is very simple. You take some boiler plate
43
code like below, change a couple of things and write the code that
44
implements your widgetry. The hardest part is writing your widgetry -
45
and its completely up to yourself how hard that should be.
48
<sect1 id="hello-world">
49
<title>Hello World Applet</title>
51
<para>As usual, following the pointless tradition of starting with
52
an example of how get 'Hello World' on the screen in some form, here's
53
just about the simplest applet you could write.
57
#include <string.h>
59
#include <panel-applet.h>
60
#include <gtk/gtklabel.h>
63
hello_applet_fill (PanelApplet *applet,
69
if (strcmp (iid, "OAFIID:My_HelloApplet") != 0)
72
label = gtk_label_new ("Hello World");
73
gtk_container_add (GTK_CONTAINER (applet), label);
75
gtk_widget_show_all (GTK_WIDGET (applet));
81
PANEL_APPLET_BONOBO_FACTORY ("OAFIID:My_HelloApplet_Factory",
83
"TheHelloWorldApplet",
89
<para>The code here is very similar to writing a normal Bonobo
90
control. You define a factory using PANEL_APPLET_BONOBO_FACTORY(),
91
passing it a factory function like hello_applet_fill().
94
<para>libpanel-applet automatically creates a #PanelApplet object
95
for you, passing this to your factory method. Here, you should fill
96
the applet with your widgets just like a #GtkBin. For example, if you
97
were writing a cdplayer applet you would create a #GtkHBox, pack the
98
hbox with the cdplayer buttons and in turn add the hbox to the applet.
103
<sect1 id="server-files">
104
<title>Bonobo Activation .server Files For Applets</title>
106
<para>Since an applet is a bonobo component, you must write
107
a .server file so that the bonobo activation daemon is aware that
108
your component exists and how to activate it. Copy and paste is
114
<oaf_server iid="OAFIID:My_HelloApplet_Factory" type="exe"
115
location="test-bonobo-applet">
117
<oaf_attribute name="repo_ids" type="stringv">
118
<item value="IDL:Bonobo/GenericFactory:1.0"/>
119
<item value="IDL:Bonobo/Unknown:1.0"/>
120
</oaf_attribute>
121
<oaf_attribute name="name" type="string" value="Hello World Applet Factory"/>
122
<oaf_attribute name="description" type="string" value="My first applet factory"/>
125
<oaf_server iid="OAFIID:My_HelloApplet" type="factory"
126
location="OAFIID:My_HelloApplet_Factory">
128
<oaf_attribute name="repo_ids" type="stringv">
129
<item value="IDL:GNOME/Vertigo/PanelAppletShell:1.0"/>
130
<item value="IDL:Bonobo/Control:1.0"/>
131
<item value="IDL:Bonobo/Unknown:1.0"/>
132
</oaf_attribute>
133
<oaf_attribute name="name" type="string" value="Hello World Applet"/>
134
<oaf_attribute name="description" type="string" value="My first applet for the GNOME2 panel"/>
135
<oaf_attribute name="panel:icon" type="string" value="gnome-applets.png"/>
140
<para>Probably the most important thing to note here is that, unlike
141
.server files for other bonobo components, applet .server files contain
142
a special attribute called 'panel:icon'. This is used by the panel to display
143
an entry for the applet in the 'Add to Panel' dialog.
147
<sect1 id="applet-popups">
148
<title>Defining a Popup Context Menu</title>
150
<para>FIXME: write</para>
153
<sect1 id="panel-signals">
154
<title>Detecting Changes in the Panel.</title>
156
<para>FIXME: write</para>
159
<sect1 id="session-saving">
160
<title>Session/Preference Saving.</title>
162
<para>FIXME: write</para>
165
<sect1 id="multi-applets">
166
<title>Multiple Applets</title>
168
<para>FIXME: write</para>
173
<chapter id="applet-porting">
174
<title>Porting Applets from the GNOME 1.x interfaces</title>
176
<para>In GNOME 1.x the applet interface lived in a header called
177
<filename>applet-widget.h</filename>. The interface was based on GOAD,
178
the GNOME 1.x object activation framework. A new interface was
179
designed for GNOME 2.x using the power of bonobo UI embedding and the
180
new object activation framework, bonobo-activation. The interface is
181
intended to be easy to use, cruft free, but semantically similar to
182
the old API in order to make porting relatively painless.</para>
184
<simplesect id="applet-porting-activation">
185
<title>Applet Activation</title>
187
<para>The first thing to change when porting to the new API is
188
the header. Include <filename>panel-applet.h</filename> instead of
189
<filename>applet-widget.h</filename>.</para>
191
<para>Next you need to change how the applet is activated.
192
Browsing through old applet's code, its obvious that this was done in
193
various ways in the past. The best advice is to hunt out the calls to
194
applet_widget_init, applet_widget_new and applet_widget_add.
195
applet_widget_new and applet_widget_add are now effectively merged
196
into one call panel_applet_new, to which the top-level widget of the
197
applet should be passed. applet_widget_init is not neccessary anymore.
198
So the new code should look something like this</para>
201
#include <panel-applet.h>
203
static BonoboObject *
209
* The old code setting up the applet widgetry
210
* goes here. So effectively delete calls to
211
* applet_widget_init and applet_widget_new
212
* and the replace applet_widget_add with a call
213
* to panel_applet_new.
216
applet = panel_applet_new (label);
218
return BONOBO_OBJECT (panel_applet_get_control (applet));
221
static BonoboObject *
222
blah_applet_factory (BonoboGenericFactory *this,
226
BonoboObject *applet = NULL;
228
if (!strcmp (iid, "OAFIID:BlahApplet"))
229
applet = blah_applet_new ();
235
PANEL_APPLET_BONOBO_FACTORY ("OAFIID:BlahApplet_Factory",
242
<para>You should use PANEL_APPLET_BONOBO_FACTORY or
243
PANEL_APPLET_BONOBO_SHLIB_FACTORY depending on whether you want the
244
applet to be out of process or in process.</para>
248
<simplesect id="applet-porting-activation-files">
249
<title>Activation files</title>
251
<para>The next thing to do may be to port from a
252
<filename>.gnorba</filename> file to a bonobo-activation
253
<filename>.server</filename> file. You no longer need a .desktop file
254
for applets. A <filename>.gnorba</filename> looks something like this
260
repo_id=IDL:GNOME/Applet:1.0
262
location_info=blah-de-blah
265
<para>Your <filename>.server</filename> file should look like
271
<oaf_server iid="OAFIID:BlahApplet"
273
location="blah-de-blah-2">
275
<oaf_attribute name="repo_ids" type="stringv">
276
<item value="IDL:Bonobo/GenericFactory:1.0""/>
277
<item value="IDL:Bonobo/Unknown:1.0"/>
278
</oaf_attribute>
279
<oaf_attribute name="name" type="string" value="Blah Factory"/>
280
<oaf_attribute name="description" type="string" value="Blah De Blah"/>
284
<oaf_server iid="OAFIID:BlahApplet"
286
location="OAFIID:BlahApplet_Factory">
288
<oaf_attribute name="repo_ids" type="stringv">
289
<item value="IDL:GNOME/PanelAppletShell:1.0"/>
290
<item value="IDL:Bonobo/Control:1.0"/>
291
<item value="IDL:Bonobo/Unknown:1.0"/>
292
</oaf_attribute>
293
<oaf_attribute name="name" type="string" value="Blah Applet"/>
294
<oaf_attribute name="description" type="string" value="Blah De Blah"/>
295
<oaf_attribute name="panel:icon" type="string" value="blah-de-blah.png"/>
302
<para>A lot of this should be copied and pasted. The most
303
important bit is "panel:icon" which specfies the icon
304
that should be displayed in the "Add to Panel" dialog.</para>
308
<simplesect id="applet-porting-menus">
309
<title>Context Menu</title>
311
<para>Most applets also place extra menu items into it context
312
menu. It might be a good idea to port this next. In GNOME 1.x this was
313
done using the applet_widget_register_stock_callback API call. In
314
GNOME 2.x 3 things must be done</para>
317
<listitem><para>An xml desription of the popup menu must be
318
written.</para></listitem>
319
<listitem><para>A description of the verbs must be prepared.
320
This is basically a list of callbacks to be call when a certain menu
321
item is clicked in the popup.</para></listitem>
322
<listitem><para>The menu is registered using a call to
323
panel_applet_setup_menu.</para></listitem>
326
<para>The xml description should look something like this
330
static const char fish_menu_xml [] =
331
"<popup name=\"button3\">\n"
332
" <menuitem name=\"Properties Item\" verb=\"BlahProperties\" _label=\"Properties ...\"\n"
333
" pixtype=\"stock\" pixname=\"gtk-properties\"/>\n"
334
" <menuitem name=\"Help Item\" verb=\"BlahHelp\" _label=\"Help\"\n"
335
" pixtype=\"stock\" pixname=\"gtk-help\"/>\n"
336
" <menuitem name=\"About Item\" verb=\"BlahAbout\" _label=\"About ...\"\n"
337
" pixtype=\"stock\" pixname=\"gnome-stock-about\"/>\n"
341
<para>This could also be in a seperate
342
<filename>.xml</filename> file and loaded with
343
panel_applet_setup_menu_from_file. The description of the verbs should
344
look something like :</para>
347
static const BonoboUIVerb fish_menu_verbs [] = {
348
BONOBO_UI_VERB ("BlahProperties", display_properties_dialog),
349
BONOBO_UI_VERB ("BlahHelp", display_help_dialog),
350
BONOBO_UI_VERB ("BlahAbout", display_about_dialog),
356
<para>This is just a list of callbacks invoked when the menu
357
items are clicked. There are other macros you may use other than
359
<filename>bonobo-ui-component.h</filename>.</para>
361
<para>To actually register the menu you just do something like
365
panel_applet_setup_menu (PANEL_APPLET (blah->applet),
371
<para>The last argument is the user_data argument passed back
372
to the callbacks.</para>
378
<chapter id="panel-applet">
379
<title>The Panel Applet Library</title>
11
<title>Panel Applet Library Overview</title>
14
Applets are small applications that are embedded in the GNOME panel. They can be used to give quick access to some features, or to display the state of something specific.
18
The Panel Applet library is what should be used to write applets as it handles all the communication with the GNOME panel. It hides all of the embedding process of the applet behind a <link linkend="PanelApplet"><type>PanelApplet</type></link> widget. It also provides <link linkend="PanelApplet"><type>PanelApplet</type></link> API to properly integrate the applet in the panel.
22
Keep in mind that starting with GNOME 3, the panel and applets are only available in the fallback mode. An applet will therefore not be usable in the default GNOME that users may use.
27
<part id="getting-started">
28
<title>Getting Started with the Panel Applet library</title>
30
<chapter id="getting-started.intro">
31
<title>Introduction</title>
34
While applets are rather simple to write, they are not the most easy form of interaction to users for two reasons: it is not intuitive how to add or remove applets for many users, and the restriction in size of applets can limit their interface. Therefore, before writing an applet, think hard whether this is the form of interaction that is best for the feature you want to provide.
38
Keep in mind that starting with GNOME 3, the panel and applets are only available in the fallback mode. An applet will therefore not be usable in the default GNOME that users may use.
43
<chapter id="getting-started.concepts">
44
<title>Concepts</title>
46
<sect2 id="getting-started.concepts.applet-types">
47
<title>Applet Types</title>
50
The applet type is the identifier representing a type of applets to the panel. It is a simple string, like <constant>HelloWorldApplet</constant> and is unique per <link linkend="getting-started.concepts.applet-factory">applet factory</link>.
55
<sect2 id="getting-started.concepts.applet-factory">
56
<title>Applet Factory</title>
59
The applet factory is an implementation detail that is mostly hidden by the Panel Applet library, but it still appears in a few places (<link linkend="PANEL-APPLET-OUT-PROCESS-FACTORY:CAPS"><function>PANEL_APPLET_OUT_PROCESS_FACTORY()</function></link>, <link linkend="PANEL-APPLET-IN-PROCESS-FACTORY:CAPS"><function>PANEL_APPLET_IN_PROCESS_FACTORY()</function></link> and <link linkend="getting-started.install.panel-applet"><filename>.panel-applet</filename> files</link>) so it is important to understand what is an applet factory.
63
The applet factory is the object that will create a new applet instance when the panel requests a new applet to be created. It is identified with a simple string id, for example <constant>HelloWorldFactory</constant>.
67
The requests the applet factory will receive from the panel specify which type of applet should be created. This is what makes it possible to have more than one applet types in one applet binary. In most cases, however, the applet factory will be specific to only one applet type. The map between applet types and the applet factory is recorded in <link linkend="getting-started.install.panel-applet"><filename>.panel-applet</filename> files</link>.
71
There is only one applet factory per applet binary, and it is always running before any applet instance is created by the applet binary. The applet factory is created via <link linkend="PANEL-APPLET-OUT-PROCESS-FACTORY:CAPS"><function>PANEL_APPLET_OUT_PROCESS_FACTORY()</function></link> or <link linkend="PANEL-APPLET-IN-PROCESS-FACTORY:CAPS"><function>PANEL_APPLET_IN_PROCESS_FACTORY()</function></link>.
76
<sect2 id="getting-started.concepts.applet-instances">
77
<title>Applet Instances</title>
80
There is no restriction as to how many instances of one applet type can be created. The user might choose to add more than one <constant>HelloWorldApplet</constant> applets to his panels. This can have some implications on the design used to write applets. The most important implication is that it is generally wrong to have global variables to keep a state specific to an applet instance.
87
<chapter id="getting-started.example">
88
<title>Hello World Example</title>
91
An example is worth a million words, so here is a simple one:
94
<example id="getting-started.example.simple">
95
<title>Hello World applet</title>
96
<programlisting language="c">
97
#include <gtk/gtk.h>
98
#include <panel-applet.h>
101
hello_world_applet_start (PanelApplet *applet)
105
label = gtk_label_new ("Hello World");
106
gtk_container_add (GTK_CONTAINER (applet), label);
107
gtk_widget_show_all (GTK_WIDGET (applet));
113
hello_world_factory_callback (PanelApplet *applet,
117
gboolean retval = FALSE;
119
if (g_strcmp0 (iid, "HelloWorldApplet") == 0)
120
retval = hello_world_applet_start (applet);
125
PANEL_APPLET_OUT_PROCESS_FACTORY ("HelloWorldFactory",
127
hello_world_factory_callback,
133
Here are the few things that are important in this example:
139
<link linkend="PANEL-APPLET-OUT-PROCESS-FACTORY:CAPS"><function>PANEL_APPLET_OUT_PROCESS_FACTORY()</function></link>: this creates an <link linkend="getting-started.concepts.applet-factory">applet factory</link> named <constant>HelloWorldFactory</constant>, and each time this applet factory will create an applet instance, it will call <function>hello_world_factory_callback()</function> with a <link linkend="PanelApplet"><type>PanelApplet</type></link> object already created.
144
<function>hello_world_factory_callback()</function>: this checks if the request to create an applet instance is for an <link linkend="getting-started.concepts.applet-types">applet type</link> supported by the <link linkend="getting-started.concepts.applet-factory">applet factory</link>. Here we can see that we only support the <constant>HelloWorldApplet</constant> applet type. This function returns <constant>TRUE</constant> on success and <constant>FALSE</constant> on failures.
149
<function>hello_world_applet_start()</function>: this is where we actually setup the <link linkend="PanelApplet"><type>PanelApplet</type></link> widget for the work the applet should do. This can include filling the widget, connecting to signals, etc.
155
While the previous example is simple, it can be useful to directly subclass the <link linkend="PanelApplet"><type>PanelApplet</type></link> type. This makes it easy to have a per-applet instance private structure, among other benefits.
158
<example id="getting-started.example.subclass">
159
<title>Hello World applet, with a PanelApplet subclass</title>
160
<programlisting language="c">
161
#include <gtk/gtk.h>
162
#include <panel-applet.h>
164
#define HELLO_WORLD_TYPE_APPLET (hello_world_applet_get_type ())
166
typedef struct _HelloWorldApplet HelloWorldApplet;
167
typedef struct _HelloWorldAppletClass HelloWorldAppletClass;
168
typedef struct _HelloWorldAppletPrivate HelloWorldAppletPrivate;
170
struct _HelloWorldApplet {
171
PanelApplet parent_object;
173
/*< private >*/
174
HelloWorldAppletPrivate *priv;
177
struct _HelloWorldAppletClass {
178
PanelAppletClass parent_class;
181
struct _HelloWorldAppletPrivate
186
static GType hello_world_applet_get_type (void) G_GNUC_CONST;
188
G_DEFINE_TYPE (HelloWorldApplet, hello_world_applet, PANEL_TYPE_APPLET);
191
hello_world_applet_init (HelloWorldApplet *applet)
193
applet->priv = G_TYPE_INSTANCE_GET_PRIVATE (applet, HELLO_WORLD_TYPE_APPLET,
194
HelloWorldAppletPrivate);
196
applet->priv->label = gtk_label_new ("Hello World");
197
gtk_container_add (GTK_CONTAINER (applet), applet->priv->label);
198
gtk_widget_show (applet->priv->label);
202
hello_world_applet_class_init (HelloWorldAppletClass *klass)
204
g_type_class_add_private (class, sizeof (HelloWorldAppletPrivate));
208
hello_world_applet_start (HelloWorldApplet *applet)
210
gtk_widget_show (GTK_WIDGET (applet));
216
hello_world_factory_callback (HelloWorldApplet *applet,
220
gboolean retval = FALSE;
222
if (g_strcmp0 (iid, "HelloWorldApplet") == 0)
223
retval = hello_world_applet_start (applet);
228
PANEL_APPLET_OUT_PROCESS_FACTORY ("HelloWorldFactory",
229
HELLO_WORLD_TYPE_APPLET,
230
(PanelAppletFactoryCallback) hello_world_factory_callback,
237
<chapter id="getting-started.context-menu">
238
<title>Using a Context Menu</title>
241
The Panel Applet library uses <type>GtkAction</type> to define menu items appearing in the context menu of the applet.
244
<sect2 id="getting-started.context-menu.content">
245
<title>Guidelines for Context Menu</title>
248
To help guarantee consistency in the interaction with applets, there are some guidelines that are recommended to follow:
254
Do not make the context menu too long: if you have more than five or six menu items, then it might be worth investing efforts on rethinking what is important in the menu.
259
For the menu item that will enable the user to configure the applet, use "Preferences" for the label, and try to avoid "Configure", "Configuration", "Settings", etc.
264
Avoid putting a "Help" menu item. The user will usually explicitly add the applet, so it is expected that he knows what the applet is about. Putting a "Help" menu item in the context menu is therefore too prominent. It might make sense to add a "Help" button in the Preferences dialog, though.
269
If you agree, avoid putting a "About" menu item. To the user, applets are not different applications but elements of one global application, the panel. Of course, this means that credits for working on the applet are not visible to the user.
276
<sect2 id="getting-started.context-menu.setup">
277
<title>Setting Up the Menu</title>
280
The only part of dealing with a context menu that is specific to applets is how to setup the context menu. Once it is setup, this is really just a matter of using <type>GtkAction</type>.
284
To setup the context menu of the applet, the <link linkend="panel-applet-setup-menu-from-file"><function>panel_applet_setup_menu_from_file()</function></link> function should be used, with a path to a <link linkend="getting-started.context-menu.xml-file">menu XML file</link> and a <type>GtkActionGroup</type> object containing all actions that are used in the menu XML file. The example below shows how to achieve this:
288
<title>Hello World applet, with a context menu</title>
289
<programlisting language="c">
290
#include <glib/gi18n.h>
291
#include <gtk/gtk.h>
292
#include <panel-applet.h>
294
/* This would usually be defined in config.h */
295
#define GETTEXT_PACKAGE "hello-world"
296
/* This would usually be defined in Makefile.am */
297
#define HELLO_WORLD_UI_DIR "/usr/share/hello-world"
299
static void hello_world_applet_prefs (GtkAction *action,
300
PanelApplet *applet);
301
static void hello_world_applet_say (GtkAction *action,
302
PanelApplet *applet);
304
static const GtkActionEntry hello_world_menu_actions [] = {
305
{ "HelloWorldPrefs", GTK_STOCK_HELP, N_("_Preferences"),
307
G_CALLBACK (hello_world_applet_prefs) },
308
{ "HelloWorldSay", GTK_STOCK_ABOUT, N_("_Say Hello"),
310
G_CALLBACK (hello_world_applet_say) }
314
hello_world_applet_prefs (GtkAction *action,
318
dialog = gtk_message_dialog_new (NULL, 0,
319
GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
321
g_signal_connect (dialog, "response",
322
G_CALLBACK (gtk_widget_destroy), NULL);
323
gtk_widget_show (dialog);
327
hello_world_applet_say (GtkAction *action,
331
dialog = gtk_message_dialog_new (NULL, 0,
332
GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
334
g_signal_connect (dialog, "response",
335
G_CALLBACK (gtk_widget_destroy), NULL);
336
gtk_widget_show (dialog);
340
hello_world_applet_start (PanelApplet *applet)
343
GtkActionGroup *action_group;
346
label = gtk_label_new ("Hello World");
347
gtk_container_add (GTK_CONTAINER (applet), label);
349
action_group = gtk_action_group_new ("Hello World Applet Actions");
350
gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
351
gtk_action_group_add_actions (action_group,
352
hello_world_menu_actions,
353
G_N_ELEMENTS (hello_world_menu_actions),
356
ui_path = g_build_filename (HELLO_WORLD_UI_DIR, "hello-world-menu.xml", NULL);
357
panel_applet_setup_menu_from_file (applet, ui_path, action_group);
360
g_object_unref (action_group);
362
gtk_widget_show_all (GTK_WIDGET (applet));
368
hello_world_factory_callback (PanelApplet *applet,
372
gboolean retval = FALSE;
374
if (g_strcmp0 (iid, "HelloWorldApplet") == 0)
375
retval = hello_world_applet_start (applet);
380
PANEL_APPLET_OUT_PROCESS_FACTORY ("HelloWorldFactory",
382
hello_world_factory_callback,
388
Here are the changes compared to the <link linkend="getting-started.example.simple">simple example</link> with no context menu:
394
We define a list of <type>GtkActionEntry</type> entries: <constant>hello_world_menu_actions</constant>. This will be used later on to build <type>GtkAction</type> objects, with their label and callback. We obviously implement the callbacks.
399
We change <function>hello_world_applet_start()</function> to define a <type>GtkActionGroup</type> object, to which we add, with <function>gtk_action_group_add_actions()</function>, <type>GtkAction</type> objects based on the <type>GtkActionEntry</type> entries. Note that the the last argument to <function>gtk_action_group_add_actions()</function> will be passed as user data to the callbacks.
404
We also change <function>hello_world_applet_start()</function> to add this <type>GtkActionGroup</type> object to the context menu of the applet, by calling <link linkend="panel-applet-setup-menu-from-file"><function>panel_applet_setup_menu_from_file()</function></link>. This function takes as argument a path to the <link linkend="getting-started.context-menu.xml-file">menu XML file</link> that will define how to display the <type>GtkAction</type> objects in the context menu.
411
<sect2 id="getting-started.context-menu.xml-file">
412
<title>Menu XML File</title>
415
The file that is used to setup menu with the <link linkend="panel-applet-setup-menu-from-file"><function>panel_applet_setup_menu_from_file()</function></link> function is a <type>GtkUIManager</type> UI definition file, without the top-level <constant><ui></constant> tag. It must only contain menuitem entries and separators. For example:
420
<menuitem name="Hello World Prefs" action="HelloWorldPrefs" />
422
<menuitem name="Hello World Say" action="HelloWorldSay" />
427
Alternatively, the <link linkend="panel-applet-setup-menu"><function>panel_applet_setup_menu()</function></link> function can be used with a string containing directly the XML.
434
<chapter id="getting-started.settings">
435
<title>Settings</title>
438
There are two main design patterns to store settings for an applet:
444
Global settings: those are settings that should be shared among all instances of the same applets. For instance, the preferred unit for temperature is something that the user will want to set only one. The way to store those settings is in no way specific to the Panel Applet library, as it should work like in any other application.
449
Per-applet instance settings: those are settings that might be different depending on the instance of an applet. For instance, an applet whose goal is to display a picture should make it possible for the user to choose a different picture for each instance of the applet. The Panel Applet library provides API to help with this.
455
There is actually a third case, which is rather rare, though: per-screen settings. It might be that some applets control some per-screen settings, like the layout of the workspaces. There is currently no API to help with this as it is a very specific case that you will probably never have to deal with for a usual applet.
458
TODO: describe settings-oriented API
461
<chapter id="getting-started.install">
462
<title>Making the Applet Visible to the Panel</title>
465
Simply installing the applet binary will obviously not be enough to make this applet working in the panel. Two files should be installed for this:
471
a <filename>.panel-applet</filename> file so that the panel knows that the applet.
476
a D-Bus service file to autostart the binary when the panel wants to create an applet.
481
<sect2 id="getting-started.install.panel-applet">
482
<title>Panel Applet File</title>
485
The <filename>.panel-applet</filename> file is a key file about the applet binary, describing the <link linkend="getting-started.concepts.applet-factory">applet factory</link> from the binary and the <link linkend="getting-started.concepts.applet-types">applet types</link> this factory can create.
489
<title>Example</title>
494
Name=Hello World Applet Factory
495
Description=Factory for the window navigation related applets
499
Description=Factory for the Hello World applet example
500
Icon=hello-world-icon
506
<title>Format</title>
508
The file must contain a <constant>Applet Factory</constant> group with the following keys:
514
<constant>Id</constant> (string): the identifier of the applet factory. This must be the same name that will be used as the first parameter to <link linkend="PANEL-APPLET-OUT-PROCESS-FACTORY:CAPS"><function>PANEL_APPLET_OUT_PROCESS_FACTORY()</function></link> or <link linkend="PANEL-APPLET-IN-PROCESS-FACTORY:CAPS"><function>PANEL_APPLET_IN_PROCESS_FACTORY()</function></link>.
519
<constant>InProcess</constant> (boolean, optional): whether the applet should be <link linkend="getting-started.in-out-process">in-process or out-of-process</link>. By default, the applet is out-of-process.
524
<constant>Location</constant> (string): the path to the applet binary. Only mandatory if <constant>InProcess</constant> is <constant>true</constant>.
529
<constant>Name</constant> (localized string, optional): the name of the applet factory. For example: <constant>Hello World Factory</constant>.
534
<constant>Description</constant> (localized string, optional): the description of the applet factory. For example: <constant>Factory for the Hello World applet example</constant>.
540
For each applet type, it must also contain a group named with the applet type identifier. Such a group must have the following keys:
546
<constant>Name</constant> (localized string): the name of the applet type. For example: <constant>Hello World</constant>.
551
<constant>Description</constant> (localized string, optional): the description of the applet type. For example: <constant>Hello World applet example</constant>.
556
<constant>Icon</constant> (string, optional): the icon name of the applet type. For example: <constant>hello-world-icon</constant>. It can also be the path to an icon, but this not recommended.
561
<constant>BonoboId</constant> (list of strings, optional): a list of bonobo id. This will tell the panel that this applet type can be used instead of a bonobo applet if the bonobo applet id is in this list.
569
<title>Installation</title>
571
The <filename>.panel-applet</filename> file must be installed in a specific directory to be discoverable by the panel. You can fetch this directory during <constant>configure</constant> withe following code:
576
LIBPANEL_APPLET_DIR=`$PKG_CONFIG --variable=libpanel_applet_dir libpanelapplet-4.0`
577
AC_SUBST(LIBPANEL_APPLET_DIR)
585
<sect2 id="getting-started.install.dbus-service">
586
<title>D-Bus Service File</title>
589
The communication between the panel and the applet factory is done over D-Bus. When creating an applet, the panel will send a message to the D-Bus service of the applet factory. If the D-Bus service is not running yet, it must be started automatically. We use D-Bus activation for this, which requires install a standard D-Bus service file. Please refer to the <ulink url="http://dbus.freedesktop.org/doc/dbus-specification.html#message-bus-starting-services">D-Bus documentation</ulink> for more information about D-Bus service files.
593
This is only needed for <link linkend="getting-started.in-out-process">out-of-process applets</link>, because in-process applets do no need to have their binary autostarted for obvious reasons.
600
<chapter id="getting-started.integration">
601
<title>Proper Integration with the Panel</title>
604
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.
607
<sect2 id="getting-started.integration.background">
608
<title>Panel Background</title>
611
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.
615
The <link linkend="panel-applet-set-background-widget"><function>panel_applet_set_background_widget()</function></link> function can be used to automatically have the right background drawn for a specific widget. Just using this function on the <link linkend="PanelApplet"><type>PanelApplet</type></link> object itself, or its child is usually enough to have proper background integration.
619
In some rare cases, though, <link linkend="panel-applet-set-background-widget"><function>panel_applet_set_background_widget()</function></link> will not be enough. The solution is then to connect to the <link linkend="PanelApplet-change-background"><function>"change-background"</function></link> signal of the <link linkend="PanelApplet"><type>PanelApplet</type></link> object: it will be emitted when the background has changed, and it will provide the <type>cairo_pattern_t</type> pattern to use as a basis to draw the background.
624
<sect2 id="getting-started.integration.lockdown">
625
<title>Panel Lockdown</title>
628
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.
632
The <link linkend="panel-applet-get-locked-down"><function>panel_applet_get_locked_down()</function></link> function can be used to query the state of the panel lockdown. It is also possible to react to changes by monitoring the <link linkend="PanelApplet--locked-down"><function>"locked-down"</function></link> property of the <link linkend="PanelApplet"><type>PanelApplet</type></link> object. You can achieve this by connecting to the <function>"notify::locked-down"</function> event.
636
In most cases, the <type>GBinding</type> API is enough to respect the panel lockdown: <function>g_object_bind_property()</function> can be used to automatically update the visiblity of a menu item in the context menu of the applet. In the following example, the <function>"HelloWorldPrefs"</function> action (which is an action from the context menu) will only be displayed if the panel is not locked down.
639
<programlisting language="c">
640
action = gtk_action_group_get_action (action_group, "HelloWorldPrefs");
641
g_object_bind_property (applet, "locked-down",
643
G_BINDING_DEFAULT|G_BINDING_INVERT_BOOLEAN|G_BINDING_SYNC_CREATE);
648
It is obviously possible to use <function>g_object_bind_property()</function> to change the visibility of widgets that appear outside of the context menu, like a button in a window.
657
<chapter id="getting-started.in-out-process">
658
<title>Out-of-Process vs In-Process</title>
661
Applets can either live in their own process ("out-of-process") or in the panel process ("in-process"). The decision to choose one or the other is done at build time, with the macro that you use to define the applet factory: <link linkend="PANEL-APPLET-OUT-PROCESS-FACTORY:CAPS"><function>PANEL_APPLET_OUT_PROCESS_FACTORY()</function></link> is used for out-of-process applets while <link linkend="PANEL-APPLET-IN-PROCESS-FACTORY:CAPS"><function>PANEL_APPLET_IN_PROCESS_FACTORY()</function></link> is used for in-process applets. Obviously, only one of those two macros can be used.
665
For most practical matters, from the applet perspective, the two options are the same. In-process applets do offer a slightly better performance when the applet is loaded, but this should not affect much the user experience. However, an in-process applet can potentially affect the whole behavior of the panel, especially in case of crashes or memory corruptions: a crash in an in-process applet will crash the whole panel. It is therefore recommended to use out-of-process applets.
669
<chapter id="getting-started.introspection">
670
<title>Writing an applet in languages other than C</title>
673
The Panel Applet library comes with support for <ulink url="http://live.gnome.org/GObjectIntrospection">GObject Introspection</ulink>. This makes it possible to write applets in the languages that have <ulink url="http://live.gnome.org/GObjectIntrospection/Users">bindings based on GObject Introspection</ulink>.
677
Here is a simple example of a python applet:
680
<title>Hello World applet, in Python</title>
681
<programlisting language="python">
682
from gi.repository import Gtk
683
from gi.repository import PanelApplet
685
def applet_fill(applet):
686
label = Gtk.Label("Hello World")
690
def applet_factory(applet, iid, data):
691
if iid != "HelloWorldApplet":
698
PanelApplet.Applet.factory_main("HelloWorldFactory",
699
PanelApplet.Applet.__gtype__,
700
applet_factory, None)
706
The only limitation of writing an applet in a language other than C is that the applet will not be able to run in the panel process: it will have to stay out-of-process. However, since it is recommended to leave applets out-of-process, this limitation is mitigated.
712
<part id="port-gnome2">
713
<title>Porting Applets from GNOME 2.x</title>
715
<refsect1 id="port-gnome2.dbus">
716
<title>Porting a D-Bus-based Applet</title>
719
There is no major issue porting a D-Bus-based applet from GNOME 2.x, from a Panel Applet library perspective. It is actually likely that the main issues will be that the applet has to be ported to GTK+ 3. Please refer to the <ulink url="http://library.gnome.org/devel/gtk3/stable/gtk-migrating-2-to-3.html">GTK+ 2 to GTK+ 3 migration guide</ulink> for this.
724
<refsect1 id="port-gnome2.bonobo">
725
<title>Porting a Bonobo-based Applet</title>
728
Please see the <ulink url="http://live.gnome.org/GnomeGoals/AppletsDbusMigration">documentation</ulink> on the wiki.
735
<part id="reference">
736
<title>API Reference</title>
738
<xi:include href="xml/applet.xml"/>
739
<xi:include href="xml/applet-factory.xml"/>
740
<xi:include href="xml/gconf.xml"/>