To begin with, I'm running Ubuntu 20.04. I've created a suspend@.service that hooks into sleep.target of systemd referring this guide. My goal is to display a GTK dialog before the system sleeps and here's what my config looks like -
[Unit]
Description=User suspend actions
Before=sleep.target
[Service]
User=%I
Type=notify
Environment=DISPLAY=:0
ExecStartPre=bash /home/user/myscript.sh
ExecStart=/usr/bin/sflock
ExecStartPost=/usr/bin/sleep 1
[Install]
WantedBy=sleep.target
Unfortunately, triggering suspend immediately turns off the screen though my dialog box is actually fired and shown in the background thereby holding up the system from sleeping. Pressing a button or two prompts me to login and there ... my dialog box is sitting right there. Dismissing it now immediately puts the system to sleep.
My question is, is there a way to prevent the display from going off and GDM from screen locking while hooking into sleep.target? I mean, is there a way to prioritise which suspend hook is executed first or something? Clearly GNOME is doing its thing and shutting of the screen and probably my hook is getting executed the last. Can I change this order?