DEV Community

Christophe Colombier
Christophe Colombier

Posted on

screensaver vs dunst

This article will be about how I configured my screensaver script to disable dunst notification.

Initial setup

Please check the xautolock article I made.

Here is the screen lock script I was using for ~/bin/lockscreen.sh

#!/bin/sh

set -e

# enable the lock screen
i3lock -c 272d2d -i ~/Documents/wallpaper-lockscreen.png
Enter fullscreen mode Exit fullscreen mode

Problem

When my computer is locked, because of a meeting or a lunch break, the notification are still received by the notifier, in my case dunst

Each notification has a short timeout, you are supposed to see them when working, but when your computer is locked you don't see them

so here is what to do

#!/bin/sh

# pause notifications
dunstctl set-paused true

# enable the lock screen
i3lock --nofork -c 272d2d -i ~/Documents/wallpaper-lockscreen.png

# restore notifications
dunstctl set-paused false
Enter fullscreen mode Exit fullscreen mode

Please note the usage of --nofork with i3lock. Without it, the script simply exits when i3lock is launched, so the notifications won't be paused.

Better implementation

I love using trap, it's a good way to avoid problem.

#!/bin/sh

# using trap make sure to restore dunst even if something fails
# restore notifications when script ends
# this command is defered when the script ends
trap "dunstctl set-paused false" EXIT

# pause notifications
dunstctl set-paused true

# enable the lock screen
i3lock --nofork -c 272d2d -i ~/Documents/wallpaper-lockscreen.png
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
ccoveille profile image
Christophe Colombier

This post was inspired by the conversation that occurred here

faq.i3wm.org/question/5654/how-can...