2007-09-19

Tray icons in DWM

DWM is a pretty neat window manager—it's very flexible and can be customized exactly to suit one's needs: I've tried several dynamic tiling managers, and so far only DWM doesn't get in my way and actually is more comfortable than traditional WMs.

Configurability of DWM may sound strange to some: there is none. All customization is done through editing the source code. This may seem daunting, but it really isn't: there isn't much code (below 2000 SLOC) and it's all so clear, that even someone without a background on X11 can get to hacking and learn something in the process. Plus, many immediately configurable settings are gathered in a single header file.

Given this, even though DWM may be mean-and-lean, it's easy to extend it with any feature one would dream of. For me, it was system tray support (you know, those little 22×22 applets docked near your clock). As I'm a KDE user, I'm very much used to little conveniences such as klipper. (Yes, that's right, I'm using DWM with KDE, just by setting KDEWM environment variable.) And vanilla DWM can't handle those properly—every tray icon gets its own ordinary window, which, as you can see, isn't terribly convenient:

[a screenshot showing tray icons on vanilla DWM]

To fix that, we first need to see how tray icons are handled in X11. It turns out there is no single standard of doing that. Well, there is the FreeDesktop one, but it's overly complicated and (fortunately) not really used (yet), except maybe for Gnome. KDE3 and third-party apps use a simpler method: they set certain window property, which get spotted by the WM (or other program) which then position and/or swallow the window accordingly.

Two atoms seem to be used for that: WM_WINDOW_ROLE set to Tray Icon and _KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR pointing to the parent window. Some programs use both.

So all we need to do is spot appropriate properties and check if they're right; if either the role is tray icon, or the KDE-specific property is set at all, we can put the tray window to the right side of the screen. Here, much better:

[improved tray handling]

3 comments:

Rumplesmigskin said...

Hey, I'd be interested to know exactly how you did this. I tried using trayer for this purpose but getting it to play nice with dwm proved more involved.

Divided Mind said...

I still have the patch laying around somewhere; it's for an old version of DWM, though, I haven't updated it since I mostly use KDE 4.0 apps nowadays and it doesn't work with the new protocol -- I use stalonetray for that. I can dig it up if you want, though.

Rumplesmigskin said...

Nah, it's alright. Stalonetray looks nice, especially since it will actually _work_ with KDE apps. Cheers.