KDEUI
knotificationrestrictions.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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
00124
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"