blob: ac6dff958968410f406c2ee097e7880e0c80b739 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#include "SwifTools/Idle/MacOSXIdleQuerier.h"
#include <cassert>
#include <iostream>
#include <CoreFoundation/CoreFoundation.h>
namespace Swift {
MacOSXIdleQuerier::MacOSXIdleQuerier() : ioService(NULL) {
mach_port_t masterPort;
IOMasterPort(MACH_PORT_NULL, &masterPort);
ioService = IOServiceGetMatchingService(masterPort, IOServiceMatching("IOHIDSystem"));
assert(ioService);
}
int MacOSXIdleQuerier::getIdleTimeSeconds() {
CFTypeRef property = IORegistryEntryCreateCFProperty(ioService, CFSTR("HIDIdleTime"), kCFAllocatorDefault, 0);
uint64_t idle = 0;
bool result = CFNumberGetValue((CFNumberRef)property, kCFNumberSInt64Type, &idle);
assert(result);
CFRelease(property);
return idle / 1000000000;
}
}
|