trizen/oblogout-py3

Hibernation from terminal is different from hibernation from oblogout

jpmvferreira opened this issue · 2 comments

Hi there, after having to change from the original oblogout to this fork, installed through the AUR, I now have an interesting problem.

When I run the command sudo systemctl hibernate the screen locks and my laptop hibernates, when I return I'm greeted with betterlockscreen as it should be considering I have it enabled in a systemd unit.
However when I use oblogout to hibernate it locks my screen, I then have to unlock it, so that it locks again and hibernates, and when I return I'm greeted with betterlockscreen as it should be.

My /etc/oblogout.conf is given by:

# theme location:
# /usr/share/themes
# this file doesn't require root priveleges to be edited

[settings]
usehal = false

[looks]
opacity = 50
buttontheme = Sardi-Oblogout-Blue
buttons = shutdown, restart, hibernate, lock

[shortcuts]
cancel = Escape
shutdown = S
restart = R
lock = L
hibernate = H

[commands]
shutdown = systemctl poweroff
restart = systemctl reboot
hibernate = systemctl hibernate
lock = betterlockscreen -l --off 30 -- -e -n

And my systemd unit file for betterlockscreen at /usr/lib/systemd/system/betterlockscreen@.service is:

[Unit]
Description = Lock screen when going to sleep/suspend
Before=sleep.target
Before=suspend.target

[Service]
User=%I
Type=simple
Environment=DISPLAY=:0
ExecStart=/usr/bin/betterlockscreen --lock
TimeoutSec=infinity
ExecStartPost=/usr/bin/sleep 1

[Install]
WantedBy=sleep.target
WantedBy=suspend.target

This might be due to me being incompetent and somewhere in time added a custom fix to lock my screen while the system was hibernating and now it found it's way somehow to annoy me, but I'm unable to see where the issue is considering that sudo systemctl hibernate works as expected and /etc/oblogout.conf looks the same.

I don't use the hibernation functionality...

But here's my config file (/etc/oblogout.conf) in case that it helps:

[settings]
# Backend
# Specify backed to use for oblogout's shutdown/restart operations
# - HAL
# - ConsoleKit
#
# If nothing then oblogout will use the commands you specify.
backend = "HAL"

# Monitor
# If you have multiple monitors,
# you can specify which one the oblogout will appear in.
monitor = 0

[looks]
# Looks
# Look and feel settings.

opacity     = 60
bgcolor     = black

# Buttontheme
# Icon theme for the buttons, must be in ~/.themes/<name>/oblogout/
# Valid values: oxygen, foom
buttontheme = oxygen

# Buttons
# You can specify which buttons and their order you want here.
buttons     = cancel, logout, restart, shutdown, suspend, lock

[shortcuts]
# Shortcuts
# Keyboard shortcuts for actions.

cancel      = Escape
shutdown    = S
restart     = R
suspend     = U
logout      = L
lock        = K
hibernate   = H

[commands]
# Commands
# You can specify command for certain action.

# Ignored if you have a backend -->
shutdown    = shutdown -h now
restart     = reboot
suspend     = pmi action suspend
hibernate   = pmi action hibernate
safesuspend = safesuspend
# <--

lock    = gnome-screensaver-command -l
switch  = gdm-control --switch-user
logout  = openbox --exit

Okay I think there's actually more to it, here's the output of the program with the -v flag:

$ oblogout -v
2021-05-08 18:24:16,042 - OpenboxLogout - DEBUG - Shortcut Options: [('cancel', 'Escape'), ('shutdown', 'S'), ('restart', 'R'), ('lock', 'L'), ('hibernate', 'H')]
2021-05-08 18:24:16,042 - OpenboxLogout - DEBUG - Setting cmd_shutdown as systemctl poweroff
2021-05-08 18:24:16,042 - OpenboxLogout - DEBUG - Setting cmd_restart as systemctl reboot
2021-05-08 18:24:16,042 - OpenboxLogout - DEBUG - Setting cmd_hibernate as systemctl hibernate
2021-05-08 18:24:16,042 - OpenboxLogout - DEBUG - Setting cmd_lock as betterlockscreen -l --off 30 -- -e -n
2021-05-08 18:24:16,042 - OpenboxLogout - DEBUG - Validated Button List: ['shutdown', 'restart', 'hibernate', 'lock']
2021-05-08 18:24:16,044 - OpenboxLogout - DEBUG - Screen supports alpha channels!
2021-05-08 18:24:17,222 - OpenboxLogout - DEBUG - Keypress: 104/h
2021-05-08 18:24:17,222 - OpenboxLogout - DEBUG - Matched hibernate
2021-05-08 18:24:17,223 - OpenboxLogout - DEBUG - Executing command: betterlockscreen -l --off 30 -- -e -n
Got 1920x1080 /home/undercover/.cache/i3lock/1920x1080
2021-05-08 18:24:25,212 - OpenboxLogout - DEBUG - Executing command: systemctl hibernate

As you can see it sets cmd_hibernate as systemctl hibernate, which is expected, and binds H (case insensitive from what I've read in the readme) to cmd_hibernate.

However when it matches hibernate, it runs betterlockscreen -l --off 30 -- -e -n instead! Only after that process is completed, which is me unlocking my screen because betterlockscreen locks my screen, does it hibernate.

When it does run systemctl hibernate then my screen is locked (because I said systemd to do so) and then it hibernates, but this should be completely transparent to oblogout.

Changing the configuration file in /etc/oblogout.conf will change the command issued when verbose is on, which means for some reason oblogout is in fact picking up the lock screen command before hibernation, by itself. So I decided to completely remove the lock command, and here's what happened:

$ oblogout -v
2021-05-08 18:44:39,647 - OpenboxLogout - DEBUG - Shortcut Options: [('cancel', 'Escape'), ('shutdown', 'S'), ('restart', 'R'), ('hibernate', 'H')]
2021-05-08 18:44:39,647 - OpenboxLogout - DEBUG - Setting cmd_shutdown as systemctl poweroff
2021-05-08 18:44:39,648 - OpenboxLogout - DEBUG - Setting cmd_restart as systemctl reboot
2021-05-08 18:44:39,648 - OpenboxLogout - DEBUG - Setting cmd_hibernate as systemctl hibernate
2021-05-08 18:44:39,648 - OpenboxLogout - DEBUG - Validated Button List: ['shutdown', 'restart', 'hibernate']
2021-05-08 18:44:39,649 - OpenboxLogout - DEBUG - Screen supports alpha channels!
2021-05-08 18:44:42,072 - OpenboxLogout - DEBUG - Keypress: 104/h
2021-05-08 18:44:42,072 - OpenboxLogout - DEBUG - Matched hibernate
2021-05-08 18:44:42,073 - OpenboxLogout - DEBUG - Executing command: gnome-screensaver-command -l
sh: line 1: gnome-screensaver-command: command not found
2021-05-08 18:44:42,084 - OpenboxLogout - DEBUG - Executing command: systemctl hibernate

It's still trying to reach a screensaver, in this case gnome-screensaver-command, which is not even available on my system!

After searching for a while I found this, in lines 404-410 in the __init__.py in the directory /usr/lib/python3.9/site-packages/oblogout:

elif (data == 'hibernate'):
            self.window.hide()
            self.__exec_cmd(self.cmd_lock)
            if self.backend:
                self.dbus.hibernate()
            else:
                self.__exec_cmd(self.cmd_hibernate)

As you can see it's in fact locking the screen before hibernating, even if I don't want to. As a temporary fix I've just decided to comment this out, but ideally there should be an option to say if you intend to lock your screen before hibernating or not, considering somebody else might already be taking care of it.