Notes on Desktop Notifications

seninha.org
2021-08-10

A desktop notification is a small popup window that notifies the user of some event. In modern X11 desktop environments, desktop notifications (or only “notifications”, for short) are created and managed by a notification server, which receives notification requests from applications via DBus, as specified by the Desktop Notification Specification.

Using a notification server centralizes how notifications are managed, and provides the user benefits such as notification history and a unified look-and-feel. However, there are stuff notifications in a environments such as KDE, Windows and macOS can do that cannot be simulated by a notification server.

There's a limit in how descriptive a notification requested by an application to the server can be. Notifications are usually limited to an icon, a title and body in rich text, and maybe some buttons. More complex notifications such as a calendar, or a download progress monitor (or even a full-featured application) are not supported.

KDE notification
KDE notification

Notifications in X11 are essentially override-redirect windows, that is, windows that are not managed by the window manager.

A regular window can be anything and can have anything drawn on it, but the contents of a notification window is usually limited by the language in which notifications are described to the server. A solution to make notifications more powerful is to make them regular (non override-redirect) windows to be managed by the window manager.

For this to be feasible, a GUI application should create its own notification window, tag it as being of the notification type, and rely on the window manager to display the notification correctly.

The main benefit of leting the window manager manage notification windows is the uniform placement of the notification based on the position of windows, gaps, docks and taskbars. Also, notifications would be decorated uniformly following the window manager theme. Another benefit is that the notification window could be minimized to be dealt with later. When the notification timer is over, the window manager would close the window.

Notification windows could then be whatever the application toolkit is capable of. Calendar notifications, download progress monitors, or other kinds of notifications could be created by applications and seamlessly mapped on the screen by the window manager.

The ewmh even reserves a window type for notifications: the _NET_WM_WINDOW_TYPE_NOTIFICATION type. But this window type is only relevant to the compositor, not to the window manager, as notifications are usually override-redirect windows.

Shod, the window manager I'm developing, does that: it manages non override-redirect windows that are of the notification type. In the image below you can see how the notification borders looks like the regular window borders. The placement of the notifications is handled by the window manager and obeys the gap that tiled windows have.

notifications in shod
notifications in shod

The way shod manages notification is still experimental. Notifications are created by xnotify, a notification program. I will further explore the idea of an application to create its own notifications in future projects of mine.

Removing the notification server, and giving the power of creating the notification window to the application would require more code on our window managers. But, in the end, that's what window managers do: they manage windows.