![]() |
![]() |
![]() |
![]() |
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 GtkAction.
To setup the context menu of the applet, the panel_applet_setup_menu_from_file()
function should be used, with a path to a menu XML file and a GtkActionGroup object containing all actions that are used in the menu XML file. The example below shows how to achieve this:
Here are the changes compared to the simple example with no context menu:
We define a list of GtkActionEntry entries: hello_world_menu_actions
. This will be used later on to build GtkAction objects, with their label and callback. We obviously implement the callbacks.
We change hello_world_applet_start()
to define a GtkActionGroup object, to which we add, with gtk_action_group_add_actions()
, GtkAction objects based on the GtkActionEntry entries. Note that the the last argument to gtk_action_group_add_actions()
will be passed as user data to the callbacks.
We also change hello_world_applet_start()
to add this GtkActionGroup object to the context menu of the applet, by calling panel_applet_setup_menu_from_file()
. This function takes as argument a path to the menu XML file that will define how to display the GtkAction objects in the context menu.