Laptop does not suspend after power is unplugged
eyalsoha@gmail.com
Submitted byAssigned to Ali Abdallah @ali
Description
I have set my laptop to suspend after 15 minutes of inactivity, but only on battery. I plugged in my laptop and left it inactive for a long time.
When I unplug my laptop, the laptop does not later suspend.
My expectation: The laptop should suspend 15 minutes after being unplugged.
To test this:
- Set inactivity timeout to 1 minute to speed up testing. Use this command: xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/inactivity-on-battery -s 1
- Plug in laptop.
- Kill existing power manager: killall xfce4-power-manager
- Run another power manager in debug: xfce4-power-manager --debug --debug --debug --no-daemon
- Wait 1 minute for the timeout. You'll eventually see this on the screen: TRACE[xfpm-manager.c:493] xfpm_manager_alarm_timeout_cb(): Alarm inactivity timeout id 4
- Without touching any keys, unplug the power cord.
- Continue to wait, the laptop will never suspend.
The problem is that unplugging or plugging in the laptop doesn't count as activity, so it doesn't reset the timer. The timer already happened so it won't happen again. This will also affect other times, like dimming the screen, etc.
One solution is to force timer to reset. There is a dbus command "SimulateUserActivity" that is used in src/xfce-screensaver.c:370 but it didn't work for me because the proxy was false. Also, the heartbeat command doesn't work for me because I don't have xscreensvaer-comand installed. And anyone, that function is not called when the power cable is plugged/unplugged.
I suggest that the change of the "on_battery" signal force a reset of all the timers, as if a key were pressed. That could be done in xfpm-manager.c in xfpm_manager_on_battery_changed_cb. Either call the routine in xfce-screensvaer.c (which doesn't work for me as described above) or do something else, like run "xdotool key shift", which simulates pressing the shift key.
Maybe it would be best if the on_battery callback called the routine in xfce-screensvaer.c but the HEARTBEAT_COMMAND were customizable for the user, so that I could set it to xdotool. I'm not sure how to do this because I can't understand how to set those properties as a user, if that's even possible.
Version: git