Unset presentation mode at sleep

I’d like the “presentation mode” (the selection available when rightclick on battery icon) to be unselected when laptop goes to sleep/hibernate.

From terminal it can be unset by running

'xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/presentation-mode -s false'

On my old majaro laptop I had a script in
/usr/lib/systemd/system-sleep/powemanage.sh
looking like this:

#!/bin/sh
echo $USER is running powerreset
/com/scripts/powerreset

and /com/scripts/powerreset
looking like this:

#!/bin/sh
export DISPLAY=:0
export XAUTHORITY=/home/marli/.Xauthority
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus

#DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus

su marli -c 'xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/presentation-mode -s false'

When putting these into the respective folders in the new laptop, it fails to goto sleep. Screen goes black and system freezes. Fan and power led is still on.
The only thing to do is long press the power button.

permission of the files is set to 755, owned by root.

What am I missing?

There is no service file.

Also, don’t use /usr/lib/systemd/, since it is reserved for the system. Modifications goes here: /etc/systemd/.

The idea sounds like a joke to me, because the whole point of presentation mode is to prevent screensaver or sleep.Why don’t you just turn it off, if you do want the pc to fall asleep. And adjust the power settings.

Because when you’re done with the presentation, you press sleep, put the laptop in your bag, go to an office, open you laptop, log in, someone comes to talk with you, you join them to their office to look at what they wanted to show you, and when you come back you realize your session is unlocked and screen is still on because you forgot to turn off presentation mode after your presentation.

Could you elaborate on this?

You need a service file to execute your script right before your system goes to suspend/hibernate. Otherwise your script just does nothing; just existing.

systemd.service

I think that is not the right track to follow. The script as is does run when expected.
Removing the line

su marli -c 'xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/presentation-mode -s false'

and adding some echo-lines to the script causes the text in echo to show in output of journalctl.

Once the command

su marli -c 'xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/presentation-mode -s false'

is reinserted, the system freeze when going to sleep.
There issue must be related to that line.

Whats wrong with that line? (It is a copy from my previous laptop where it worked perfectly)

You do not need sudo for this.

xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/presentation-mode -s false

should be enough. And make sure the service is in user space too. The mismatch of contexts may be the source of the problem.

Without su the following error is returned:

Failed to init libxfconf: Error sending credentials: Error sending message: Broken pipe.

That is when run as root from terminal.
Run as logged in user from terminal updates the setting.
Run with su as root from terminal also updates the setting.

As the systemd scripts are run as root, the su seem like it has to be there.

Maybe you are right, i am not sure on this one, it was just a suggestion.

Any idea why the command is causing the system to freeze when going to sleep, while running good from terminal?
Also it was running good as a pre-sleep script in my previous laptop.

Could it be that it has to run before something else that is triggered when going to sleep? How can I make the script trigger before everything else?

Generally, you can set your service to run after or before every other service. In the options Target or Wanted by. But where exactly it should go, i do not know. You can play with --list-dependencies to see where you can glue it.

[teo@teo-lenovo-v15 ~]$ systemctl list-dependencies --all --before sleep.target
sleep.target
○ ├─systemd-hibernate.service
○ │ └─conservation_mode.service
○ │   └─shutdown.target
○ │     ├─systemd-soft-reboot.service
○ │     │ └─soft-reboot.target
○ │     └─final.target
○ │       └─systemd-soft-reboot.service
○ │         └─soft-reboot.target
○ └─systemd-suspend.service
○   └─conservation_mode.service
○     └─shutdown.target
○       ├─systemd-soft-reboot.service
○       │ └─soft-reboot.target
○       └─final.target
○         └─systemd-soft-reboot.service
○           └─soft-reboot.target

Conservation mode is a custom aur package with the following content

[Unit]
Description=Set conservation_mode on for lenovo laptop
After=multi-user.target
After=systemd-suspend.service
After=systemd-hibernate.service


[Service]
ExecStart=/usr/bin/conservation_mode.sh

[Install]
WantedBy=multi-user.target

What ever I try, the script seems to run as the last thing. I’d like it to run as the first thing when sleep is called.
I may misunderstand the documentation… My understanding is that if a service is RequiredBy=sleep.target the sleep progress should stop and wait for that service to finish. But it doesn’t seem to work that way.

Using before or after swaps the order of logged lines by one: Using “before” the script is logged to run before sleep.target. Which sounds like the expected behavior, but after everything else.
The first thing to stop is NetworkManager, happens even before that. NetworkManager is actually logged as stopped before the first line containing systemd. How does the NetworkManager get to idea that system is going to sleep before systemd?

