LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Bodhi (https://www.linuxquestions.org/questions/bodhi-92/)
-   -   Both Lock and Suspend on Laptop Lid Close - Looking for command line option (https://www.linuxquestions.org/questions/bodhi-92/both-lock-and-suspend-on-laptop-lid-close-looking-for-command-line-option-4175642628/)

joozooh 11-18-2018 07:28 PM

Both Lock and Suspend on Laptop Lid Close - Looking for command line option
 
Hi there,
I've been looking all over for a way to get my laptop running Bodhi to either:
both lock the screen and suspend when closing the laptop lid,
OR
set this to option to a key-binding WITHOUT getting a prompt appear to confirm whether I'm "sure [I] want to suspend [the] computer?".
I've set the lock settings to lock when suspending and when I suspend either from system menu, or from a keyboard shortcut, this works (though with keyboard shortcuts it has the above mentioned issue of a dialogue box that appears first for confirmation, which I then need to use the touchpad to confirm.)
However, when I suspend the laptop, or call:
suspend
from the command line, the lock does not properly activate.
The laptop just suspends and when waking from sleep does not prompt for a password before returning me to my session.
I've also tried:
systemctl suspend
from the command line, but this also does not lock before suspending.

I'm currently thinking to figure out how the screen lock functions on bodhi so that I can write a shell script which activates the lock and then suspends the computer. I would then append this the ACPI binding for lid close, which will launch a command to run the shell script.
However, I can't seem to find any information anywhere on how the lock settings on bodhi work under the hood, in which files the settings exist, or how to activate them via command line.

Any help or insights regarding any of the above would be greatly appreciated.
Even somebody just pointing me to some docs where I can find the command-line commands needed to work with the enlightenment/moksha environment from a terminal, specifically the lock settings,
or,
some docs that explain which program is being used for locking the screen on bodhi under the hood, so that I can look up docs for this on my own,
would be excellent.

Thanks in advance for any help,
Jo

JWJones 11-18-2018 08:58 PM

I use slock to achieve this, via an entry in my fvwm menu (which I have named 'Lock + Sleep') that executes the following:

Code:

Exec slock & sudo sh -c 'echo -n mem > /sys/power/state'

rbtylee 11-19-2018 04:45 AM

Load the Dbus Extension module and then the command:

Code:

enlightenment_remote -desktop-lock
Locks the desktop.

And then the command

Code:

systemctl suspend
Should suspend the machine.

joozooh 11-19-2018 07:00 PM

Thanks very much for all the help so far, I've been able to really get going with this as a result, so I'm very grateful.
So far, I've been able to:
  • Install slock and test its usage
  • Set the following command to launch from a key combination:
    Code:

    slock systemctl suspend
  • Disable systemd control of Lid Switch at /etc/systemd/logind.conf by uncommenting and adjusting this line:
    Code:

    HandleLidSwitch=ignore
  • Enable acpid:
    Code:

    systemctl enable acpid
    (was previously disabled checked with):
    Code:

    $> systemctl is-enabled acpid
    disabled

  • Create and ACPID event and corresponding action for the lid close event, which actually functions to append text to a file or call a script:
    • In /etc/acpi/events/ made a file called lid:
      Code:

      event=button/lid
      action=/etc/acpi/actions/close-lid.sh %e

    • In /etc/acpi/actions made a file called close-lid.sh:
      Code:

      #!/bin/sh

      echo $1 $2 $3 $4 $5 >> /home/username/mylog
      echo "$1" | grep "button/lid" && grep -q open /proc/acpi/button/lid/*/state && exit 0

      slock

      echo after slock >> /home/username/mylog

    • THEN: Tailed mylog file with:
      Code:

      tail -f /home/username/mylog
      And get output in realtime as the file adjusts with opening and closing the lid, but no slock function.
      SO:
    • Make a file in /home/username/ called slockTest.sh and make it executable:
      Code:

      #!/bin/sh
      echo in slocktest >> /home/username/mylog
      slock
      echo still in slocktest >> /home/username/mylog

    • Test execution with:
      Code:

      /home/user/slockTest.sh
      And slock works with mylog update in realtime
    • Adjust /etc/acpi/actions/close-lid.sh:
      Code:

      #!/bin/sh

      echo $1 $2 $3 $4 $5 >> /home/username/mylog
      echo "$1" | grep "button/lid" && grep -q open /proc/acpi/button/lid/*/state && exit 0

      /home/username/slockTest.sh

      echo after slock >> /home/username/mylog

      BUT !!! slock will still not work with the lid close function..

SO:
I've done a bit more research and found this Ask Ubuntu post, which points to this guide, which I will follow next to hopefully get some desired functionality with the lid close.
After that I'll also give rbtylee's suggestions a go to see if I can get some more enlightenment specific lock behaviour working.

I'll probably post any continuing progress here as well.

Thanks again JWJones and rbtylee for your help.


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