FedoraForum.org - Fedora Support Forums and Community
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2011
    Posts
    141

    HOWTO: Inhibit Gnome-Screensaver when Flash is fullscreen in Gnome 3

    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.
    Last edited by mikeym; 23rd January 2012 at 12:57 AM. Reason: Script fix

  2. #2
    Join Date
    May 2004
    Location
    Ontario, Canada
    Posts
    64

    Re: HOWTO: Inhibit Gnome-Screensaver when Flash is fullscreen in Gnome 3

    Thank you for this script!

    I know there exists a couple different extensions for gnome3 that will do this, but I feel this should be done automatically wherever it can be done.

    One thing I will note your line:

    Code:
    if title == 'exe' and 'Exe' in winclass:
    I had to replace it with this to get it to work,

    Code:
    if title == 'plugin-container' and 'plugin-container' in winclass:
    This was the only way it would inhibit the blanking of the screen using Firefox 14. The only other thing I am going to try and debug is that it seems to stop running on it's own. I haven't yet spent the time to find the problem. I will update this when I find the solution.

    Many thanks!

  3. #3
    Join Date
    May 2004
    Location
    Ontario, Canada
    Posts
    64

    Re: HOWTO: Inhibit Gnome-Screensaver when Flash is fullscreen in Gnome 3

    Ok. All I can say is it's failing on an unhandled exception. I haven't had time to debug it any further and don't really remember python well enough to figure out more.

    I've gone back (for now) of using an extension in gnome3 to inhibit the blanking of the screen.

Similar Threads

  1. gnome inhibit applet missing from Fedora 14 ?
    By megaloman in forum Using Fedora
    Replies: 0
    Last Post: 16th November 2010, 06:20 PM
  2. F13: gnome-mplayer does not start in fullscreen
    By borispr in forum Using Fedora
    Replies: 7
    Last Post: 6th September 2010, 05:04 PM
  3. gnome inhibit applet missing from 12?
    By leftoflexo in forum Using Fedora
    Replies: 2
    Last Post: 19th April 2010, 10:19 PM
  4. Replies: 9
    Last Post: 14th November 2008, 05:16 PM
  5. Adding the xscreensaver batch & customizing screensaver options in gnome-screensaver
    By Firewing1 in forum Guides & Solutions (Not For Questions)
    Replies: 27
    Last Post: 14th July 2006, 11:09 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •