swift
Loading...
Searching...
No Matches
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
16class QFile;
18class QSignalMapper;
19
20namespace swift::input
21{
23 class CJoystickDevice : public QObject
24 {
26
27 public:
29 CJoystickDevice(const QString &path, QFile *fd, QObject *parent);
30 ~CJoystickDevice() override;
31
33 const QString &getName() const { return m_name; }
34
36 const 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 {
59
60 public:
62 CJoystickLinux(CJoystickLinux const &) = delete;
63
66
68 ~CJoystickLinux() override = 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:
93 QVector<CJoystickDevice *> m_joystickDevices;
94 QFileSystemWatcher *m_inputWatcher = nullptr;
95 };
96
97} // namespace swift::input
98
99#endif // SWIFT_INPUT_JOYSTICKLINUX_H
bool isAttached() const
Is joystick device still attached?
const QString & getName() const
Get device name.
virtual ~CJoystickDevice()
Destructor.
void buttonChanged(const QString &name, int index, bool isPressed)
Joystick button changed.
const QString & getPath() const
Get device path, e.g. /dev/input/js0.
CJoystickDevice(const QString &path, QFile *fd, QObject *parent)
Constructor.
CJoystickLinux(CJoystickLinux const &)=delete
Copy Constructor.
swift::misc::input::CJoystickButtonList getAllAvailableJoystickButtons() const
Get all available joystick buttons.
CJoystickLinux & operator=(CJoystickLinux const &)=delete
Assignment operator.
~CJoystickLinux()=default
Destructor.
Value object representing hotkey sequence.
Value object encapsulating a list of joystick buttons.
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
QObject * parent() const const