diff options
| author | 2011-01-01 20:19:56 +0000 | |
|---|---|---|
| committer | 2011-01-01 20:19:56 +0000 | |
| commit | c601b5a27f74b16158adafe429faefbe573e64a2 (patch) | |
| tree | a3cde3206a45628f8ac86e8dfbdab70b20c3a831 /src/modules/my/Idle_x11.cpp | |
| parent | probable compilation fix for rijndaled/crypto++ (diff) | |
| download | KVIrc-c601b5a27f74b16158adafe429faefbe573e64a2.tar.gz KVIrc-c601b5a27f74b16158adafe429faefbe573e64a2.tar.bz2 KVIrc-c601b5a27f74b16158adafe429faefbe573e64a2.zip | |
The big rename for modules. Still some details remaining.
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@5284 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src/modules/my/Idle_x11.cpp')
| -rw-r--r-- | src/modules/my/Idle_x11.cpp | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/modules/my/Idle_x11.cpp b/src/modules/my/Idle_x11.cpp new file mode 100644 index 000000000..9b4c4a062 --- /dev/null +++ b/src/modules/my/Idle_x11.cpp @@ -0,0 +1,96 @@ +/* + * 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 COMPILE_ON_MAC +#if !defined(COMPILE_ON_WINDOWS) && !defined(COMPILE_ON_MINGW) + +#include"Idle.h" + +#ifndef COMPILE_XSS_SUPPORT + IdlePlatform::IdlePlatform() {} + IdlePlatform::~IdlePlatform() {} + bool IdlePlatform::init() const { return false; } + int IdlePlatform::secondsIdle() const { return 0; } +#else + #include <QApplication> + #include <QDesktopWidget> + #include <QX11Info> + + #include <X11/Xlib.h> + #include <X11/Xutil.h> + #include <X11/extensions/scrnsaver.h> + + 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() const + { + if(d->ss_info) + return true; + + old_handler = XSetErrorHandler(xerrhandler); + + int event_base, error_base; + if(XScreenSaverQueryExtension(QX11Info::display(), &event_base, &error_base)) { + d->ss_info = XScreenSaverAllocInfo(); + return true; + } + return false; + } + + int IdlePlatform::secondsIdle() const + { + if(!d->ss_info) return 0; + if(!XScreenSaverQueryInfo(QX11Info::display(), QX11Info::appRootWindow(), d->ss_info)) return 0; + return d->ss_info->idle / 1000; + } +#endif +#endif +#endif |
