Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have an Ubuntu box connected to a plasma TV. Still images reduce the lifetime of plasma TVs and may cause pixel-burn. I am looking for a technique to start the screensaver if the picture on the monitor is still for a while but prevents the screensaver if the picture is moving. Here is my not-working piece of python code but any solution using python or otherwise is good for me:

import gtk.gdk
import time
from subprocess import *

w = gtk.gdk.get_default_root_window()
sz = w.get_size()

while (True):
    buf1 = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1])
    pb1 = buf1.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1])
    time.sleep(3)
    buf2 = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1])
    pb2 = buf2.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1])

    pix1 = pb1.get_pixels()
    pix2 = pb2.get_pixels()
    diffs = 0
    for i in range(len(pix1)):
        if(pix1[i] != pix2[i]):
            diffs = diffs + 1
    if(diffs > 10000):
        call(["xset", "dpms", "force", "on"])
        call(["gnome-screensaver-command", "--exit"])
share|improve this question
    
Do you really want that? I have less than 10000 diffs while I'm typing this comment. With PC use, (near) still images are unfortunately very much normal (every time you read something or write something for that matter). At the same time a single animation (such as a on screen clock) could prevent it ever from coming up. –  frostschutz Jun 8 '13 at 21:18
    
The threshold and the timeout are adjustable. The purpose of the script is to prevent screensaver when e.g., a movie is being played but the keyboard is not being touched. –  Mohsen Jun 8 '13 at 22:46
    
For the screensaver during movie problem I found a different solution in xautolock. You can set it up to prevent locking when the mouse pointer is e.g. exactly in the lower left corner of the screen. So when I watch a movie, I just move the mouse there, and it doesn't lock. –  frostschutz Jun 9 '13 at 13:03
    
If you want to stick with your script, you should optimize your loop to only take one screenshot per iteration, instead of two. Also check if Python doesn't have an image library capable of returning the number of diffs, the for loop is just unbearably slow. Way too much overhead for a background screensaver control. –  frostschutz Jun 9 '13 at 22:03
    
Of course it can be optimized. But overhead is not the main issue of my script right now since it runs only once every few minutes. The main issue is that it doesn't work. Why? I don't know. –  Mohsen Jun 10 '13 at 2:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.