The ‘focus‘ word has many meanings, ranging from the optical concept of ‘good convergence of light rays generated by an object’ to the cognitive process of directing the attention to a particular target while ignoring other targets.

Now the interesting part: this concept can be used in computers too, especially in user interfaces, to direct the user to relevant information or to help him through a step-by-step process. How to do that? Since every image you see on screen is ‘on focus’ by default, you can easily unfocus unuseful information.

Blurring is the act of altering images so they appear out of focus. My Maestro[2] and other illustriuos people already talked extensively about this topic here on planet KDE. However you don’t improve the world until a technology becomes available to everybody, right?

Then some days ago I read on notmart‘s blog that plasma and kwin supported blurring the background on windows.. so I rebuilt KDE4 svn, restarted it, and… boy.. does it make a difference! Look at Marco’s blog or at this picture I stole from him! All the popups become instantly more readable, even krunner does, and you immediately get the feeling that the plasma panel and all the systray applets really are above your desktop and they look as they were made of some glass/plastic material.

So: why limiting this just to some plasma applets? Well, I think that the usage of this effect must be wise, however I wanted that for my app too…

…’cause I like eye-candy! 😉

After a quick tour through the beautiful KDE svn I grabbed all the needed source code and loaded Fotowall in creator. Since I already had the structure for the blur-behind on windows in place, adding the KDE4 effect was really easy. Here are some samples of what you can get:

To activate the back blur you need:

obviously an application with a transparent background. Qt easily allows to work with transparency on top-level windows.

you have to enable the “blur” effect in kwin’s “desktop effects” configuration.

a couple of lines of code to ask kwin to activate blurring to your window.

Here is the code that does the magic:

#if defined(Q_WS_X11) /** Blur behind windows (on KDE4.5+) Uses a feature done for Plasma 4.5+ for hinting the window manager to draw blur behind the window. */ #include <X11/Xlib.h> #include <X11/Xatom.h> #include <QX11Info> static bool kde4EnableBlurBehindWindow(WId window, bool enable, const QRegion ®ion = QRegion()) { Display *dpy = QX11Info::display(); Atom atom = XInternAtom(dpy, "_KDE_NET_WM_BLUR_BEHIND_REGION", False); if (enable) { QVector<QRect> rects = region.rects(); QVector<quint32> data; for (int i = 0; i < rects.count(); i++) { const QRect r = rects[i]; data << r.x() << r.y() << r.width() << r.height(); } XChangeProperty(dpy, window, atom, XA_CARDINAL, 32, PropModeReplace, reinterpret_cast<const unsigned char *>(data.constData()), data.size()); } else { XDeleteProperty(dpy, window, atom); } } #endif

And then you can activate the blur on the caller widget with:

kde4EnableBlurBehindWindow(winId(), true);

You could add the back blur to your application too, however I advise you that the interface is not standardized, so don’t blame either me or the kwin authors if something changes. Here is another picture, because everybody loves them 😉

And now, as a side note, a picture from my new work place: the beautiful city of San Diego, blessed by the sun and by a ton of great programmers that by some chance happen to be co-workers of me 😉 With all the blue sky and long days, I can’t imagine a more inspiring place for making new blog posts and code experiments!

Notes:

[1] obviously the name is completely made up 😉

[2] Italian word meaning “teacher” as in school or life teacher