This post highlights how to make any DBUS notification use the demands_attention
flag, which can be used to mark the corresponding application, window, or workspace as requiring attention. This might be especially useful for e.g. users of the i3 window manager: for applications that show popup notifications (e.g. Dunst) but do not set the urgency hint, there often is no visual hint after the popup has disappeared.
The solution is to intercept the notification in Dunst and set the urgency hint by hand – which works with any any EWHM/NetWM compatible X window manager, including the i3 window manager. The post is long to provide some explanation, but the solution is short. Hence:TL;DR: apply a filter like the one below to your .config/dunst/dunstrc
, restart dunst, and provide a script that sets the urgency hint by hand (the one that is in ~/bin/dunst-urgent-notification.sh
in my example).
In window managers like i3 you essentially rely on that applications that need attention to not only show this in any tray or status bar application. You rely on those application to properly use the urgency hint to communicate that they need attention to the window manager they are running in, which allows the window manager to mark e.g. the workspace they app is on as being in need of attention. For example, the i3 window manager highlights the workspace symbol of the workspace that the application runs on (which indicated it needs attention) in red instead of gray.
The point is that many applications (from Thunderbird over Pidgin to Signal, and even to Skype nowadays) seem to correctly set the urgency hint, or to let you configure if the urgency hint should be set when e.g. receiving a new mail or chat message. However, the annoying problem is that certain application do still neither set the urgency hint, nor provide any configuration or extension possibility to set that flag. Skype has been among those in the past, and Slack and Discord are still among them. Missing a mail or chat message in a work environment can be problematic. In the worst case you are away from your computer for a minute, miss the popup (which likely auto-closes after a short while), and when you come back you have zero visual hint that there is something on a different workspace that needs your attention. I’ve struggled with this for a while now and have finally stumbled over a viable because quick and easy solution to this problem.
The solution comes with Dunst, the the lightweight notification daemon, which likely is in use on your system if you use a window manager like i3 or alike. Dunst receives notifications and displays them. It also allows for filtering for notifications and doing custom actions. We are going to use this filtering and custom action to set the urgency hint by hand when receiving notifications from certain applications. Additionally to this, the same mechanism can be used to e.g. suppress popups or alter their content.
The original information for the underlying configuration can be found here and here. The real helpful hint on how to use Dunst for setting the urgency hint was however posted on reddit.
To selectively filter and modify messages: in .config/dunst/dunstrc
can add a filter at the bottom of the file that looks like this (adapt to your needs):
[slack] # a name for the filter: this is just used to identify what we are doing here
appname = "Slack" # this is the application name, see below
summary = "*" # this is the filter criterion applied to the message, see below
# urgency = critical # those attributes could be used to set details of the message in the script called below
# format = "" # could be used to alter the popup text, see below
script = ~/bin/dunst-urgent-notification.sh # this is the script that is called, see below
Be aware that for changes in dunstrc to be applied to dunst you need to kill and restart dunst, e.g. via
killall dunst; notify-send foo
For the dunstrc filter above: how do we find out the application name of the application we want to apply filtering to? Use e.g. xprop
in a terminal and click into the application window of the target application. The 2nd string in WM_CLASS(STRING)
is the application name. Casing matters!
The summary is the filter that is applied to the message, e.g. a receiving a message from a certain peer, or similar. “*” applies it to all messages from the specified application class.
The script we specify in the last line is called with the following parameters in this order: appname
, summary
, body
, icon
, category
, match_transient
, and msg_urgency
. This is what we can make use of to set the urgency hint for exactly the correct window: we notify the window manager (e.g. i3) that the window for appname
needs attention, in which case the window manager knows which workspace is affected. With i3 this causes the workspace the application is on to be highlighted in red then.
As long as there is no format specified (it’s commented out above) the popup content itself with not be modified and the popup will be shown normally. If format = “” the popup itself will be suppressed completely. In any of those cases, the script in the line below will be called in addition. This means: as long as we know the application name and apply the correct filter, we e.g. invoke the urgency hint, and in addition we can freely allow, modify, or suppress the corresponding popup of the notification.
The script in ~/bin/dunst-urgent-notification.sh
contains the following (don’t forget to make it executable):
#!/bin/sh
wmctrl -r $1 -b add,demands_attention
wmctrl
thereby notifies the window manager (if we use i3, that would be the currently running i3 instance then) and sets the demands_attention
flag for the application window that is passed in the first parameter – which is the appname
that we got from the Dunst filter above. In i3 and alike, this will thereby cause the corresponding workspace to be marked as urgent, means, it will me visually marked – in addition to the popup that we get or do not get.
Finally solves a an issue that probably annoyed e.g. i3 users for a long time. Hope it helps!
PS to application developers: should you develop a new application that notifies its users in some way, consider setting the urgency hint or giving an options in the config to allow setting the urgency hint when doing a user notification. This avoids the hassle above altogether that your i3 users have to go through if they want the workspace that your app is running on to be highlighted, when a new notification happens. Thanks!