While remotely monitoring my desktop session with powertop while it was idle (screensaver active) I noticed that a few processes cause a lot of activity, and keeping the CPU from going into the PC7 state (the complete cpu package deepest sleep state). Most notably firefox and it’s plugin-container cause frequent wakeups.
I wrote a short script that listens on dbus for screensaver ActiveChanged messages, and either sends a STOP or a CONT signal to firefox and the plugin-container. This script makes my desktop go from 20W to 19W of power when I am not using it.
import subprocess
import datetime
import dbus, gobject
from dbus.mainloop.glib import DBusGMainLoop
stoplist = ['firefox', 'plugin-container', 'steam']
def msg2_cb(msg):
dt = datetime.datetime.now()
if (msg):
for name in stoplist:
subprocess.call(["killall", "-STOP", name])
else:
for name in stoplist:
subprocess.call(["killall", "-CONT", name])
if __name__ == '__main__':
DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
bus.add_signal_receiver(msg2_cb, 'ActiveChanged', None, None, '/org/gnome/ScreenSaver')
mainloop = gobject.MainLoop ()
mainloop.run ()
The obvious caveat is that any downloads by firefox are also stopped if the screensaver becomes active.
My Python is rusty but where msg2_cb() get its parameter? From what I understand it’s always going to stop the processes.
the msg parameter contains a boolean false or true (screensaver active or not)