It does not trigger at all if I use any of these:
WantedBy=systemd-logind.service
WantedBy=multi-user.target

It seems like a lot of time spent to create an complicated automated solution to save a few seconds

I don’t understand use of 2 shell scripts rather than creating a systemd unit

I turn presentation mode on/off manually and use the indicator icon to show when it is active

xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/show-presentation-indicator -s true

But my partner has a £5 PC remote control that can poweroff system and has presentation mode permanently enabled

Forget to turn off presentation mode once, when some funny/evil guy is around, and you will appreciate the functionality of the script. (Or some children)

As shown, letting sleep.target run the script, as it is designed to do, or create a service RequiredBy=sleep.target to run the script doesn’t make any difference. The script is run after everything else is stopped. It needs to be run when sleep is called, before everything else is triggered.

NetworkManager seems to know sleep is called, before sleep.target is called. Hence it should be possible. But how does NetworkManager know this?

Maybe this will help

[tracy@daphne network-online.target.wants]$ cat NetworkManager-wait-online.service
[Unit]
Description=Network Manager Wait Online
Documentation=man:NetworkManager-wait-online.service(8)
Requires=NetworkManager.service
After=NetworkManager.service
Before=network-online.target

[Service]
# `nm-online -s` waits until the point when NetworkManager logs
# "startup complete". That is when startup actions are settled and
# devices and profiles reached a conclusive activated or deactivated
# state. It depends on which profiles are configured to autoconnect and
# also depends on profile settings like ipv4.may-fail/ipv6.may-fail,
# which affect when a profile is considered fully activated.
# Check NetworkManager logs to find out why wait-online takes a certain
# time.

Type=oneshot
ExecStart=/usr/bin/nm-online -s -q
RemainAfterExit=yes

# Set $NM_ONLINE_TIMEOUT variable for timeout in seconds.
# Edit with `systemctl edit NetworkManager-wait-online`.
#
# Note, this timeout should commonly not be reached. If your boot
# gets delayed too long, then the solution is usually not to decrease
# the timeout, but to fix your setup so that the connected state
# gets reached earlier.
Environment=NM_ONLINE_TIMEOUT=60

[Install]
WantedBy=network-online.target

I don’t understand how to make use of that. Because network manager doesn’t start or stop at sleep event, but it gets the instruction to sleep.

Log looks like this:

aug. 04 22:16:30 systemd-logind[827]: The system will suspend now!
aug. 04 22:16:30 NetworkManager[866]: <info>  [1722802590.8682] manager: sleep: sleep requested (sleeping: no  enabled: yes)
aug. 04 22:16:30 NetworkManager[866]: <info>  [1722802590.8684] device (wlp2s0): state change: unavailable -> unmanaged (reason 'unmanaged-sleeping', sys-iface-state: 'managed')
aug. 04 22:16:30 NetworkManager[866]: <info>  [1722802590.8699] device (p2p-dev-wlp2s0): state change: unavailable -> unmanaged (reason 'unmanaged-sleeping', sys-iface-state: 'managed')
aug. 04 22:16:30 NetworkManager[866]: <info>  [1722802590.8705] manager: NetworkManager state is now ASLEEP
aug. 04 22:16:31 systemd[1]: Reached target Sleep.

Thinking about other ways to trigger… If the script could be triggered when session is locked that would also be good. At session unlock could be an (less preferred) alternative as well.

The easiest would be to make a script which exits presentation mode and then triggers sleep. You could bind it to a keyboard shortcut for convenience.

#!/usr/bin/bash

xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/presentation-mode -s false

systemctl suspend
1 Like

I ran
xfconf-query -c xfce4-session -p /general/LockCommand -l -v
and realized it had no value.

then ran

xfconf-query -c xfce4-session -p /general/LockCommand -t string -s "/com/scripts/lock-session.sh"

Now the script ran when lid is closed (closing lid action set to “lock session”), but the session didn’t lock. So I added this to the end of the script:
xfce4-screensaver-command -l

Now script runs, and session lock when lid is closed. But still not when system is going to sleep.

My first thought when I read this was: “Oh, but that won’t trigger when system triggers the sleep.”
Then I realized I’m dumb. System won’t go to sleep when presentation mode is on. That’s the point of presentation mode.

Any way to bind this to the power button?

Edit: on further thought… I wasn’t all that dumb. When battery runs low system will trigger sleep even in presentation mode. In that situation the script won’t run when implemented this way.