File indexing completed on 2024-05-19 05:37:51
0001 /* 0002 SPDX-FileCopyrightText: 2007 Fredrik Höglund <fredrik@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #include "mouseengine.h" 0008 0009 #include <QCursor> 0010 0011 #ifdef HAVE_XFIXES 0012 #include "cursornotificationhandler.h" 0013 #endif 0014 0015 MouseEngine::MouseEngine(QObject *parent) 0016 : Plasma5Support::DataEngine(parent) 0017 , timerId(0) 0018 #ifdef HAVE_XFIXES 0019 , handler(nullptr) 0020 #endif 0021 { 0022 init(); 0023 } 0024 0025 MouseEngine::~MouseEngine() 0026 { 0027 if (timerId) 0028 killTimer(timerId); 0029 #ifdef HAVE_XFIXES 0030 delete handler; 0031 #endif 0032 } 0033 0034 QStringList MouseEngine::sources() const 0035 { 0036 QStringList list; 0037 0038 list << QLatin1String("Position"); 0039 #ifdef HAVE_XFIXES 0040 list << QLatin1String("Name"); 0041 #endif 0042 0043 return list; 0044 } 0045 0046 void MouseEngine::init() 0047 { 0048 if (!timerId) 0049 timerId = startTimer(40); 0050 0051 // Init cursor position 0052 QPoint pos = QCursor::pos(); 0053 setData(QLatin1String("Position"), QVariant(pos)); 0054 lastPosition = pos; 0055 0056 #ifdef HAVE_XFIXES 0057 handler = new CursorNotificationHandler; 0058 connect(handler, &CursorNotificationHandler::cursorNameChanged, this, &MouseEngine::updateCursorName); 0059 0060 setData(QLatin1String("Name"), QVariant(handler->cursorName())); 0061 #endif 0062 } 0063 0064 void MouseEngine::timerEvent(QTimerEvent *) 0065 { 0066 QPoint pos = QCursor::pos(); 0067 0068 if (pos != lastPosition) { 0069 setData(QLatin1String("Position"), QVariant(pos)); 0070 lastPosition = pos; 0071 } 0072 } 0073 0074 void MouseEngine::updateCursorName(const QString &name) 0075 { 0076 setData(QLatin1String("Name"), QVariant(name)); 0077 } 0078 0079 K_PLUGIN_CLASS_WITH_JSON(MouseEngine, "plasma-dataengine-mouse.json") 0080 0081 #include "mouseengine.moc"