• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDEUI

knotificationrestrictions.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002     Copyright (C) 2006 Aaron Seigo <aseigo@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to
00016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017     Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "knotificationrestrictions.h"
00021 
00022 #include <kdebug.h>
00023 
00024 #include <config.h>
00025 
00026 #include <QTimer>
00027 
00028 #ifdef HAVE_XTEST
00029 #include <QX11Info>
00030 
00031 #include <X11/keysym.h>
00032 #include <X11/extensions/XTest.h>
00033 #endif // HAVE_XTEST
00034 
00035 class KNotificationRestrictions::Private
00036 {
00037     public:
00038         Private( KNotificationRestrictions* qq, Services c )
00039             : q( qq ),
00040               control(c)
00041 #ifdef HAVE_XTEST
00042              ,screensaverTimer(0),
00043               haveXTest(0),
00044               XTestKeyCode(0)
00045 #endif // HAVE_XTEST
00046         {
00047         }
00048 
00049         void screensaverFakeKeyEvent();
00050         void startScreenSaverPrevention();
00051         void stopScreenSaverPrevention();
00052 
00053         KNotificationRestrictions* q;
00054         Services control;
00055         QTimer* screensaverTimer;
00056 #ifdef HAVE_XTEST
00057         int haveXTest;
00058         int XTestKeyCode;
00059 #endif // HAVE_XTEST
00060 };
00061 
00062 KNotificationRestrictions::KNotificationRestrictions( Services control,
00063                                                       QObject* parent )
00064     : QObject(parent),
00065       d( new Private( this, control ) )
00066 {
00067     if (d->control & ScreenSaver) {
00068         d->startScreenSaverPrevention();
00069     }
00070 }
00071 
00072 KNotificationRestrictions::~KNotificationRestrictions()
00073 {
00074     if (d->control & ScreenSaver) {
00075         d->stopScreenSaverPrevention();
00076     }
00077 
00078     delete d;
00079 }
00080 
00081 void KNotificationRestrictions::Private::screensaverFakeKeyEvent()
00082 {
00083     kDebug(297) << "KNotificationRestrictions::screensaverFakeKeyEvent()";
00084 #ifdef HAVE_XTEST
00085     kDebug(297) << "---- using XTestFakeKeyEvent";
00086     Display* display = QX11Info::display();
00087     XTestFakeKeyEvent(display, XTestKeyCode, true, CurrentTime);
00088     XTestFakeKeyEvent(display, XTestKeyCode, false, CurrentTime);
00089     XSync(display, false);
00090 #endif // HAVE_XTEST
00091 }
00092 
00093 void KNotificationRestrictions::Private::startScreenSaverPrevention()
00094 {
00095     kDebug(297) << "KNotificationRestrictions::startScreenSaverPrevention()";
00096 #ifdef HAVE_XTEST
00097     if ( !haveXTest ) {
00098         int a,b,c,e;
00099         haveXTest = XTestQueryExtension(QX11Info::display(), &a, &b, &c, &e);
00100 
00101         if ( !haveXTest ) {
00102             kDebug(297) << "--- No XTEST!";
00103             return;
00104         }
00105     }
00106 
00107     if ( !XTestKeyCode ) {
00108         XTestKeyCode = XKeysymToKeycode(QX11Info::display(), XK_Shift_L);
00109 
00110         if ( !XTestKeyCode ) {
00111             kDebug(297) << "--- No XKeyCode for XK_Shift_L!";
00112             return;
00113         }
00114     }
00115 
00116     if ( !screensaverTimer ) {
00117         screensaverTimer = new QTimer( q );
00118         connect( screensaverTimer, SIGNAL(timeout()),
00119                  q, SLOT(screensaverFakeKeyEvent()) );
00120     }
00121 
00122     kDebug(297) << "---- using XTest";
00123     // send a fake event right away in case this got started after a period of
00124     // innactivity leading to the screensaver set to activate in <55s
00125     screensaverFakeKeyEvent();
00126     screensaverTimer->start( 55000 );
00127 #endif // HAVE_XTEST
00128 }
00129 
00130 void KNotificationRestrictions::Private::stopScreenSaverPrevention()
00131 {
00132 #ifdef HAVE_XTEST
00133     delete screensaverTimer;
00134     screensaverTimer = 0;
00135 #endif // HAVE_XTEST
00136 }
00137 #include "knotificationrestrictions.moc"

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal