mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Reorganized platform-dependent code
Auto-away timer check reduced to 1s
This commit is contained in:
parent
8e4f69aa79
commit
677058eb65
6
qtox.pro
6
qtox.pro
|
@ -156,7 +156,7 @@ HEADERS += src/widget/form/addfriendform.h \
|
|||
src/misc/serialize.h \
|
||||
src/widget/form/settings/advancedform.h \
|
||||
src/audio.h \
|
||||
src/platform.h
|
||||
src/platform/timer.h
|
||||
|
||||
SOURCES += \
|
||||
src/widget/form/addfriendform.cpp \
|
||||
|
@ -224,4 +224,6 @@ SOURCES += \
|
|||
src/misc/serialize.cpp \
|
||||
src/widget/form/settings/advancedform.cpp \
|
||||
src/audio.cpp \
|
||||
src/platform.cpp
|
||||
src/platform/osx_timer.cpp \
|
||||
src/platform/win_timer.cpp \
|
||||
src/platform/x11_timer.cpp
|
||||
|
|
45
src/platform/osx_timer.cpp
Normal file
45
src/platform/osx_timer.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
This program is libre software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
#include "src/platform/timer.h"
|
||||
#include <QDebug>
|
||||
#include <IOKit/IOKitLib.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
||||
|
||||
uint32_t Platform::getIdleTime()
|
||||
{
|
||||
// https://hg.pidgin.im/pidgin/main/file/13e4ae613a6a/pidgin/gtkidle.c
|
||||
static io_service_t service = NULL;
|
||||
CFTypeRef property;
|
||||
uint64_t idleTime_ns = 0;
|
||||
|
||||
if (!service)
|
||||
{
|
||||
mach_port_t master;
|
||||
IOMasterPort(MACH_PORT_NULL, &master);
|
||||
service = IOServiceGetMatchingService(master, IOServiceMatching("IOHIDSystem"));
|
||||
}
|
||||
|
||||
property = IORegistryEntryCreateCFProperty(service, CFSTR("HIDIdleTime"), kCFAllocatorDefault, 0);
|
||||
CFNumberGetValue((CFNumberRef)property, kCFNumberSInt64Type, &idleTime_ns);
|
||||
CFRelease(property);
|
||||
|
||||
return idleTime_ns / 1000000;
|
||||
}
|
||||
|
||||
#endif // defined(__APPLE__) && defined(__MACH__)
|
|
@ -14,16 +14,15 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef PLATFORM_H
|
||||
#define PLATFORM_H
|
||||
#ifndef PLATFORM_TIMER_H
|
||||
#define PLATFORM_TIMER_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
/* Platform-dependent code */
|
||||
|
||||
namespace Platform
|
||||
{
|
||||
uint32_t getIdleTime();
|
||||
}
|
||||
|
||||
#endif // PLATFORM_H
|
||||
#endif // PLATFORM_TIMER_H
|
31
src/platform/win_timer.cpp
Normal file
31
src/platform/win_timer.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
This program is libre software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include <QDebug>
|
||||
#ifdef Q_OS_WIN32
|
||||
#include "src/platform/timer.h"
|
||||
#include <Windows.h>
|
||||
|
||||
|
||||
uint32_t Platform::getIdleTime()
|
||||
{
|
||||
LASTINPUTINFO info = { 0 };
|
||||
if(GetLastInputInfo(&info))
|
||||
return info.dwTime / 1000;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // Q_OS_WIN32
|
|
@ -14,47 +14,16 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "platform.h"
|
||||
#include <QDebug>
|
||||
#if defined(Q_OS_WIN32)
|
||||
#include <Windows.h>
|
||||
#elif defined(__APPLE__) && defined(__MACH__)
|
||||
#include <IOKit/IOKitLib.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#else // Q_OS_UNIX
|
||||
#ifdef Q_OS_UNIX
|
||||
#include "src/platform/timer.h"
|
||||
#include <X11/extensions/scrnsaver.h>
|
||||
#endif
|
||||
|
||||
|
||||
uint32_t Platform::getIdleTime()
|
||||
{
|
||||
// http://qt-project.org/faq/answer/how_can_i_detect_a_period_of_no_user_interaction
|
||||
// Detecting global inactivity, like Skype, is possible but not via Qt:
|
||||
// http://stackoverflow.com/a/21905027/1497645
|
||||
// https://hg.pidgin.im/pidgin/main/file/13e4ae613a6a/pidgin/gtkidle.c
|
||||
uint32_t idleTime = 0;
|
||||
|
||||
#if defined(Q_OS_WIN32)
|
||||
LASTINPUTINFO info = { 0 };
|
||||
if(GetLastInputInfo(&info))
|
||||
idleTime = info.dwTime / 1000;
|
||||
#elif defined(__APPLE__) && defined(__MACH__)
|
||||
static io_service_t service = NULL;
|
||||
CFTypeRef property;
|
||||
uint64_t idleTime_ns = 0;
|
||||
|
||||
if (!service)
|
||||
{
|
||||
mach_port_t master;
|
||||
IOMasterPort(MACH_PORT_NULL, &master);
|
||||
service = IOServiceGetMatchingService(master, IOServiceMatching("IOHIDSystem"));
|
||||
}
|
||||
|
||||
property = IORegistryEntryCreateCFProperty(service, CFSTR("HIDIdleTime"), kCFAllocatorDefault, 0);
|
||||
CFNumberGetValue((CFNumberRef)property, kCFNumberSInt64Type, &idleTime_ns);
|
||||
CFRelease(property);
|
||||
|
||||
idleTime = idleTime_ns / 1000000;
|
||||
#else // Q_OS_UNIX
|
||||
Display *display = XOpenDisplay(NULL);
|
||||
if(!display)
|
||||
{
|
||||
|
@ -77,7 +46,7 @@ uint32_t Platform::getIdleTime()
|
|||
qDebug() << "XScreenSaverAllocInfo() failed";
|
||||
}
|
||||
XCloseDisplay(display);
|
||||
#endif
|
||||
return idleTime;
|
||||
}
|
||||
|
||||
#endif // Q_OS_UNIX
|
|
@ -35,7 +35,7 @@
|
|||
#include "form/inputpassworddialog.h"
|
||||
#include "src/autoupdate.h"
|
||||
#include "src/audio.h"
|
||||
#include "src/platform.h"
|
||||
#include "src/platform/timer.h"
|
||||
#include <QMessageBox>
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
|
@ -125,7 +125,7 @@ void Widget::init()
|
|||
ui->menubar->hide();
|
||||
|
||||
idleTimer = new QTimer();
|
||||
idleTimer->start(10000);
|
||||
idleTimer->start(1000);
|
||||
|
||||
//restore window state
|
||||
restoreGeometry(Settings::getInstance().getWindowGeometry());
|
||||
|
|
Loading…
Reference in New Issue
Block a user