You are not logged in.

#1 2013-09-10 17:17:04

alomsimoy
Member
Registered: 2013-06-03
Posts: 10

[SOLVED] Run xscreensaver when I close the laptop lid

I have xscreensaver running in my archlinux, and with a systemd service, I can start it after waking up my laptop.

The problem is that I like to keep my laptop running when I close the lid (for example, to go to bed while I'm downloading a file, I like to simply close my lid), but I want to lock my computer.

In the /etc/systemd/logind.conf, there is a nice option called HandleLidSwitch, which specifies which action is invoked when the lid is closed, and there is a lock option, but It doesn't work for me.
The option suspend works fine.

Here is my /etc/systemd/logind.conf:

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# See logind.conf(5) for details

[Login]
#NAutoVTs=6
#ReserveVT=6
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root
#Controllers=
#ResetControllers=cpu
#InhibitDelayMaxSec=5
HandlePowerKey=suspend
#HandleSuspendKey=suspend
#HandleHibernateKey=hibernate
HandleLidSwitch=ignore
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
#LidSwitchIgnoreInhibited=yes
#IdleAction=ignore
#IdleActionSec=30min

Any help?

Last edited by alomsimoy (2013-09-10 18:08:33)

Offline

#2 2013-09-10 17:24:04

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [SOLVED] Run xscreensaver when I close the laptop lid

I would say that you should just have logind ignore the LidSwitch altogether.  So if it is set to ignore the lid switch, then it obviously isn't going to be entering the suspend.target (or is it the sleep.target, I can't remember).  Therefore, you are going to have to have some other way of triggering actions in response to these events.

The lid switch sends an event to udev, so you have the option of having a udev rule that responds to this, or using acpid to start this for you.  I would recommend using acpid, as it is much more flexible in what it can allow you to do.


Edit: acpid is not necessarily more flexible than a udev rule, as it relies on the udev events.  But it is a much easier method of setup since it simply relies of basic scripting in order to make it work.  It can allow for one central script (or collection of scripts) to handle all the different events that udev sends.  To see what kinds of things trigger a udev event, you can use udevadm monitor or if you install acpid, there is the acpi_listen option.

Edit2:  BTW, what is it you mean by not working?  Does it still suspend on lid close, or is your xscreensaver not started?  You need to be more explicit there.  If it is still suspending, have you rebooted or restarted logind after making those changes to logind.conf?  You can't just edit the file and have the changes implemented right away, as the configuration is parsed and the settign implemented on the service start.

Last edited by WonderWoofy (2013-09-10 17:28:05)

Offline

#3 2013-09-10 17:36:25

progandy
Member
Registered: 2012-05-17
Posts: 5,192

Re: [SOLVED] Run xscreensaver when I close the laptop lid

Apart from an udev rule or acpid there is another possible solution.
The options "lock" for HandleLidSwitch invokes the Lock() method for the systemd session. If you want to react to that, you'll have to register your screensaver for that event, which you can do with xss-lock. https://aur.archlinux.org/packages/xss-lock/ A cleaner solution for xscreensaver would be to implement the systemd events directly instead of using another daemon.

By the way, i don't use a systemd service at all. I let xss-lock with i3lock handle everything. Screensaver timeout comes from the xorg screensaver (xset s on), suspend, hibernate and lock from systemd-logind. Those events are all processed by xss-lock.

Edit: acpid is not necessarily more flexible than a udev rule, as it relies on the udev events.  But it is a much easier method of setup since it simply relies of basic scripting in order to make it work.  It can allow for one central script (or collection of scripts) to handle all the different events that udev sends.  To see what kinds of things trigger a udev event, you can use udevadm monitor or if you install acpid, there is the acpi_listen option.

Not all acpi events result in a udev event, so acpid is sometimes the only choice. The lidswitch seems to be an exception together with other power (battery) events.

Last edited by progandy (2013-09-10 17:41:25)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#4 2013-09-10 17:52:36

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [SOLVED] Run xscreensaver when I close the laptop lid

progandy wrote:

Not all acpi events result in a udev event, so acpid is sometimes the only choice. The lidswitch seems to be an exception together with other power (battery) events.

Interesting… it has been a long time since I have used acpid or read any documentation about it.  I was under the impression that it simply listened to the udev events.  Thanks for pointing this out.

Offline

#5 2013-09-10 17:57:24

alomsimoy
Member
Registered: 2013-06-03
Posts: 10

Re: [SOLVED] Run xscreensaver when I close the laptop lid

If I put ignore, it simply power off my screen until I open it, without starting xscreensaver. Same if I put lock.

I'm trying xss-lock, but I don't understand how it works...

After changing ignore to lock in HandleLidSwitch, I'm trying this:

dell-arch% xss-lock `xscreensaver-command -lock` &
[2] 24114
dell-arch% Failed to set screensaver attributes; is another one running?   <----At this point I close the lid

[2]  + exit 1     xss-lock `xscreensaver-command -lock`

Edit: Ooops, wrong code, I forgot to kill the other xss-lock

Here is the correct:

dell-arch% xss-lock `xscreensaver-command -lock` &
[1] 25408
dell-arch%                      <------ At this point I close the lid
** (xss-lock:25408): WARNING **: Error spawning locker: Falló al ejecutar el proceso hijo «xscreensaver-command:» (No existe el fichero o el directorio)

Edit2:
SOLVED!

Running xss-lock -- xscreensaver-command -lock goes great!

Now I just have to put in my openbox autostart file this:

xss-lock -- xscreensaver-command -lock &

Thanks!!

Last edited by alomsimoy (2013-09-10 18:10:39)

Offline

#6 2013-09-10 18:11:50

cris9288
Member
Registered: 2013-01-07
Posts: 348

Re: [SOLVED] Run xscreensaver when I close the laptop lid

There's another solution in the i3 wiki: create a systemd service that executes yours screensaver before sleep.target is reached.

 

/etc/systemd/system/suspend@.service
[Unit]
Description=Starts i3lock at suspend time
Before=sleep.target

[Service]
User=%I
Type=forking
Environment=DISPLAY=:0
ExecStartPre= 
ExecStart=/usr/bin/i3lock

[Install]
WantedBy=sleep.target

EDIT: Please disregard this post. As Wonderwoofy has already pointed out, I did not thoroughly read the OP, so my solution is not relevant.

Last edited by cris9288 (2013-09-10 18:41:33)

Offline

#7 2013-09-10 18:17:57

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [SOLVED] Run xscreensaver when I close the laptop lid

@cris9288, if you had read the thread, you would have seen that what you suggested is not actually possible because the sleep.target is never being activated.  The OP wanted to be able to leave the machine running on lid close, yet still have the screen locked.

Offline

#8 2013-09-10 22:14:07

Hutchism
Member
Registered: 2013-05-01
Posts: 34

Re: [SOLVED] Run xscreensaver when I close the laptop lid

@cris9288 However that was exactly what I was looking for at this hour of the day smile

Offline

Board footer

Powered by FluxBB