--- a/pidgin/gtkidle.c Sun Oct 13 03:52:05 2019 -0500
+++ b/pidgin/gtkidle.c Sun Oct 13 05:14:08 2019 -0500
@@ -24,6 +24,9 @@
# include <CoreFoundation/CoreFoundation.h>
# include <IOKit/IOKitLib.h>
@@ -73,27 +76,29 @@
/* Query the IOKit API */
- static io_service_t macIOsrvc = NULL;
- uint64_t idle_time = 0; /* nanoseconds */
- IOMasterPort(MACH_PORT_NULL, &master);
- macIOsrvc = IOServiceGetMatchingService(master,
- IOServiceMatching("IOHIDSystem"));
- property = IORegistryEntryCreateCFProperty(macIOsrvc, CFSTR("HIDIdleTime"),
- kCFAllocatorDefault, 0);
- CFNumberGetValue((CFNumberRef)property,
- kCFNumberSInt64Type, &idle_time);
- /* 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); + CFMutableDictionaryRef dict = NULL; + status = IORegistryEntryCreateCFProperties(entry, &dict, kCFAllocatorDefault, 0); + if (status == KERN_SUCCESS) { + CFNumberRef obj = CFDictionaryGetValue(dict, CFSTR("HIDIdleTime")); + int64_t nanoseconds = 0; + if (CFNumberGetValue(obj, kCFNumberSInt64Type, &nanoseconds)) { + idleSeconds = (double) nanoseconds / NSEC_PER_SEC; + IOObjectRelease(entry);