Ubuntu logo

App Developer

Resources

Technologies

Unity launcher

The recommended and supported way to take control of your launcher icon is to use the API provided by libunity. This library wraps a low level DBus protocol which is documented below.

Each launcher icon can be controlled remotely by a discrete LauncherEntry object. New launcher entry object may be created by call unity_launcher_entry_get_for_desktop_id (char *id); where id is the name of the desktop file shipped by the application you wish to control. For example evolution ships "evolution.desktop" or empathy ships "empathy.desktop".

LauncherEntryes are able to control 4 major components of a Launcher Icon:

Count

The first aspect they can control is the count associated with the icon. The count may be set by calling


unity_launcher_entry_set_count (UnityLauncherEntry *self, gint64 count);

This will remotely prime the count, then calling


unity_launcher_entry_set_count_visible (UnityLauncherEntry *self, gboolean visible)

can toggle its visible status. Updates to the count and other properties are live, unsetting and resetting the visibility is not require nor is it encouraged.

Progress

Progress can be set by


unity_launcher_entry_set_progress (UnityLauncherEntry *self, gdouble progress);

and made visible by calling


unity_launcher_entry_set_progress_visible (UnityLauncherEntry *self, gboolean visible);

The progress value should be between 0.0 and 1.0.

Urgency

You can set an urgency of your launcher icon by setting a boolean on the urgent property:


unity_launcher_entry_set_urgent (UnityLauncherEntry *self, gboolean urgent);

Quicklists

There are two kinds of Quicklists: the static ones which are always shown once on right-click from the launcher entry and dynamic one which are only displayed once the application is started.

Static Quicklists can provide useful entry points to the application when the application is not running. Dynamic Quicklists should provide the same functionality as the static Quicklist, augmenting it with functionality that would be useful to the user when the application is not in focus.

For example, an IM application would have a static Quicklist allowing the user to initiate a new conversation and add a new contact. When running, these options are still valuable and would therefore still be present, however the application would supplement them with a new set of options that allow the user to change their status.

Static Quicklist entries

Adding a Static Quicklist entry is very easy, all you need is to add some support to the desktop file. This is based on the desktop file formats Action Groups.

Here is what needs to be added to gnome-screenshot to support Quicklist

[…]
 Actions=Screen;Window;

[Desktop Action Screen]
Name=Take a Screenshot of the Whole Screen
Exec=gnome-screenshot
OnlyShowIn=Unity;

[Desktop Action Window]
Name=Take a Screenshot of the Current Window
Exec=gnome-screenshot -w
OnlyShowIn=Unity;

Actions is referencing a Desktop Action. Each Desktop Action references an item entry in the Quicklist. Here, we have the “Screen” and “Window” entries, corresponding to :

[Desktop Actionentry]

Then, each group have:

  • a Name=, which is the entry as it’s displayed which should be in title case.
  • an Exec= referring a command line to execute once clicked. Details on additional syntax.
  • OnlyShowIn=Unity is recommended to tell “show that entry in the Unity Springboard Quicklist” so that the file can be given upstream without the possibility of showing up in other untested desktop environments. Please let upstream projects decide if they want to have this action shown more widely.

In the desktop spec there is a full desktop file sample with actions. Here is an example of a patch for gnome-utils using the old X-Ayatana style, but shows how to format the patch, with links to ubuntu bug and forwarded upstream.

Dynamic Quicklist entries

Quicklists may also be created and appended to the launcher. To create a quicklist a root node must first be created as a container, and then child nodes are added to it. This final result may be packed into the launcher which is then shipped over the bus to Unity. Updates to the quicklist are also live. Rather than describe the entire API, an example of using quicklist (as well as progress and count) is provided below using the vala bindings.

It is important to note that the main loop must be invoked for the program to actual work. Libunity requires the usage of the main loop as work may be done async.

Quicklist elements

Quicklists can contain:

  • Textual links
  • Text with no associated action
  • Select options
  • Radio options
  • Horizontal dividers

Here are some visual designs with examples of all these elements in context:

Example code

Python

from gi.repository import Unity, GObject, Dbusmenu

loop = GObject.MainLoop()

# Pretend to be Firefox for the sake of the example
launcher = Unity.LauncherEntry.get_for_desktop_id("firefox.desktop")

# Show a count of 124 on the icon
launcher.set_property("count", 124)
launcher.set_property("count_visible", True)

# Set progress to 42% done
launcher.set_property("progress", 0.42)
launcher.set_property("progress_visible", True)

# We also want a quicklist
ql = Dbusmenu.Menuitem.new()
item1 = Dbusmenu.Menuitem.new()
item1.property_set(Dbusmenu.MENUITEM_PROP_LABEL, "Item 1")
item1.property_set_bool(Dbusmenu.MENUITEM_PROP_VISIBLE, True)
item2 = Dbusmenu.Menuitem.new()
item2.property_set(Dbusmenu.MENUITEM_PROP_LABEL, "Item 2")
item2.property_set_bool(Dbusmenu.MENUITEM_PROP_VISIBLE, True)
ql.child_append(item1)
ql.child_append(item2)

launcher.set_property("quicklist", ql)

def update_urgency():
    if launcher.get_property("urgent"):
        print "Removing urgent flag"
        launcher.set_property("urgent", False)
    else:
        print "setting urgent flag"
        launcher.set_property("urgent", True)
    return True

GObject.timeout_add_seconds(5, update_urgency)

loop.run()

Vala

/* Compile with: valac --pkg unity launcherexample.vala */
namespace LauncherExample {
  public static void main ()
  {
    /* Pretend to be evolution for the sake of the example */
    var l = Unity.LauncherEntry.get_for_desktop_id ("evolution.desktop");

    /* Show a count of 124 on the icon */
    l.count = 124;
    l.count_visible = true;

    /* Set progress to 42% done */
    l.progress = 0.42;
    l.progress_visible = true;

    /* We also want a quicklist */
    var ql = new Dbusmenu.Menuitem ();
    var item1 = new Dbusmenu.Menuitem ();
    item1.property_set (Dbusmenu.MENUITEM_PROP_LABEL, "Item 1");
    var item2 = new Dbusmenu.Menuitem ();
    item2.property_set (Dbusmenu.MENUITEM_PROP_LABEL, "Item 2");
    ql.child_append (item1);
    ql.child_append (item2);
    l.quicklist = ql;

    new MainLoop().run();
  }
}

We need your help!

Submit a tutorial

With your help, we can make this site grow to meet each developer's needs. Contribute by sharing your programming knowledge!