swift
joysticklinux.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2014 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
4 #ifndef SWIFT_INPUT_JOYSTICKLINUX_H
5 #define SWIFT_INPUT_JOYSTICKLINUX_H
6 
8 
9 #include <QMap>
10 #include <QString>
11 
12 #include "input/joystick.h"
13 #include "misc/collection.h"
15 
16 class QFile;
17 class QFileSystemWatcher;
18 class QSignalMapper;
19 
20 namespace swift::input
21 {
23  class CJoystickDevice : public QObject
24  {
25  Q_OBJECT
26 
27  public:
29  CJoystickDevice(const QString &path, QFile *fd, QObject *parent);
30  ~CJoystickDevice();
31 
33  QString getName() const { return m_name; }
34 
36  QString getPath() const { return m_path; }
37 
39  bool isAttached() const { return m_fd->exists(); }
40 
41  signals:
43  void buttonChanged(const QString &name, int index, bool isPressed);
44 
45  private:
47  void processInput();
48 
49  QString m_name;
50  QString m_path;
51  QFile *m_fd = nullptr;
52  };
53 
56  class CJoystickLinux : public IJoystick
57  {
58  Q_OBJECT
59 
60  public:
62  CJoystickLinux(CJoystickLinux const &) = delete;
63 
66 
68  virtual ~CJoystickLinux() = default;
69 
72 
73  private:
74  friend class IJoystick;
75 
77  void cleanupJoysticks();
78 
80  void addJoystickDevice(const QString &path);
81 
82  void joystickButtonChanged(const QString &name, int index, bool isPressed);
83 
85  CJoystickLinux(QObject *parent = nullptr);
86 
89  void reloadDevices(QString path);
90 
91  private:
92  swift::misc::input::CHotkeyCombination m_buttonCombination;
93  QVector<CJoystickDevice *> m_joystickDevices;
94  QFileSystemWatcher *m_inputWatcher = nullptr;
95  };
96 
97 } // namespace swift::input
98 
99 #endif // SWIFT_INPUT_JOYSTICKLINUX_H
Linux Joystick device.
Definition: joysticklinux.h:24
bool isAttached() const
Is joystick device still attached?
Definition: joysticklinux.h:39
QString getName() const
Get device name.
Definition: joysticklinux.h:33
void buttonChanged(const QString &name, int index, bool isPressed)
Joystick button changed.
QString getPath() const
Get device path, e.g. /dev/input/js0.
Definition: joysticklinux.h:36
CJoystickDevice(const QString &path, QFile *fd, QObject *parent)
Constructor.
Linux implemenation of IJoystick.
Definition: joysticklinux.h:57
CJoystickLinux(CJoystickLinux const &)=delete
Copy Constructor.
virtual swift::misc::input::CJoystickButtonList getAllAvailableJoystickButtons() const
Get all available joystick buttons.
virtual ~CJoystickLinux()=default
Destructor.
CJoystickLinux & operator=(CJoystickLinux const &)=delete
Assignment operator.
Abstract interface for native joystick handling.
Definition: joystick.h:22
Value object representing hotkey sequence.
Value object encapsulating a list of joystick buttons.