woodchuck-devel
[Top][All Lists]
Advanced

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

Re: [Woodchuck-devel] [gpodder-devel] Closing gPodder after a Woodchuck-


From: Neal H. Walfield
Subject: Re: [Woodchuck-devel] [gpodder-devel] Closing gPodder after a Woodchuck-triggered update
Date: Wed, 01 Feb 2012 22:45:57 +0100
User-agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (Goj┼Ź) APEL/10.8 Emacs/23.2 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO)

Hi,

There is an even better (and simpler mechanism) to determine whether
the user has interacted with an application: the _NET_WM_USER_TIME X11
property, which is maintained for each X11 top-level window and
updated by X11 every time the user interacts with the application.

Here is some initial untested code, which I would add to util.py or
woodchuck.py:

    def last_user_interaction():
        """Return the time at which the user last interacted with the
        application."""
        def die(msg):
            if hasattr(die, 'once'):
                logging.debug(msg, exc_info=True)
                die.once = True
    
        # Use our current toolkit to return the value of _NET_WM_USER_TIME
        if gpodder.ui.gtk:
            try:
                from gtk.gdk import display_get_default
                return display_get_default().get_user_time()
            except Exception:
                die("Calling display_get_default().get_user_time()")
                # Fall through and use the generic routine.
    
        if gpodder.ui.qt:
            try:
                from PySide.QtGui import QX11Info
                return QX11Info.appUserTime()
            except Exception:
                die("Calling QX11Info.appUserTime()")
                # Fall through and use the generic routine.
    
        die("Unable to determine the time of the last user interaction, "
            "faking an active user.")
    
        # We don't have a way to determine the last interaction time.  It
        # is better to incorrectly indicate that the user interacted with
        # the application than to incorrectly indicate that the user never
        # interacted with the application.
        return time.time()

My idea would be to have Woodchuck record the time when it is
initialized.  Whenever an update is completed, Woodchuck checks the
time.  If the time is unchanged, then it causes gPodder to quit (how?
Should it just do a sys.exit?).

What do you think of this approach?

Thanks,

Neal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]