[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Solution for Gnome 3 screen blanking

After much experimenting and hair pulling I thought Id share my solution for disabling the screen blanking on Gnome 3.

There are various solutions on the web but this is the only one Ive found which always works every boot and keeps working after upgrades.

Basically it consists of a Python script which is lauched automatically at login.

Id like to credit a website here which gave me the key idea but unfortunately I can no longer find it.

Basically you need to use DBus to request the screensaver be inhibited, BUT,

Catch 1 is, the inhibit only applies as long as the process which requested it is still running. Therefore its no good using the dbus commands in a shell script as each command runs as a separate process and terminates, therefore you need to write your own program which will request a DBus inhibit then sleep rather than exiting. Python provides a nice easy portable solution akin to a shell script.

Catch 2 is that the screensaver daemon must be running BEFORE you call inhibit

Catch 3 is that although the screensaver daemon runs automatically when you log in, if you then run your Python script manually from the terminal it will work, but if you set your Python script to also run automantically at login, then, due to the scheduling order, you cannot guarantee it will always request the inhibit until after the daemon has started. Therefore you need to make it loop so it periodically requests an inhibit, this way if the daemon wasnt running the first time through the loop it will be later on. This also makes it robust if the screensaver daemon should restart for whatever reason. How long you sleep for is a tradeoff - too little and you waste processor cycles, too long and the screensaver timer will kick in before youve inhibited it. 30 seconds is a good value guaranteed to always work as the minimum time setting in System Settings is 1 min, but you can adjust this upwards if you have the screen saver time set higher in System Settings.

The code for the script follows at the end.

To run it you need to open gnome-session-properties from the terminal and add an entry for the Python script and also make sure the Gnome screensaver daemon is enabled. If like me, as an earlier attempt at disabling the screensaver you disabled the daemon, you MUST re-enable it, in order for the inhibit request to work - the entry is called 'Screensaver' with the description 'Launch screensaver and locker program'

Ive had this running on a public touchscreen terminal for months flawlessly, accross dozens of reboots and it survied the upgrade from Gnome 3.2 to 3.4

Hope its of some help to others.


Python code

import dbus
import os
import time

while True:
    bus = dbus.SessionBus()
proxy = bus.get_object('org.gnome.SessionManager','/org/gnome/SessionManager')
    os.system("xset -dpms")


Reply to: