1
//----------------------------------------------------------------------------
3
// This file is part of the KDE project
5
// Copyright (c) 1999 Martin R. Jones <mjones@kde.org>
6
// Copyright (c) 2003 Lubos Lunak <l.lunak@kde.org>
8
// KDE screensaver engine
15
#include "xautolock.h"
16
#include "xautolock.moc"
18
#include <kapplication.h>
22
#include <X11/Xutil.h>
24
#include "xautolock_c.h"
27
int xautolock_useXidle = 0;
28
int xautolock_useMit = 0;
29
xautolock_corner_t xautolock_corners[ 4 ];
31
static XAutoLock* self = NULL;
33
static int catchFalseAlarms(Display *, XErrorEvent *)
38
//===========================================================================
40
// Detect user inactivity.
41
// Named XAutoLock after the program that it is based on.
43
XAutoLock::XAutoLock()
47
dummy = dummy; // shut up
48
xautolock_useXidle = 0;
50
// code for corners (see #13360)
51
// setting a corner to ca_forceLock or ca_dontLock
52
// makes that corner start screensaver or prevent
54
// the order is topleft, topright, bottomleft, bottomright
55
// So when you add GUI for this, add a method changing these values.
56
#if 0 //now we have a GUI to configure it. => use value load to kconfig and not re-initialise value
57
xautolock_corners[ 0 ] = ca_nothing;
58
xautolock_corners[ 1 ] = ca_nothing;
59
xautolock_corners[ 2 ] = ca_nothing;
60
xautolock_corners[ 3 ] = ca_nothing;
63
useXidle = XidleQueryExtension( qt_xdisplay(), &dummy, &dummy );
65
#ifdef HAVE_XSCREENSAVER
66
if( !xautolock_useXidle )
67
xautolock_useMit = XScreenSaverQueryExtension( qt_xdisplay(), &dummy, &dummy );
69
if( !xautolock_useXidle && !xautolock_useMit )
71
kapp->installX11EventFilter( this );
72
int (*oldHandler)(Display *, XErrorEvent *);
73
oldHandler = XSetErrorHandler(catchFalseAlarms);
74
XSync(qt_xdisplay(), False );
75
xautolock_initDiy( qt_xdisplay());
76
XSync(qt_xdisplay(), False );
77
XSetErrorHandler(oldHandler);
80
mTimeout = DEFAULT_TIMEOUT;
86
mTimerId = startTimer( CHECK_INTERVAL );
90
//---------------------------------------------------------------------------
94
XAutoLock::~XAutoLock()
99
//---------------------------------------------------------------------------
101
// The time in seconds of continuous inactivity.
103
void XAutoLock::setTimeout(int t)
109
//---------------------------------------------------------------------------
111
// Start watching Activity
113
void XAutoLock::start()
120
//---------------------------------------------------------------------------
122
// Stop watching Activity
124
void XAutoLock::stop()
129
//---------------------------------------------------------------------------
131
// Reset the trigger time.
133
void XAutoLock::resetTrigger()
135
mTrigger = time(0) + mTimeout;
138
//---------------------------------------------------------------------------
140
// Set the remaining time to 't', if it's shorter than already set.
142
void XAutoLock::setTrigger( time_t t )
148
//---------------------------------------------------------------------------
150
// Process new windows and check the mouse.
152
void XAutoLock::timerEvent(QTimerEvent *ev)
154
if (ev->timerId() != mTimerId)
159
int (*oldHandler)(Display *, XErrorEvent *) = NULL;
160
if( !xautolock_useXidle && !xautolock_useMit )
161
{ // only the diy way needs special X handler
162
XSync( qt_xdisplay(), False );
163
oldHandler = XSetErrorHandler(catchFalseAlarms);
166
xautolock_processQueue();
168
time_t now = time(0);
169
if ((now > mLastTimeout && now - mLastTimeout > TIME_CHANGE_LIMIT) ||
170
(mLastTimeout > now && mLastTimeout - now > TIME_CHANGE_LIMIT+1))
172
/* the time has changed in one large jump. This could be because
173
the date was changed, or the machine was suspended. We'll just
180
xautolock_queryIdleTime( qt_xdisplay());
181
xautolock_queryPointer( qt_xdisplay());
183
if( !xautolock_useXidle && !xautolock_useMit )
184
XSetErrorHandler(oldHandler);
194
bool XAutoLock::x11Event( XEvent* ev )
196
xautolock_processEvent( ev );
197
// don't futher process key events that were received only because XAutoLock wants them
198
if( ev->type == KeyPress && !ev->xkey.send_event
199
&& !xautolock_useXidle && !xautolock_useMit
200
&& !QWidget::find( ev->xkey.window ))
205
bool XAutoLock::ignoreWindow( WId w )
207
if( w != qt_xrootwin() && QWidget::find( w ))
213
void xautolock_resetTriggers()
215
self->resetTrigger();
219
void xautolock_setTrigger( time_t t )
221
self->setTrigger( t );
225
int xautolock_ignoreWindow( Window w )
227
return self->ignoreWindow( w );