LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Trying to trigger xautolock from opening lid to laptop (https://www.linuxquestions.org/questions/slackware-14/trying-to-trigger-xautolock-from-opening-lid-to-laptop-4175617881/)

drew2x 11-18-2017 10:55 AM

Trying to trigger xautolock from opening lid to laptop
 
Hello,

I've managed to get xautolock to trigger Suckless.org's "slock" after 15 minutes of idling from my xinitrc. However, I'm having a hard time figuring out how to have the screen locked after shutting and opening the lid of my laptop. I found the lid action on a previous thread, so I managed to get pm-suspend working. I tried adding the following to my /etc/acpi/events/lid file to no avail.. not sure what I'm missing or if I'm just attempting this from the wrong location. As I type this I'm thinking maybe I need to reverse and have it called on wake?

Code:

event=button/lid LID close
action=/usr/bin/slock && /usr/sbin/pm-suspend


GazL 11-19-2017 05:39 AM

The problem you have is that the acpid events are handled outside of the users X process environment, so slock running in the event handler will have no connection to the user or the Xserver.

The way to workaround that is to have the acpid handler send some sort of signal to a screenlocker daemon process running within the users X environment.

A quick and dirty one knocked up in shellscript might look something like this:
/usr/local/bin/lid-locker:
Code:

#!/bin/sh

lockscreen()
{
  xlock -mode blank
}

trap lockscreen SIGUSR1
trap exit SIGTERM SIGINT

echo lid-locker PID: $$
trap -p

while :
do
  sleep 1d &
  while ! wait
  do
    :
  done
done

Have that started in the background from your xsession/xinitrc and then the acpid script just needs to
pkill --signal USR1 -x lid-locker


There might be more modern ways of doing something like this involving udev, or dbus, but I don't have much knowledge of those.

Hope that gives you some ideas.

drew2x 11-20-2017 02:18 AM

That makes sense, I'm going to play around with this script idea and see if I can get it working. For the moment I figured out how to setup a shortcut to trigger slock with F12 in dwm before I close the lid. Thanks! I will report my luck.


All times are GMT -5. The time now is 10:46 PM.