by Matthias Thoma, member of Project JEDI -- 2001 Spirit of Delphi Award Winner
This article demonstrates an easy way to add common TForms to KDEs system tray area.
The system tray is a special desktop area provided by the window manager. It is commonly used by daemons and background applications to show the status of a hardware device (like the Notebook battery, for example) or as less space consuming state indicator of an generic application (like virus scanning software). In official MS Windows terminology that part of the desktop is called the "taskbar notification area".
This article is dedicated to KDE 2 and higher solely. System trays are provided by and handled by each window manager seperately. While there exists an draft "System Tray Protocol Specification" [Pen2002] all the widely used window managers do not support it yet.
![]() |
![]() |
| KDE system tray | Windows taskbar notification area |
A KDE system tray applet is not very complicated. It is simply a usual window (TForm to stay within Kylix terminology) mapped into the system tray area. KDE Applets have normally a size of 24x24 pixels - greater sizes are ignored even if there would be enough space in the tray.
The following example demonstrates the mapping. Please create a new application, add a TTimer, put the following source in the OnCreate handler respecitvely in the OnTimer handler of the new form and compile/run the application. The form will appear in the system tray and change its color every second.
procedure TForm1.FormCreate(Sender: TObject);
var
prop: TAtom;
data: TAtom;
begin
Width := 24;
Height := 24;
BorderStyle := fbsNone;
BorderIcons := [];
prop := XInternAtom(Application.Display, '_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR', 1);
XChangeProperty(Application.Display, QWidget_winId(self.Handle), prop,
XA_WINDOW, 32, PropModeReplace, PByte(@data), 1);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Color := TColor(random(MaxInt));
end;
In the OnCreate handler the form is resized and made borderless. Otherwise you would only see the border and form caption in the system tray. Of course, this properties could set accordingly in the Object Inspector as well.
On XWindow systems the window appearance can be influenced by so called properties and "hints". You can request the window manager (give him a "hint") to show a window in a specific way, but the window manager is free to override your requests.
The same technique is used to let KDE know that your form should appear in the tray. KDE defines a special property "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR" which is added to the property list of the window.
A form in the system tray behaves the same way as a normal form - it reacts on mouse clicks with an OnClick event, you can add a popup menu, one could even show a movie within the form - there are no limitations.
I hope you know now enough about KDE system tray applets to integrate them successfully into your own applications. If you any comments or questions please feel free to contact me.
References:
[Pen2002] Havoc Pennington (2002), System Tray Protocol Specification
Updated 23 Dec 2002
since 22 Dec 2002