source: psi/trunk/src/tools/idle/idle_x11.cpp

Last change on this file was 2, checked in by dmik, 19 years ago

Imported original Psi 0.10 sources from Affinix

File size: 2.1 KB
Line 
1/*
2 * idle_x11.cpp - detect desktop idle time
3 * Copyright (C) 2003 Justin Karneges
4 *
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.
9 *
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.
14 *
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
18 *
19 */
20
21#include"idle.h"
22
23#ifndef HAVE_XSS
24
25IdlePlatform::IdlePlatform() {}
26IdlePlatform::~IdlePlatform() {}
27bool IdlePlatform::init() { return false; }
28int IdlePlatform::secondsIdle() { return 0; }
29
30#else
31
32#include<qapplication.h>
33
34#include<X11/Xlib.h>
35#include<X11/Xutil.h>
36#include<X11/extensions/scrnsaver.h>
37
38static XErrorHandler old_handler = 0;
39extern "C" int xerrhandler(Display* dpy, XErrorEvent* err)
40{
41 if(err->error_code == BadDrawable)
42 return 0;
43
44 return (*old_handler)(dpy, err);
45}
46
47class IdlePlatform::Private
48{
49public:
50 Private() {}
51
52 XScreenSaverInfo *ss_info;
53};
54
55IdlePlatform::IdlePlatform()
56{
57 d = new Private;
58 d->ss_info = 0;
59}
60
61IdlePlatform::~IdlePlatform()
62{
63 if(d->ss_info)
64 XFree(d->ss_info);
65 if(old_handler) {
66 XSetErrorHandler(old_handler);
67 old_handler = 0;
68 }
69 delete d;
70}
71
72bool IdlePlatform::init()
73{
74 if(d->ss_info)
75 return true;
76
77 old_handler = XSetErrorHandler(xerrhandler);
78
79 int event_base, error_base;
80 if(XScreenSaverQueryExtension(QApplication::desktop()->screen()->x11Display(), &event_base, &error_base)) {
81 d->ss_info = XScreenSaverAllocInfo();
82 return true;
83 }
84 return false;
85}
86
87int IdlePlatform::secondsIdle()
88{
89 if(!d->ss_info)
90 return 0;
91 if(!XScreenSaverQueryInfo(QApplication::desktop()->screen()->x11Display(), qt_xrootwin(), d->ss_info))
92 return 0;
93 return d->ss_info->idle / 1000;
94}
95
96#endif
Note: See TracBrowser for help on using the repository browser.