Plasma5Support

mouseengine.cpp
1/*
2 SPDX-FileCopyrightText: 2007 Fredrik Höglund <fredrik@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-only
5*/
6
7#include "mouseengine.h"
8
9#include <QCursor>
10
11#if WITH_X11
12#include "cursornotificationhandler.h"
13#endif
14
15MouseEngine::MouseEngine(QObject *parent)
16 : Plasma5Support::DataEngine(parent)
17 , timerId(0)
18#if WITH_X11
19 , handler(nullptr)
20#endif
21{
22 init();
23}
24
25MouseEngine::~MouseEngine()
26{
27 if (timerId)
28 killTimer(timerId);
29#if WITH_X11
30 delete handler;
31#endif
32}
33
34QStringList MouseEngine::sources() const
35{
37
38 list << QLatin1String("Position");
39#if WITH_X11
40 list << QLatin1String("Name");
41#endif
42
43 return list;
44}
45
46void MouseEngine::init()
47{
48 if (!timerId)
49 timerId = startTimer(40);
50
51 // Init cursor position
52 QPoint pos = QCursor::pos();
53 setData(QLatin1String("Position"), QVariant(pos));
54 lastPosition = pos;
55
56#if WITH_X11
57 handler = new CursorNotificationHandler;
58 connect(handler, &CursorNotificationHandler::cursorNameChanged, this, &MouseEngine::updateCursorName);
59
60 setData(QLatin1String("Name"), QVariant(handler->cursorName()));
61#endif
62}
63
64void MouseEngine::timerEvent(QTimerEvent *)
65{
66 QPoint pos = QCursor::pos();
67
68 if (pos != lastPosition) {
69 setData(QLatin1String("Position"), QVariant(pos));
70 lastPosition = pos;
71 }
72}
73
74void MouseEngine::updateCursorName(const QString &name)
75{
76 setData(QLatin1String("Name"), QVariant(name));
77}
78
79K_PLUGIN_CLASS_WITH_JSON(MouseEngine, "plasma-dataengine-mouse.json")
80
81#include "mouseengine.moc"
#define K_PLUGIN_CLASS_WITH_JSON(classname, jsonFile)
void setData(const QString &source, const QVariant &value)
Sets a value for a data source.
KIOCORE_EXPORT QStringList list(const QString &fileClass)
Namespace for everything in libplasma.
Definition datamodel.cpp:15
QCA_EXPORT void init()
QPoint pos()
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void killTimer(int id)
int startTimer(int interval, Qt::TimerType timerType)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:38 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.