qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
timer_osx.cpp
Go to the documentation of this file.
1 /*
2  Pidgin is the legal property of its developers, whose names are too numerous
3  to list here. Please refer to the COPYRIGHT file distributed with this
4  source distribution (which can be found at
5  <https://hg.pidgin.im/pidgin/main/file/13e4ae613a6a/COPYRIGHT> ).
6 
7  Copyright © 2006 by Richard Laager
8  Copyright © 2014-2019 by The qTox Project Contributors
9 
10  This file is part of qTox, a Qt-based graphical interface for Tox.
11 
12  qTox is libre software: you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation, either version 3 of the License, or
15  (at your option) any later version.
16 
17  qTox is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with qTox. If not, see <http://www.gnu.org/licenses/>.
24 */
25 
26 #include <QtCore/qsystemdetection.h>
27 #include "src/platform/timer.h"
28 #include <CoreFoundation/CoreFoundation.h>
29 #include <IOKit/IOKitLib.h>
30 
31 uint32_t Platform::getIdleTime()
32 {
33  // https://hg.pidgin.im/pidgin/main/file/13e4ae613a6a/pidgin/gtkidle.c
34  // relevant code introduced to Pidgin in:
35  // https://hg.pidgin.im/pidgin/main/diff/8ff1c408ef3e/src/gtkidle.c
36  static io_service_t service = 0;
37  CFTypeRef property;
38  uint64_t idleTime_ns = 0;
39 
40  if (!service) {
41  mach_port_t master;
42  IOMasterPort(MACH_PORT_NULL, &master);
43  service = IOServiceGetMatchingService(master, IOServiceMatching("IOHIDSystem"));
44  }
45 
46  property = IORegistryEntryCreateCFProperty(service, CFSTR("HIDIdleTime"), kCFAllocatorDefault, 0);
47  CFNumberGetValue(static_cast<CFNumberRef>(property), kCFNumberSInt64Type, &idleTime_ns);
48  CFRelease(property);
49 
50  return idleTime_ns / 1000000;
51 }
timer.h