diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 02:13:59 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 02:13:59 +0000 |
commit | a6d58bb6052ac8cb01805a48c4ad2f129126116f (patch) | |
tree | dd867a099fcbb263a8009a9fb22695b87855dad6 /src/modules/my/idle_x11.cpp | |
download | kvirc-a6d58bb6052ac8cb01805a48c4ad2f129126116f.tar.gz kvirc-a6d58bb6052ac8cb01805a48c4ad2f129126116f.zip |
Added KDE3 version of kvirc
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kvirc@1095341 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/modules/my/idle_x11.cpp')
-rw-r--r-- | src/modules/my/idle_x11.cpp | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/modules/my/idle_x11.cpp b/src/modules/my/idle_x11.cpp new file mode 100644 index 00000000..fa2f1f15 --- /dev/null +++ b/src/modules/my/idle_x11.cpp @@ -0,0 +1,113 @@ +/* + * idle_x11.cpp - detect desktop idle time + * Copyright (C) 2003 Justin Karneges + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ +#ifndef Q_OS_MACX +#ifndef COMPILE_ON_WINDOWS + +#include"idle.h" + +#ifndef COMPILE_XSS_SUPPORT + +IdlePlatform::IdlePlatform() {} +IdlePlatform::~IdlePlatform() {} +bool IdlePlatform::init() { return false; } +int IdlePlatform::secondsIdle() { return 0; } + +#else + +#include<qapplication.h> + +#include<X11/Xlib.h> +#include<X11/Xutil.h> +#include<X11/extensions/scrnsaver.h> + +#ifdef COMPILE_USE_QT4 + #include <qdesktopwidget.h> +#endif + +static XErrorHandler old_handler = 0; +extern "C" int xerrhandler(Display* dpy, XErrorEvent* err) +{ + if(err->error_code == BadDrawable) + return 0; + + return (*old_handler)(dpy, err); +} + +class IdlePlatform::Private +{ +public: + Private() {} + + XScreenSaverInfo *ss_info; +}; + +IdlePlatform::IdlePlatform() +{ + d = new Private; + d->ss_info = 0; +} + +IdlePlatform::~IdlePlatform() +{ + if(d->ss_info) + XFree(d->ss_info); + if(old_handler) { + XSetErrorHandler(old_handler); + old_handler = 0; + } + delete d; +} + +bool IdlePlatform::init() +{ + if(d->ss_info) + return true; + + old_handler = XSetErrorHandler(xerrhandler); + + int event_base, error_base; + if(XScreenSaverQueryExtension(QApplication::desktop()->screen()->x11Display(), &event_base, &error_base)) { + d->ss_info = XScreenSaverAllocInfo(); + return true; + } + return false; +} + +#ifdef COMPILE_USE_QT4 + #include <qx11info_x11.h> +#endif + +int IdlePlatform::secondsIdle() +{ + if(!d->ss_info) + return 0; +#ifdef COMPILE_USE_QT4 + if(!XScreenSaverQueryInfo(QApplication::desktop()->screen()->x11Display(), QX11Info::appRootWindow(), d->ss_info)) +#else + if(!XScreenSaverQueryInfo(QApplication::desktop()->screen()->x11Display(), qt_xrootwin(), d->ss_info)) +#endif + return 0; + return d->ss_info->idle / 1000; +} + +#endif + +#endif +#endif |