2
* idle_x11.cpp - detect desktop idle time
3
* Copyright (C) 2003 Justin Karneges
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
IdlePlatform::IdlePlatform() {}
26
IdlePlatform::~IdlePlatform() {}
27
bool IdlePlatform::init() { return false; }
28
int IdlePlatform::secondsIdle() { return 0; }
32
#include <qapplication.h>
33
#include <QDesktopWidget>
37
#include <X11/Xutil.h>
38
#include <X11/extensions/scrnsaver.h>
40
static XErrorHandler old_handler = 0;
41
extern "C" int xerrhandler(Display* dpy, XErrorEvent* err)
43
if(err->error_code == BadDrawable)
46
return (*old_handler)(dpy, err);
49
class IdlePlatform::Private
54
XScreenSaverInfo *ss_info;
57
IdlePlatform::IdlePlatform()
63
IdlePlatform::~IdlePlatform()
68
XSetErrorHandler(old_handler);
74
bool IdlePlatform::init()
79
old_handler = XSetErrorHandler(xerrhandler);
81
int event_base, error_base;
82
if(XScreenSaverQueryExtension(QApplication::desktop()->screen()->x11Display(), &event_base, &error_base)) {
83
d->ss_info = XScreenSaverAllocInfo();
89
int IdlePlatform::secondsIdle()
93
if(!XScreenSaverQueryInfo(QApplication::desktop()->screen()->x11Display(), QX11Info::appRootWindow(), d->ss_info))
95
return d->ss_info->idle / 1000;