DBus-Activated Systemtray Plasmoids

In this article, I’m describing a way to dynamically load Plasmoids into the systemtray. It’s interesting for you if you develop Plasma addons, or if you’re interested in the design of Plasma by KDE.

One of the wishes that came up during the latest Plasma sprint in Barcelona was a more dynamic way of showing functionality in the systemtray, that little notification area sitting in the panel next to the clock. The systemtray can have different kinds of “things” in them: Statusnotifiers, which are basically systray icons of applications, and Plasma widgets, which allows for much more functionality and freedom in UI development. Statusnotifiers are instantiated by applications, so their lifetime is entirely in the hands of the application they belong to. For Plasma widgets, this is a bit different, they’re currently loaded on startup. Ideally, we want to load specific services on-demand, say when a specific service becomes available.

You may have guessed by the title already, this feature has now landed in Plasma Next. It was actually quite easy to do, yet it’s a very powerful feature. First, let’s see what it looks like:

This feature allows loading and unloading Plasmoids when dbus services come and go. Applets can specify in their metadata which service should control their lifecycle.

This has the following advantages:

  • We can dynamically only load widgets when they’re useful, reducing clutter in many cases
  • Applications can provide widgets that appear and disappear based on the application running
  • We can load controls for system services dynamically as they come and go
  • It makes it easier to delay loading of widgets in the systemtray until when a specific service appears, cutting down startup time
  • It makes widgets and their features more discoverable as they’ll be able to appear automatically

One immediate user for this is the media controller widget, which will now only be loaded once an MPRIS2-compatible media player is running (as indicated by a dbus interface becoming available on the session bus.)

How do you do that? It’s quite easy. Two things need to be done: the widget should indicate to be loaded into the systemtray automatically, and it needs to specify a service which triggers loading it. That’s two lines in your metadata.desktop file, looking like this for example:

X-Plasma-NotificationArea=true
X-Plasma-DBusActivationService=org.mpris.MediaPlayer2.

That’s all. Enjoy your cleaner, more dynamic systemtray!

4 Responses to “DBus-Activated Systemtray Plasmoids”

  1. Aaron Seigo says:

    Very cool that this is implemented finally; this is not a new wish, however .. it has been discussed and sketched out on whiteboards at Tokamaks in past years.

    The current implementation has a number of issues; e.g. it assumes a number of things about the pattern of the dbus service name (an RE would resolve that). It also looks like it won’t work ‘as expected’ with multiple system trays (first-come-first-gets could lead to some appearing in one tray and other widgets in another), though now that xembed has been dropped there is no reason the manager needs to remain a singleton. It could instead be merged with Host with each instance managing its own set of icons and that problem would go away. This ought to make a number of things simpler in the code, not to mention resolve porting bugs such as how the manager is never cleaned up (despite the ref counting). It will be a bit more overhead in the case of multiple trays, but one can probably safely assume that not only will the overhead be minimal (it’s ‘just’ data, not UI) but on systems that have need for multiple trays they also have more resources to throw at things. (Which is to say, no resource constrained mobile device is going to require multiple trays ..)

    • sebas says:

      The manager has a couple of problems right now, which we’re still ironing out. The multiple trays issue is among these.

  2. gaboo says:

    This frameworks and Plasma Next thing is getting exciting :)
    Thanks for sharing!

  3. enoop says:

    I also noticed a button on the system tray widget that looks like it is used to toggle if the widget stays open after losing focus. Am I right on my understanding of this, and if so will this be universally applied to widgets in plasma-next? (sorry for being off topic)