Plasma
mouseengine.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 #include "mouseengine.h"
00020
00021 #include <QCursor>
00022
00023 #include <config-X11.h>
00024
00025 #ifdef HAVE_XFIXES
00026 # include "cursornotificationhandler.h"
00027 #endif
00028
00029
00030 MouseEngine::MouseEngine(QObject* parent, const QVariantList& args)
00031 : Plasma::DataEngine(parent, args), timerId(0), handler(0)
00032 {
00033 Q_UNUSED(args)
00034 }
00035
00036
00037 MouseEngine::~MouseEngine()
00038 {
00039 if (timerId)
00040 killTimer(timerId);
00041 #ifdef HAVE_XFIXES
00042 delete handler;
00043 #endif
00044 }
00045
00046
00047 QStringList MouseEngine::sources() const
00048 {
00049 QStringList list;
00050
00051 list << QLatin1String("Position");
00052 #ifdef HAVE_XFIXES
00053 list << QLatin1String("Name");
00054 #endif
00055
00056 return list;
00057 }
00058
00059
00060 void MouseEngine::init()
00061 {
00062 if (!timerId)
00063 timerId = startTimer(40);
00064
00065
00066 QPoint pos = QCursor::pos();
00067 setData(QLatin1String("Position"), QVariant(pos));
00068 lastPosition = pos;
00069
00070 #ifdef HAVE_XFIXES
00071 handler = new CursorNotificationHandler;
00072 connect(handler, SIGNAL(cursorNameChanged(QString)), SLOT(updateCursorName(QString)));
00073
00074 setData(QLatin1String("Name"), QVariant(handler->cursorName()));
00075 #endif
00076
00077 scheduleSourcesUpdated();
00078 }
00079
00080
00081 void MouseEngine::timerEvent(QTimerEvent *)
00082 {
00083 QPoint pos = QCursor::pos();
00084
00085 if (pos != lastPosition)
00086 {
00087 setData(QLatin1String("Position"), QVariant(pos));
00088 lastPosition = pos;
00089
00090 scheduleSourcesUpdated();
00091 }
00092 }
00093
00094
00095 void MouseEngine::updateCursorName(const QString &name)
00096 {
00097 setData(QLatin1String("Name"), QVariant(name));
00098 scheduleSourcesUpdated();
00099 }
00100
00101 #include "mouseengine.moc"
00102