You are not logged in.

#1 2018-08-30 21:43:12

zoltansz
Member
Registered: 2018-08-30
Posts: 9

[SOLVED] lock screen upon lid close

Hi,

I would like to lock the screen when I close the lid of my laptop (on Gnome).

What I did is as follows.

  1. In  '/etc/systemd/logind.conf' I set:

    HandleLidSwitch=lock 
  2. I installed 'slock', the locker itself.

  3. I installed 'xss-lock', which to my understanding listens to the 'lock' event.

  4. Following this thread, I issued

    $ xss-lock slock

    to inform xss-lock which locker I would like to use. At this step I get the error:

    ** (xss-lock:4385): WARNING **: 22:57:23.238: Error getting current session: GDBus.Error:org.freedesktop.login1.NoSessionForPID: PID 4385 does not belong to any known session

    and the screen does not lock upon closing the lid.


In addition I tried:

  1. In  '/etc/systemd/logind.conf' if I set:

    HandleLidSwitch=poweroff

    it works like a charm; it powers off the laptop...

  2. 'slock' itself also works nicely.

  3. Google-ing the error; I did not find anything relevant.

Any ideas how to handle the error? Thanks.

Last edited by zoltansz (2018-08-31 23:07:14)

Offline

#2 2018-08-30 22:53:32

zoltansz
Member
Registered: 2018-08-30
Posts: 9

Re: [SOLVED] lock screen upon lid close

Note: before the 'xss-lock' adventure I tried systemd-lock-handler. Here, after installing python-txdbus and systemd-lock-handler I followed the recipe at the url.

I edited '/etc/systemd/logind.conf' and set

HandleLidSwitch=lock

followed by

$ systemctl --user enable --now systemd-lock-handler.service

=>

Created symlink /home/zoltan/.config/systemd/user/default.target.wants/systemd-lock-handler.service → /usr/lib/systemd/user/systemd-lock-handler.service.

Since the screen lock still did not take effect upon lid close I went for

$ cat /usr/lib/systemd/user/systemd-lock-handler.service

which produces

[Unit]
Description=Logind lock event to systemd target translation
Documentation=https://github.com/hobarrera/systemd-lock-handler

[Service]
ExecStart=/usr/bin/systemd-lock-handler

[Install]
WantedBy=default.target

Thus, I issued

$ /usr/bin/systemd-lock-handler

which gives

Traceback (most recent call last):
  File "/usr/bin/systemd-lock-handler", line 5, in <module>
    from twisted.internet import defer, reactor
ModuleNotFoundError: No module named 'twisted'

but 'python-txdbus' installed 'python-twisted'.

Last edited by zoltansz (2018-08-30 23:21:11)

Offline

#3 2018-08-31 21:22:27

tejonaco
Member
Registered: 2018-08-05
Posts: 37

Re: [SOLVED] lock screen upon lid close

I supose that you want to suspend or hibernate when you close the lid, in this case yo should type
"HandleLidSwitch=suspend" or "HandleLidSwitch=hibernate"
and clean any other change that you made.

If you only want to lock the screen and let the computer on, maybe there is a key like XF86LidSwitch key (in xorg) that lets you made a shortcut with xbindkeys and xdotool.

Last edited by tejonaco (2018-08-31 21:22:56)

Offline

#4 2018-08-31 21:29:44

zoltansz
Member
Registered: 2018-08-30
Posts: 9

Re: [SOLVED] lock screen upon lid close

Thanks for the quick feedback. I am interested in locking only by lid closing (no suspend, ...).

Last edited by zoltansz (2018-08-31 21:34:38)

Offline

#5 2018-08-31 22:56:53

tejonaco
Member
Registered: 2018-08-05
Posts: 37

Re: [SOLVED] lock screen upon lid close

In arch wiki lock appears like a valid option in logind.conf, maybe you have to install gnome-screensaver.

Offline

#6 2018-08-31 23:00:58

zoltansz
Member
Registered: 2018-08-30
Posts: 9

Re: [SOLVED] lock screen upon lid close

I managed to find a solution via acpid and this thread. Summary:

  1. Install slock, the (picked) screen locker.

  2. Set in '/etc/systemd/logind.conf':

    HandleLidSwitch=ignore
  3. Install acpid, who will handle the 'lid close' event. 

  4. Enable and start 'acpid' immediately:

    # systemctl enable --now acpid
  5. Set the action in '/etc/acpi/handler.sh' (thread: $1=button/lid, $3=close) to

    DISPLAY=:0 su -c - zoltan /usr/bin/slock

Last edited by zoltansz (2018-08-31 23:14:59)

Offline

Board footer

Powered by FluxBB