swift
Loading...
Searching...
No Matches
joystickmacos.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2019 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
4#ifndef SWIFT_INPUT_JOYSTICKMACOS_H
5#define SWIFT_INPUT_JOYSTICKMACOS_H
6
8
9#include <IOKit/hid/IOHIDManager.h>
10
11#include <QHash>
12
13#include "input/joystick.h"
15
16namespace swift::input
17{
18
20 class CJoystickDevice : public QObject
21 {
23
24 public:
26 CJoystickDevice(QObject *parent = nullptr);
27
29 virtual ~CJoystickDevice() override;
30
32 bool init(const IOHIDDeviceRef device);
33
36
38 IOHIDDeviceRef getNativeDevice() const { return m_deviceRef; }
39
40 signals:
42 void buttonChanged(const swift::misc::input::CJoystickButton &joystickButton, bool isPressed);
43
44 private:
45 void processButtonEvent(IOHIDValueRef value);
46
47 static void valueCallback(void *context, IOReturn result, void *sender, IOHIDValueRef value);
48
49 QString m_deviceName = "unknown";
50 // IOHIDDeviceRef is owned by IOHIDManager. Do not release it.
51 IOHIDDeviceRef m_deviceRef = nullptr;
53 };
54
56 class CJoystickMacOS : public IJoystick
57 {
59
60 public:
62 CJoystickMacOS(CJoystickMacOS const &) = delete;
63
66
68 virtual ~CJoystickMacOS() override;
69
72
73 protected:
74 virtual bool init() override;
75
76 private:
77 friend class IJoystick;
78
80 CJoystickMacOS(QObject *parent = nullptr);
81
83 void addJoystickDevice(const IOHIDDeviceRef device);
84
86 void removeJoystickDevice(const IOHIDDeviceRef device);
87
88 void joystickButtonChanged(const swift::misc::input::CJoystickButton &joystickButton, bool isPressed);
89
90 static void matchCallback(void *context, IOReturn result, void *sender, IOHIDDeviceRef device);
91 static void removeCallback(void *context, IOReturn result, void *sender, IOHIDDeviceRef device);
92
93 IOHIDManagerRef m_hidManager = nullptr;
94 QVector<CJoystickDevice *> m_joystickDevices;
95
97 };
98
99} // namespace swift::input
100
101#endif // SWIFT_INPUT_JOYSTICKMACOS_H
Linux Joystick device.
bool init(const IOHIDDeviceRef device)
Initialize device.
IOHIDDeviceRef getNativeDevice() const
Return the native IOHIDDeviceRef.
virtual ~CJoystickDevice()
Destructor.
swift::misc::input::CJoystickButtonList getDeviceButtons() const
Get all available device buttons.
void buttonChanged(const swift::misc::input::CJoystickButton &joystickButton, bool isPressed)
Joystick button changed.
CJoystickDevice(const QString &path, QFile *fd, QObject *parent)
Constructor.
CJoystickMacOS & operator=(CJoystickMacOS const &)=delete
Assignment operator.
CJoystickMacOS(CJoystickMacOS const &)=delete
Copy Constructor.
virtual bool init()
Initializes the platform joystick devices.
virtual ~CJoystickMacOS()
Destructor.
virtual swift::misc::input::CJoystickButtonList getAllAvailableJoystickButtons() const
Get all available joystick buttons.
Value object representing hotkey sequence.
Value object representing a joystick button.
Value object encapsulating a list of joystick buttons.
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
QObject * parent() const const
QObject * sender() const const