forked from jahnf/Projecteur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspotlight.h
42 lines (34 loc) · 1.3 KB
/
spotlight.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// This file is part of Projecteur - https://github.com/jahnf/projecteur - See LICENSE.md and README.md
#pragma once
#include <QObject>
#include <map>
class QSocketNotifier;
class QTimer;
/// Simple class to notify the application if the Logitech Spotlight sending mouse move events.
/// Used to turn the applications spot on or off.
class Spotlight : public QObject
{
Q_OBJECT
public:
explicit Spotlight(QObject* parent);
virtual ~Spotlight();
bool spotActive() const { return m_spotActive; }
bool anySpotlightDeviceConnected() const;
QStringList connectedDevices() const;
signals:
void error(const QString& errMsg);
void connected(const QString& devicePath); //!< signal for every device connected
void disconnected(const QString& devicePath); //!< signal for every device disconnected
void anySpotlightDeviceConnectedChanged(bool connected);
void spotActiveChanged(bool isActive);
private:
enum class ConnectionResult { CouldNotOpen, NotASpotlightDevice, Connected };
ConnectionResult connectSpotlightDevice(const QString& devicePath);
bool setupDevEventInotify();
int connectDevices();
void tryConnect(const QString& devicePath, int msec, int retries);
private:
std::map<QString, QScopedPointer<QSocketNotifier>> m_eventNotifiers;
QTimer* m_activeTimer;
bool m_spotActive = false;
};