Mercurial > pidgin
changeset 13323:723f5b7ef6a2
[gaim-migrate @ 15693]
Long long ago, in a far-off land, a patch was sent to gaim-devel...
I modified this patch, but couldn't test it, so it sat. Today, I got to borrow an evaluation laptop from Apple (here at the University of Minnesota, Crookston). So, I bring you...
A patch from Michael Culbertson: On Mac OS X, obtain the system idle time via IOKit. Thus, our idle time calculations will reflect system usage rather than X11 application usage.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Fri, 24 Feb 2006 03:38:09 +0000 |
parents | 83d522bbc741 |
children | b53e83c5e638 |
files | COPYRIGHT config.h.mingw configure.ac src/gtkidle.c src/gtkprefs.c |
diffstat | 5 files changed, 72 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/COPYRIGHT Fri Feb 24 02:16:25 2006 +0000 +++ b/COPYRIGHT Fri Feb 24 03:38:09 2006 +0000 @@ -64,6 +64,7 @@ Adam Cowell Palmer Cox Jeramey Crawford +Michael Culbertson Martijn Dekker Balwinder Singh Dheeman Andrew Dieffenbach
--- a/config.h.mingw Fri Feb 24 02:16:25 2006 +0000 +++ b/config.h.mingw Fri Feb 24 03:38:09 2006 +0000 @@ -183,6 +183,9 @@ declares uintmax_t. */ #define HAVE_INTTYPES_H_WITH_UINTMAX 1 +/* Define if we have IOKit */ +/* #undef HAVE_IOKIT */ + /* Define to 1 if you have the `krb_get_err_text' function. */ /* #undef HAVE_KRB_GET_ERR_TEXT */ @@ -318,7 +321,7 @@ /* Define to 1 if you have the <signal.h> header file. */ /* #define HAVE_SIGNAL_H 1 */ -/* define if we have silcmime.h */ +/* Define if we have silcmime.h */ /* #undef HAVE_SILCMIME_H */ /* Define to 1 if you have the <smime.h> header file. */
--- a/configure.ac Fri Feb 24 02:16:25 2006 +0000 +++ b/configure.ac Fri Feb 24 03:38:09 2006 +0000 @@ -25,6 +25,14 @@ case "$host_os" in darwin*) AC_CHECK_LIB(resolv, res_query) + + AC_CHECK_HEADER(CoreFoundation/CoreFoundation.h, [ + AC_CHECK_HEADER(IOKit/IOKitLib.h, [ + AC_DEFINE(HAVE_IOKIT, 1, [Define if we have IOKit]) + LIBS="$LIBS -framework IOKit -framework CoreFoundation" + ], []) + ], []) + AC_MSG_CHECKING([for fink]) if test -d /sw; then AC_MSG_RESULT([found, adding /sw to search paths]) @@ -264,7 +272,7 @@ #include <silcmime.h> ], [], [ AC_MSG_RESULT(yes) - AC_DEFINE(HAVE_SILCMIME_H, 1, [define if we have silcmime.h]) + AC_DEFINE(HAVE_SILCMIME_H, 1, [Define if we have silcmime.h]) ], [ AC_MSG_RESULT(no) ])
--- a/src/gtkidle.c Fri Feb 24 02:16:25 2006 +0000 +++ b/src/gtkidle.c Fri Feb 24 03:38:09 2006 +0000 @@ -23,23 +23,32 @@ #include "internal.h" #include "gtkidle.h" -#ifdef USE_SCREENSAVER -# ifndef _WIN32 -# include <X11/Xlib.h> -# include <X11/Xutil.h> -# include <X11/extensions/scrnsaver.h> -# include <gdk/gdkx.h> -# else -# include "idletrack.h" -# endif -#endif /* USE_SCREENSAVER */ +#ifdef HAVE_IOKIT +# include <CoreFoundation/CoreFoundation.h> +# include <IOKit/IOKitLib.h> +#else +# ifdef USE_SCREENSAVER +# ifdef _WIN32 +# include "idletrack.h" +# else + /* We're on X11 and not MacOS X with IOKit. */ +# include <X11/Xlib.h> +# include <X11/Xutil.h> +# include <X11/extensions/scrnsaver.h> +# include <gdk/gdkx.h> +# endif /* !_WIN32 */ +# endif /* USE_SCREENSAVER */ +#endif /* !HAVE_IOKIT */ #include "idle.h" /** * Get the number of seconds the user has been idle. In Unix-world - * this is based on the X Windows usage. In MS Windows this is based - * on keyboard/mouse usage. + * this is based on the X Windows usage. In MS Windows this is + * based on keyboard/mouse usage information obtained from the OS. + * In MacOS X, this is based on keyboard/mouse usage information + * obtained from the OS, if configure detected IOKit. Otherwise, + * MacOS X is handled as a case of X Windows. * * In Debian bug #271639, jwz says: * @@ -58,11 +67,40 @@ * * @return The number of seconds the user has been idle. */ -#ifdef USE_SCREENSAVER +#if defined(USE_SCREENSAVER) || defined(HAVE_IOKIT) static time_t gaim_gtk_get_time_idle() { -# ifndef _WIN32 +# ifdef HAVE_IOKIT + /* Query the IOKit API */ + + static io_service_t macIOsrvc = NULL; + CFTypeRef property; + uint64_t idle_time = 0; /* nanoseconds */ + + if (macIOsrvc == NULL) + { + mach_port_t master; + IOMasterPort(MACH_PORT_NULL, &master); + macIOsrvc = IOServiceGetMatchingService(master, + IOServiceMatching("IOHIDSystem")); + } + + property = IORegistryEntryCreateCFProperty(macIOsrvc, CFSTR("HIDIdleTime"), + kCFAllocatorDefault, 0); + CFNumberGetValue((CFNumberRef)property, + kCFNumberSInt64Type, &idle_time); + CFRelease(property); + + /* convert nanoseconds to seconds */ + return idle_time / 1000000000; +# else +# ifdef _WIN32 + /* Query Windows */ + return (GetTickCount() - wgaim_get_lastactive()) / 1000; +# else + /* We're on X11 and not MacOS X with IOKit. */ + /* Query xscreensaver */ static XScreenSaverInfo *mit_info = NULL; int event_base, error_base; @@ -74,20 +112,18 @@ return (mit_info->idle) / 1000; } else return 0; -# else - /* Query windows */ - return (GetTickCount() - wgaim_get_lastactive()) / 1000; -# endif /* _WIN32 */ +# endif /* !_WIN32 */ +# endif /* !HAVE_IOKIT */ } -#endif /* USE_SCREENSAVER */ +#endif /* USE_SCREENSAVER || HAVE_IOKIT */ static GaimIdleUiOps ui_ops = { -#ifdef USE_SCREENSAVER +#if defined(USE_SCREENSAVER) || defined(HAVE_IOKIT) gaim_gtk_get_time_idle #else NULL -#endif /* USE_SCREENSAVER */ +#endif /* USE_SCREENSAVER || HAVE_IOKIT */ }; GaimIdleUiOps *
--- a/src/gtkprefs.c Fri Feb 24 02:16:25 2006 +0000 +++ b/src/gtkprefs.c Fri Feb 24 03:38:09 2006 +0000 @@ -1748,7 +1748,7 @@ GAIM_PREF_STRING, "/core/away/idle_reporting", _("Never"), "none", _("From last sent message"), "gaim", -#ifdef USE_SCREENSAVER +#ifdef USE_SCREENSAVER || defined(HAVE_IOKIT) _("Based on keyboard or mouse use"), "system", #endif NULL);