Re-invent Your Desktop with Plasma!

Don't settle for a desktop that came out of a box; find out how to write your own Plasma widgets (aka plasmoids) and give your desktop a shot in the arm or a kick in the you-know-what.
Build Environment

For your build to succeed, you must have the Qt4 and KDE development libraries, cmake and the usual compilation tools, such as make, g++ and so on, installed onto your system. Note that this tutorial assumes a KDE version greater than or equal to 4.3.

To build your plasmoid, change directory to your plasmoid, and issue the following commands:

mkdir build
cmake -DCMAKE_INSTALL_PREFIX=`kde4-config --prefix` ..
sudo make install

Note the backticks (``) in the cmake command, which mean “substitute here the result of the evaluation of the quoted command”.

The first time you test the plasmoid, you'll have to refresh the KDE configuration cache by issuing the command:

kbuildsycoca4 --noincremental

You'll also need to run this command any time you make modifications to the plasmoid desktop file.

To test the plasmoid, run the following command:

plasmoidviewer plasmoid

Plasmoidviewer is a little test application that makes it easy to load and play with a single plasmoid without having to restart your desktop every time.

Writing Other Types of Plasmoids

In this tutorial, I've explained how to write a simple plasmoid from scratch, but I've barely scratched the surface. As I mentioned previously, Plasma is all about plugins, and writing other types of plasmoids is just as easy. You can, for example, write your own “containment”. Containments are a subset of applets, which are built to contain other applets. The panel, the desktop, or the “folder view” are all examples of containments. Being applets, they also can be used like regular applets wherever that makes sense.

You can write wallpapers, which are plugins that draw a containment's background. With these, you can draw a simple image or a more complex rendering, such as a Mandelbrot fractal or even an animated (and intractable) Earth globe!

You also can create a plasma theme, which changes the look and feel of all the applets through the usage of SVGs.

Apart from visualization, you can write a DataEngine and/or an associated Service to be able to gather information from the rest of the world. You can make a Runner, which is a plugin that responds to user queries—from “3+2” to “run command x” to “google for x” to “shut down the PC”. These are then accessible from Krunner, from menus, or even from your own applet!

All of this also is accessible through scripted languages, be it JavaScript, Ruby, Python or many others. And obviously, you can invent your own binding to Plasma by re-implementing a ScriptEngine, which has been done, for example, to be able to load simple Apple Dashboard or Edje widgets.

As you can see, there are almost infinite possibilities for expressing your creativity, and all this goodness is exposed through an intuitive and powerful API.

A Quick Look into the Future

This article was written in October 2009, when the stable version of KDE was 4.3, and Qt was at version 4.5. By the time you read this, however, both Qt 4.6 and KDE 4.4 should be available, so let's briefly outline what possibilities these new versions will offer:

  • First, Qt introduces a new animation framework, sometimes referred to as Qt Kinetic, which makes animations in our plasmoids trivial. You will be able to decide what should be animated, how that element should look at the start of the animation (for example, be at position 0,0) and how it should look at the end of it (for example, be at position 100,20, rotated 20 degrees and scaled by a factor 2), and everything will be taken care of for you. For more information, take a look at the Qt documentation (see Resources).

  • Anchor layouts, a minor improvement in Qt that might nonetheless save you from major headaches, are designed to make it possible to achieve many visual presentations with less effort.

  • Remote plasmoids is one of the most interesting things that KDE 4.4 will bring. This technology has been developed as a Google Summer of Code Project, and it allows you to transport applets, data engines and services over the network transparently. Without any more code than what you would write for a local component, you will be able (because of compression and caching algorithms) to distribute services and content between any HTTP-capable machine efficiently. Ideas include writing a lightweight server application that distributes plasmoids and/or content directly from a Web server, without requiring any graphical interface on it or perhaps built directly into your Web 2.0 application. The API to interact with this technology is, in fact, extremely simple and has a very small runtime requirement.


Free Dummies Books
Continuous Engineering


  • What continuous engineering is
  • How to continuously improve complex product designs
  • How to anticipate and respond to markets and clients
  • How to get the most out of your engineering resources

Get your free book now

Sponsored by IBM

Free Dummies Books
Service Virtualization

Learn to:

  • Define service virtualization
  • Select the most beneficial services to virtualize
  • Improve your traditional approach to testing
  • Deliver higher-quality software faster

Get your free book now

Sponsored by IBM