summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Kramlich <grim@reaperworld.com>2019-10-13 05:14:08 -0500
committerGary Kramlich <grim@reaperworld.com>2019-10-13 05:14:08 -0500
commitecdbeffb87ea02a7f305bc25bc79300706fe39c0 (patch)
tree44ee1d0c7df46d80b4f70e0f9c3a44bbac3736b8
parentd451b8e23453d8e8f50440c7f2dfae3be3ea54db (diff)
downloadpidgin-ecdbeffb87ea02a7f305bc25bc79300706fe39c0.tar.gz
Move to a newer method for getting the idle time on macos
-rw-r--r--pidgin/gtkidle.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/pidgin/gtkidle.c b/pidgin/gtkidle.c
index 8838cf64cc..eb71cf1c4f 100644
--- a/pidgin/gtkidle.c
+++ b/pidgin/gtkidle.c
@@ -24,6 +24,9 @@
#include "gtkidle.h"
#ifdef HAVE_IOKIT
+# ifndef HAVE_UNISTD_H
+# define HAVE_UNISTD_H
+# endif
# include <CoreFoundation/CoreFoundation.h>
# include <IOKit/IOKitLib.h>
#elif defined (_WIN32)
@@ -73,27 +76,29 @@ pidgin_get_time_idle(void)
{
# 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;
+ double idleSeconds = -1;
+ io_iterator_t iter = 0;
+ if (IOServiceGetMatchingServices(kIOMasterPortDefault, IOServiceMatching("IOHIDSystem"), &iter) == KERN_SUCCESS) {
+ io_registry_entry_t entry = IOIteratorNext(iter);
+ if (entry) {
+ CFMutableDictionaryRef dict = NULL;
+ kern_return_t status;
+ status = IORegistryEntryCreateCFProperties(entry, &dict, kCFAllocatorDefault, 0);
+ if (status == KERN_SUCCESS) {
+ CFNumberRef obj = CFDictionaryGetValue(dict, CFSTR("HIDIdleTime"));
+ if (obj) {
+ int64_t nanoseconds = 0;
+ if (CFNumberGetValue(obj, kCFNumberSInt64Type, &nanoseconds)) {
+ idleSeconds = (double) nanoseconds / NSEC_PER_SEC;
+ }
+ }
+ CFRelease(dict);
+ }
+ IOObjectRelease(entry);
+ }
+ IOObjectRelease(iter);
+ }
+ return idleSeconds;
# else
# ifdef _WIN32
/* Query Windows */