Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
lock screen after resume ?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
LegionOfHell
Apprentice
Apprentice


Joined: 16 Mar 2019
Posts: 166
Location: Toronto, Canada

PostPosted: Tue Aug 20, 2019 11:33 pm    Post subject: lock screen after resume ? Reply with quote

How do I lock the screen right after a wake up ? I am using slock and pm-suspend.
Back to top
View user's profile Send private message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 7440
Location: almost Mile High in the USA

PostPosted: Wed Aug 21, 2019 12:31 am    Post subject: Reply with quote

Wonder if this question should be stickied as a FAQ as it comes up frequently. Nah, probably not.

But anyway the trick is to lock the screen _before_ you suspend. This also closes a race condition where someone could kill your lock script before it takes effect.

Which leads to the question: How do you not forget to lock the screen?

One way is to script it, and just run a script to lock the screen before setting the power state to suspend. This becomes tricky if you script it in an ACPI script because you'll need to do funky user switching, usually having to run the initial part of your script as root, and then switching to whatever user who may or may not be using the console at the time, get their X session keys (xauth) and then running the lock.

The modern way is to use a DE that handles it for you. The DE will intercept your suspend command, whether it be the suspend button or lid switch, run your lock program, and then finally suspend the machine. A well coded DE, usually using dbus, will even reset the timer for your timeout based screen lock so that if you suspend at the 9.75 minute mark and the idle timeout happens at 10 minutes, you won't get double locked.
_________________
Intel Core i7 2700K@ 4.1GHz/HD3000 graphics/8GB DDR3/180GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
Fitzcarraldo
Veteran
Veteran


Joined: 30 Aug 2008
Posts: 1822
Location: United Kingdom

PostPosted: Wed Aug 21, 2019 5:49 pm    Post subject: Reply with quote

If you're using pm-utils without a DE you can put a Bash script in /etc/pm/sleep.d/ to lock the screen. Something along the following lines might suffice:

Code:
#!/bin/sh
username=fitzcarraldo
userhome=/home/$username
export XAUTHORITY="$userhome/.Xauthority"
export DISPLAY=":0"

case "$1" in
    suspend)
        # Put here the command to lock the screen before suspending.
        /usr/bin/slock
    ;;
    resume)
        # Put here any commands (if any) you want to be run upon resuming from suspension.
    ;;
esac

_________________
Clevo W230SS: amd64 nvidia-drivers & xf86-video-intel.
Compal NBLB2: ~amd64 xf86-video-ati. Dual boot Win 7 Pro 64-bit.
OpenRC eudev elogind & KDE on both.

Fitzcarraldo's blog
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum