Hi,
This is a quick script I wrote to inhibit gnome-screensaver when Flash is in fullscreen. I had to write it because I realised that existing scripts to inhibit the screensaver from gnome 2 no longer worked and in fact it was impossible to convert them (I tried) to gnome 3 as they were written in Bash.
Anyway, put the following in
$HOME/bin/flash-screensaver-inhibitor.py
Code:
#!/usr/bin/python -u
# #######################################
#
# Inhibit Screensaver in Flash in Gnome 3
# By mikey
# Contact abc.mikey (at) googlemail.com
#
#########################################
# NOTE the -u switch in the hashbang that
# turns on unbuffered stdout for
# debuging
from Xlib.display import Display
from Xlib import X, error
from time import sleep
import dbus
# Check we are still connected, by sending NoOp to X
def X_session_connected(display):
try:
display.no_operation()
display.sync()
except error.ConnectionClosedError:
return False
return True
bus = dbus.SessionBus()
proxy = bus.get_object ('org.gnome.SessionManager', '/org/gnome/SessionManager')
sessionManager = dbus.Interface (proxy, 'org.gnome.SessionManager')
cookie = 0
display = Display()
root = display.screen().root
count = 0
while X_session_connected(display):
count += 1
# Poll approx once every minute; 30 * 2 seconds
if count == 30:
count = 0
ret = root.get_full_property(display.intern_atom('_NET_ACTIVE_WINDOW'), X.AnyPropertyType)
if ret is not None:
windowID = ret.value[0]
if windowID != 0:
window = display.create_resource_object('window', windowID)
title = window.get_wm_name()
winclass = window.get_wm_class()
print 'Active Window: ', title, ' ; ', winclass
if title == 'exe' and 'Exe' in winclass:
if cookie == 0:
print 'Inhibiting Gnome Screensaver'
cookie = sessionManager.Inhibit ("flash-screensaver-inhibitor.py", 0, "Flash fullscreen override", 8)
else:
if cookie != 0:
print 'Uninhibiting Gnome Screensaver'
sessionManager.Uninhibit(cookie)
cookie = 0
else:
print 'Root window active'
sleep(2)
# NOTE usefull command to show if screensaver is inhibited:
#
# dbus-send --session --dest=org.gnome.SessionManager --type=method_call --print-reply --reply-timeout=20000 /org/gnome/SessionManager org.gnome.SessionManager.IsInhibited uint32:8
#
And make it executable with
chmod +x $HOME/bin/flash-screensaver-inhibitor.py
And copy the following into
$HOME/.config/autostart/flash-screensaver-inhibitor.desktop
Code:
[Desktop Entry]
Type=Application
Exec=sh -c "$HOME/bin/flash-screensaver-inhibitor.py &> /dev/null"
Hidden=false
X-GNOME-Autostart-enabled=true
Name[en_US]=Flash Screensaver Inhibitor
Name=Flash Screensaver Inhibitor
Comment[en_US]=Inhibit screensaver when viewing Flash
Comment=Inhibit screensaver when viewing Flash
You can then disable it later if you like using the Startup Applications dialogue:
gnome-session-properties
If you need to debug for any reason, try changing /dev/null to a desired log file from
gnome-session-properties
That's it!
Fix: Fixed a stupid mistake that allowed the screensaver to still activate. Now inhibits properly.