add more spacing
[personal-kdebase.git] / workspace / plasma / dataengines / mouse / mouseengine.cpp
blob19a7fb7405647963ebadb4f71104e8164b729df7
1 /*
2 * Copyright © 2007 Fredrik Höglund <fredrik@kde.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License version 2 as
6 * published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
13 * You should have received a copy of the GNU Library General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "mouseengine.h"
21 #include <QCursor>
23 #ifdef HAVE_XFIXES
24 # include "cursornotificationhandler.h"
25 #endif
28 MouseEngine::MouseEngine(QObject* parent, const QVariantList& args)
29 : Plasma::DataEngine(parent, args), timerId(0)
30 #ifdef HAVE_XFIXES
31 , handler(0)
32 #endif
34 Q_UNUSED(args)
38 MouseEngine::~MouseEngine()
40 if (timerId)
41 killTimer(timerId);
42 #ifdef HAVE_XFIXES
43 delete handler;
44 #endif
48 QStringList MouseEngine::sources() const
50 QStringList list;
52 list << QLatin1String("Position");
53 #ifdef HAVE_XFIXES
54 list << QLatin1String("Name");
55 #endif
57 return list;
61 void MouseEngine::init()
63 if (!timerId)
64 timerId = startTimer(40);
66 // Init cursor position
67 QPoint pos = QCursor::pos();
68 setData(QLatin1String("Position"), QVariant(pos));
69 lastPosition = pos;
71 #ifdef HAVE_XFIXES
72 handler = new CursorNotificationHandler;
73 connect(handler, SIGNAL(cursorNameChanged(QString)), SLOT(updateCursorName(QString)));
75 setData(QLatin1String("Name"), QVariant(handler->cursorName()));
76 #endif
78 scheduleSourcesUpdated();
82 void MouseEngine::timerEvent(QTimerEvent *)
84 QPoint pos = QCursor::pos();
86 if (pos != lastPosition)
88 setData(QLatin1String("Position"), QVariant(pos));
89 lastPosition = pos;
91 scheduleSourcesUpdated();
96 void MouseEngine::updateCursorName(const QString &name)
98 setData(QLatin1String("Name"), QVariant(name));
99 scheduleSourcesUpdated();
102 #include "mouseengine.moc"