aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/gamepads
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/gamepads')
-rw-r--r--src/plugins/gamepads/android/android.pro2
-rw-r--r--src/plugins/gamepads/android/jar/jar.pro18
-rw-r--r--src/plugins/gamepads/android/jar/src/org/qtproject/qt/android/gamepad/QtGamepad.java110
-rw-r--r--src/plugins/gamepads/android/src/android.json3
-rw-r--r--src/plugins/gamepads/android/src/main.cpp61
-rw-r--r--src/plugins/gamepads/android/src/qandroidgamepadbackend.cpp635
-rw-r--r--src/plugins/gamepads/android/src/qandroidgamepadbackend_p.h135
-rw-r--r--src/plugins/gamepads/android/src/src.pro17
-rw-r--r--src/plugins/gamepads/darwin/darwin.json3
-rw-r--r--src/plugins/gamepads/darwin/darwin.pro19
-rw-r--r--src/plugins/gamepads/darwin/main.cpp61
-rw-r--r--src/plugins/gamepads/darwin/qdarwingamepadbackend.mm570
-rw-r--r--src/plugins/gamepads/darwin/qdarwingamepadbackend_p.h77
-rw-r--r--src/plugins/gamepads/evdev/evdev.json3
-rw-r--r--src/plugins/gamepads/evdev/evdev.pro14
-rw-r--r--src/plugins/gamepads/evdev/main.cpp62
-rw-r--r--src/plugins/gamepads/evdev/qevdevgamepadbackend.cpp553
-rw-r--r--src/plugins/gamepads/evdev/qevdevgamepadbackend_p.h138
-rw-r--r--src/plugins/gamepads/gamepads.pro7
-rw-r--r--src/plugins/gamepads/sdl2/main.cpp61
-rw-r--r--src/plugins/gamepads/sdl2/qsdlgamepadbackend.cpp210
-rw-r--r--src/plugins/gamepads/sdl2/qsdlgamepadbackend_p.h74
-rw-r--r--src/plugins/gamepads/sdl2/sdl2.json3
-rw-r--r--src/plugins/gamepads/sdl2/sdl2.pro17
-rw-r--r--src/plugins/gamepads/xinput/main.cpp62
-rw-r--r--src/plugins/gamepads/xinput/qxinputgamepadbackend.cpp291
-rw-r--r--src/plugins/gamepads/xinput/qxinputgamepadbackend_p.h63
-rw-r--r--src/plugins/gamepads/xinput/xinput.json3
-rw-r--r--src/plugins/gamepads/xinput/xinput.pro14
29 files changed, 0 insertions, 3286 deletions
diff --git a/src/plugins/gamepads/android/android.pro b/src/plugins/gamepads/android/android.pro
deleted file mode 100644
index 6ad7e3b..0000000
--- a/src/plugins/gamepads/android/android.pro
+++ /dev/null
@@ -1,2 +0,0 @@
-TEMPLATE=subdirs
-SUBDIRS += jar src
diff --git a/src/plugins/gamepads/android/jar/jar.pro b/src/plugins/gamepads/android/jar/jar.pro
deleted file mode 100644
index 879bbd9..0000000
--- a/src/plugins/gamepads/android/jar/jar.pro
+++ /dev/null
@@ -1,18 +0,0 @@
-TARGET = Qt$${QT_MAJOR_VERSION}AndroidGamepad
-
-load(qt_build_paths)
-CONFIG += java
-
-DESTDIR = $$MODULE_BASE_OUTDIR/jar
-
-API_VERSION = android-16
-
-JAVACLASSPATH += $$PWD/src
-
-JAVASOURCES += $$PWD/src/org/qtproject/qt/android/gamepad/QtGamepad.java
-
-# install
-target.path = $$[QT_INSTALL_PREFIX]/jar
-INSTALLS += target
-
-OTHER_FILES += $$JAVASOURCES
diff --git a/src/plugins/gamepads/android/jar/src/org/qtproject/qt/android/gamepad/QtGamepad.java b/src/plugins/gamepads/android/jar/src/org/qtproject/qt/android/gamepad/QtGamepad.java
deleted file mode 100644
index 94ffa9f..0000000
--- a/src/plugins/gamepads/android/jar/src/org/qtproject/qt/android/gamepad/QtGamepad.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 BogDan Vatra <bogdan@kde.org>
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-package org.qtproject.qt.android.gamepad;
-
-import android.app.Activity;
-import android.content.Context;
-import android.hardware.input.InputManager;
-import android.os.Handler;
-
-
-public class QtGamepad {
- private long m_nativePtr = 0;
- private InputManager m_manager;
- Activity m_activity;
- private InputManager.InputDeviceListener m_listener = new InputManager.InputDeviceListener() {
- @Override
- public void onInputDeviceAdded(int i) {
- synchronized (QtGamepad.this) {
- QtGamepad.onInputDeviceAdded(m_nativePtr, i);
- }
- }
-
- @Override
- public void onInputDeviceRemoved(int i) {
- synchronized (QtGamepad.this) {
- QtGamepad.onInputDeviceRemoved(m_nativePtr, i);
- }
- }
-
- @Override
- public void onInputDeviceChanged(int i) {
- synchronized (QtGamepad.this) {
- QtGamepad.onInputDeviceChanged(m_nativePtr, i);
- }
- }
- };
-
- QtGamepad(Activity activity)
- {
- m_manager = (InputManager) activity.getSystemService(Context.INPUT_SERVICE);
- m_activity = activity;
- }
-
- public void register(long nativePtr)
- {
- synchronized (this) {
- if (m_manager != null) {
- m_nativePtr = nativePtr;
- m_activity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- m_manager.registerInputDeviceListener(m_listener, new Handler());
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- }
- }
-
- public void unregister()
- {
- synchronized (this) {
- if (m_manager != null) {
- m_nativePtr = 0;
- m_manager.unregisterInputDeviceListener(m_listener);
- }
- }
- }
-
- private static native void onInputDeviceAdded(long nativePtr, int deviceId);
- private static native void onInputDeviceRemoved(long nativePtr, int deviceId);
- private static native void onInputDeviceChanged(long nativePtr, int deviceId);
-}
diff --git a/src/plugins/gamepads/android/src/android.json b/src/plugins/gamepads/android/src/android.json
deleted file mode 100644
index 6843bd3..0000000
--- a/src/plugins/gamepads/android/src/android.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "Keys": [ "android" ]
-}
diff --git a/src/plugins/gamepads/android/src/main.cpp b/src/plugins/gamepads/android/src/main.cpp
deleted file mode 100644
index 97af630..0000000
--- a/src/plugins/gamepads/android/src/main.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtGamepad/private/qgamepadbackendfactory_p.h>
-#include <QtGamepad/private/qgamepadbackendplugin_p.h>
-
-#include "qandroidgamepadbackend_p.h"
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidGamepadBackendPlugin : public QGamepadBackendPlugin
-{
- Q_OBJECT
- Q_PLUGIN_METADATA(IID QtGamepadBackendFactoryInterface_iid FILE "android.json")
-public:
- QGamepadBackend *create(const QString &key, const QStringList &paramList) override;
-};
-
-QGamepadBackend *QAndroidGamepadBackendPlugin::create(const QString &key, const QStringList &paramList) {
- Q_UNUSED(key);
- Q_UNUSED(paramList);
-
- return new QAndroidGamepadBackend();
-}
-
-QT_END_NAMESPACE
-
-#include "main.moc"
diff --git a/src/plugins/gamepads/android/src/qandroidgamepadbackend.cpp b/src/plugins/gamepads/android/src/qandroidgamepadbackend.cpp
deleted file mode 100644
index eae0e6a..0000000
--- a/src/plugins/gamepads/android/src/qandroidgamepadbackend.cpp
+++ /dev/null
@@ -1,635 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 BogDan Vatra <bogdan@kde.org>
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "qandroidgamepadbackend_p.h"
-
-#include <QtCore/QCoreApplication>
-#include <QtCore/QEvent>
-#include <QtCore/QPair>
-#include <QtCore/QThread>
-#include <QtCore/QList>
-
-#include <functional>
-#include <vector>
-
-#include <QVariant>
-#include <jni.h>
-#include <math.h>
-
-QT_BEGIN_NAMESPACE
-namespace {
- const QLatin1String AXES_KEY("axes");
- const QLatin1String BUTTONS_KEY("buttons");
-
- class FunctionEvent : public QEvent
- {
- typedef std::function<void()> Function;
- public:
- explicit FunctionEvent(const Function &func)
- : QEvent(QEvent::User)
- , m_function(func)
- {}
- inline void call() { m_function(); }
- static inline void runOnQtThread(QObject *receiver, const Function &func) {
- if (qApp->thread() == QThread::currentThread())
- func();
- else
- qApp->postEvent(receiver, new FunctionEvent(func));
- }
-
- private:
- Function m_function;
- };
-
- const char keyEventClass[] = "android/view/KeyEvent";
- inline int keyField(const char *field)
- {
- return QJNIObjectPrivate::getStaticField<jint>(keyEventClass, field);
- }
-
- const char motionEventClass[] = "android/view/MotionEvent";
- inline int motionField(const char *field)
- {
- return QJNIObjectPrivate::getStaticField<jint>(motionEventClass, field);
- }
-
- const char inputDeviceClass[] = "android/view/InputDevice";
- inline int inputDeviceField(const char *field)
- {
- return QJNIObjectPrivate::getStaticField<jint>(inputDeviceClass, field);
- }
-
-
- struct DefaultMapping : public QAndroidGamepadBackend::Mapping {
- DefaultMapping()
- {
- buttonsMap[keyField("KEYCODE_BUTTON_A")] = QGamepadManager::ButtonA;
- buttonsMap[keyField("KEYCODE_BUTTON_B")] = QGamepadManager::ButtonB;
- buttonsMap[keyField("KEYCODE_BUTTON_X")] = QGamepadManager::ButtonX;
- buttonsMap[keyField("KEYCODE_BUTTON_Y")] = QGamepadManager::ButtonY;
- buttonsMap[keyField("KEYCODE_BUTTON_L1")] = QGamepadManager::ButtonL1;
- buttonsMap[keyField("KEYCODE_BUTTON_R1")] = QGamepadManager::ButtonR1;
- buttonsMap[keyField("KEYCODE_BUTTON_L2")] = QGamepadManager::ButtonL2;
- buttonsMap[keyField("KEYCODE_BUTTON_R2")] = QGamepadManager::ButtonR2;
- buttonsMap[keyField("KEYCODE_BUTTON_SELECT")] = QGamepadManager::ButtonSelect;
- buttonsMap[keyField("KEYCODE_BUTTON_START")] = QGamepadManager::ButtonStart;
- buttonsMap[keyField("KEYCODE_BUTTON_THUMBL")] = QGamepadManager::ButtonL3;
- buttonsMap[keyField("KEYCODE_BUTTON_THUMBR")] = QGamepadManager::ButtonR3;
- buttonsMap[keyField("KEYCODE_DPAD_UP")] = QGamepadManager::ButtonUp;
- buttonsMap[keyField("KEYCODE_DPAD_DOWN")] = QGamepadManager::ButtonDown;
- buttonsMap[keyField("KEYCODE_DPAD_RIGHT")] = QGamepadManager::ButtonRight;
- buttonsMap[keyField("KEYCODE_DPAD_LEFT")] = QGamepadManager::ButtonLeft;
- buttonsMap[keyField("KEYCODE_DPAD_CENTER")] = QGamepadManager::ButtonCenter;
- buttonsMap[keyField("KEYCODE_BUTTON_MODE")] = QGamepadManager::ButtonGuide;
-
- if (QtAndroidPrivate::androidSdkVersion() >= 12) {
- axisMap[motionField("AXIS_X")].gamepadAxis = QGamepadManager::AxisLeftX;
- axisMap[motionField("AXIS_Y")].gamepadAxis = QGamepadManager::AxisLeftY;
- axisMap[motionField("AXIS_HAT_X")].gamepadAxis = QGamepadManager::AxisLeftX;
- axisMap[motionField("AXIS_HAT_Y")].gamepadAxis = QGamepadManager::AxisLeftY;
- axisMap[motionField("AXIS_Z")].gamepadAxis = QGamepadManager::AxisRightX;
- axisMap[motionField("AXIS_RZ")].gamepadAxis = QGamepadManager::AxisRightY;
- {
- auto &axis = axisMap[motionField("AXIS_LTRIGGER")];
- axis.gamepadAxis = QGamepadManager::AxisInvalid;
- axis.gamepadMinButton = QGamepadManager::ButtonL2;
- axis.gamepadMaxButton = QGamepadManager::ButtonL2;
- }
- {
- auto &axis = axisMap[motionField("AXIS_RTRIGGER")];
- axis.gamepadAxis = QGamepadManager::AxisInvalid;
- axis.gamepadMinButton = QGamepadManager::ButtonR2;
- axis.gamepadMaxButton = QGamepadManager::ButtonR2;
- }
-
- allAndroidAxes.push_back(motionField("AXIS_X"));
- allAndroidAxes.push_back(motionField("AXIS_Y"));
- allAndroidAxes.push_back(motionField("AXIS_Z"));
- allAndroidAxes.push_back(motionField("AXIS_RZ"));
- allAndroidAxes.push_back(motionField("AXIS_BRAKE"));
- allAndroidAxes.push_back(motionField("AXIS_GAS"));
-
- for (int i = 1; i < 16; ++i)
- allAndroidAxes.push_back(motionField(QByteArray("AXIS_GENERIC_").append(QByteArray::number(i)).constData()));
-
- allAndroidAxes.push_back(motionField("AXIS_HAT_X"));
- allAndroidAxes.push_back(motionField("AXIS_HAT_Y"));
- allAndroidAxes.push_back(motionField("AXIS_LTRIGGER"));
- allAndroidAxes.push_back(motionField("AXIS_RTRIGGER"));
- allAndroidAxes.push_back(motionField("AXIS_RUDDER"));
- allAndroidAxes.push_back(motionField("AXIS_THROTTLE"));
- allAndroidAxes.push_back(motionField("AXIS_WHEEL"));
- }
-
- if (QtAndroidPrivate::androidSdkVersion() >= 12) {
- acceptedSources.push_back(inputDeviceField("SOURCE_GAMEPAD"));
- acceptedSources.push_back(inputDeviceField("SOURCE_CLASS_JOYSTICK"));
- if (QtAndroidPrivate::androidSdkVersion() >= 21) {
- acceptedSources.push_back(inputDeviceField("SOURCE_HDMI"));
- }
- } else {
- acceptedSources.push_back(inputDeviceField("SOURCE_DPAD"));
- }
-
- ACTION_DOWN = keyField("ACTION_DOWN");
- ACTION_UP = keyField("ACTION_UP");
- ACTION_MULTIPLE = keyField("ACTION_MULTIPLE");
- FLAG_LONG_PRESS = keyField("FLAG_LONG_PRESS");
- }
- std::vector<int> acceptedSources;
- std::vector<int> allAndroidAxes;
- int ACTION_DOWN, ACTION_MULTIPLE, ACTION_UP, FLAG_LONG_PRESS;
- };
-
- void onInputDeviceAdded(JNIEnv *, jclass, jlong qtNativePtr, int deviceId)
- {
- if (!qtNativePtr)
- return;
- reinterpret_cast<QAndroidGamepadBackend*>(qtNativePtr)->addDevice(deviceId);
- }
- void onInputDeviceRemoved(JNIEnv *, jclass, jlong qtNativePtr, int deviceId)
- {
- if (!qtNativePtr)
- return;
- reinterpret_cast<QAndroidGamepadBackend*>(qtNativePtr)->removeDevice(deviceId);
- }
- void onInputDeviceChanged(JNIEnv *, jclass, jlong qtNativePtr, int deviceId)
- {
- if (!qtNativePtr)
- return;
- reinterpret_cast<QAndroidGamepadBackend*>(qtNativePtr)->updateDevice(deviceId);
- }
-
- static JNINativeMethod methods[] = {
- {"onInputDeviceAdded", "(JI)V", (void *)onInputDeviceAdded},
- {"onInputDeviceRemoved", "(JI)V", (void *)onInputDeviceRemoved},
- {"onInputDeviceChanged", "(JI)V", (void *)onInputDeviceChanged}
- };
-
- const char qtGamePadClassName[] = "org/qtproject/qt/android/gamepad/QtGamepad";
-
- inline void setAxisInfo(QJNIObjectPrivate &event, int axis, QAndroidGamepadBackend::Mapping::AndroidAxisInfo &info)
- {
- QJNIObjectPrivate device(event.callObjectMethod("getDevice", "()Landroid/view/InputDevice;"));
- if (device.isValid()) {
- const int source = event.callMethod<jint>("getSource", "()I");
- QJNIObjectPrivate motionRange = device.callObjectMethod("getMotionRange","(II)Landroid/view/InputDevice$MotionRange;", axis, source);
- if (motionRange.isValid()) {
- info.flatArea = motionRange.callMethod<jfloat>("getFlat", "()F");
- info.minValue = motionRange.callMethod<jfloat>("getMin", "()F");
- info.maxValue = motionRange.callMethod<jfloat>("getMax", "()F");
- info.fuzz = motionRange.callMethod<jfloat>("getFuzz", "()F");
- return;
- }
- }
- info.flatArea = 0;
- }
-
-} // namespace
-
-Q_GLOBAL_STATIC(DefaultMapping, g_defaultMapping)
-
-void QAndroidGamepadBackend::Mapping::AndroidAxisInfo::restoreSavedData(const QVariantMap &value)
-{
- gamepadAxis = QGamepadManager::GamepadAxis(value[QLatin1String("axis")].toInt());
- gamepadMinButton = QGamepadManager::GamepadButton(value[QLatin1String("minButton")].toInt());
- gamepadMaxButton = QGamepadManager::GamepadButton(value[QLatin1String("maxButton")].toInt());
-}
-
-QVariantMap QAndroidGamepadBackend::Mapping::AndroidAxisInfo::dataToSave() const
-{
- QVariantMap data;
- data[QLatin1String("axis")] = gamepadAxis;
- data[QLatin1String("minButton")] = gamepadMinButton;
- data[QLatin1String("maxButton")] = gamepadMaxButton;
- return data;
-}
-
-QAndroidGamepadBackend::QAndroidGamepadBackend(QObject *parent)
- : QGamepadBackend(parent)
-{
- QtAndroidPrivate::registerGenericMotionEventListener(this);
- QtAndroidPrivate::registerKeyEventListener(this);
-}
-
-QAndroidGamepadBackend::~QAndroidGamepadBackend()
-{
- QtAndroidPrivate::unregisterGenericMotionEventListener(this);
- QtAndroidPrivate::unregisterKeyEventListener(this);
-}
-
-void QAndroidGamepadBackend::addDevice(int deviceId)
-{
- if (deviceId == -1)
- return;
-
- QMutexLocker lock(&m_mutex);
- QJNIObjectPrivate inputDevice = QJNIObjectPrivate::callStaticObjectMethod(inputDeviceClass, "getDevice", "(I)Landroid/view/InputDevice;", deviceId);
- int sources = inputDevice.callMethod<jint>("getSources", "()I");
- bool acceptable = false;
- for (int source : g_defaultMapping()->acceptedSources) {
- if ( (source & sources) == source) {
- acceptable = true;
- break;
- }
- }
-
- if (acceptable) {
- m_devices.insert(deviceId, *g_defaultMapping());
- int productId = qHash(inputDevice.callObjectMethod("getDescriptor", "()Ljava/lang/String;").toString());
- m_devices[deviceId].productId = productId;
- if (productId) {
- QVariant settings = readSettings(productId);
- if (!settings.isNull()) {
- auto &deviceInfo = m_devices[deviceId];
- deviceInfo.needsConfigure = false;
-
- QVariantMap data = settings.toMap()[AXES_KEY].toMap();
- for (QVariantMap::const_iterator it = data.begin(); it != data.end(); ++it)
- deviceInfo.axisMap[it.key().toInt()].restoreSavedData(it.value().toMap());
-
- data = settings.toMap()[BUTTONS_KEY].toMap();
- for (QVariantMap::const_iterator it = data.begin(); it != data.end(); ++it)
- deviceInfo.buttonsMap[it.key().toInt()] = QGamepadManager::GamepadButton(it.value().toInt());
- }
- }
- FunctionEvent::runOnQtThread(this, [this, deviceId]{
- emit gamepadAdded(deviceId);
- });
- }
-}
-
-void QAndroidGamepadBackend::updateDevice(int deviceId)
-{
- Q_UNUSED(deviceId);
- //QMutexLocker lock(&m_mutex);
-}
-
-void QAndroidGamepadBackend::removeDevice(int deviceId)
-{
- QMutexLocker lock(&m_mutex);
- if (m_devices.remove(deviceId)) {
- FunctionEvent::runOnQtThread(this, [this, deviceId]{
- emit gamepadRemoved(deviceId);
- });
- }
-}
-
-bool QAndroidGamepadBackend::event(QEvent *ev)
-{
- if (ev->type() == QEvent::User) {
- static_cast<FunctionEvent*>(ev)->call();
- return true;
- }
- return QGamepadBackend::event(ev);
-}
-
-bool QAndroidGamepadBackend::isConfigurationNeeded(int deviceId)
-{
- QMutexLocker lock(&m_mutex);
- auto it = m_devices.find(deviceId);
- if (it == m_devices.end())
- return false;
- return it->needsConfigure;
-}
-
-bool QAndroidGamepadBackend::configureButton(int deviceId, QGamepadManager::GamepadButton button)
-{
- QMutexLocker lock(&m_mutex);
- auto it = m_devices.find(deviceId);
- if (it == m_devices.end())
- return false;
-
- it.value().calibrateButton = button;
- return true;
-}
-
-bool QAndroidGamepadBackend::configureAxis(int deviceId, QGamepadManager::GamepadAxis axis)
-{
- QMutexLocker lock(&m_mutex);
- auto it = m_devices.find(deviceId);
- if (it == m_devices.end())
- return false;
-
- it.value().calibrateAxis = axis;
- return true;
-}
-
-bool QAndroidGamepadBackend::setCancelConfigureButton(int deviceId, QGamepadManager::GamepadButton button)
-{
- QMutexLocker lock(&m_mutex);
- auto it = m_devices.find(deviceId);
- if (it == m_devices.end())
- return false;
-
- it.value().cancelConfigurationButton = button;
- return true;
-}
-
-void QAndroidGamepadBackend::resetConfiguration(int deviceId)
-{
- QMutexLocker lock(&m_mutex);
- auto it = m_devices.find(deviceId);
- if (it == m_devices.end())
- return;
-
- it.value().axisMap.clear();
- it.value().buttonsMap.clear();
- it.value().calibrateButton = QGamepadManager::ButtonInvalid;
- it.value().calibrateAxis = QGamepadManager::AxisInvalid;
- it.value().cancelConfigurationButton = QGamepadManager::ButtonInvalid;
- it.value().needsConfigure = false;
-}
-
-bool QAndroidGamepadBackend::handleKeyEvent(jobject event)
-{
- QJNIObjectPrivate ev(event);
- QMutexLocker lock(&m_mutex);
- const int deviceId = ev.callMethod<jint>("getDeviceId", "()I");
- const auto deviceIt = m_devices.find(deviceId);
- if (deviceIt == m_devices.end())
- return false;
-
- const int action = ev.callMethod<jint>("getAction", "()I");
- if (action != g_defaultMapping()->ACTION_DOWN &&
- action != g_defaultMapping()->ACTION_UP) {
- return false;
- }
- const int flags = ev.callMethod<jint>("getFlags", "()I");
- if ((flags & g_defaultMapping()->FLAG_LONG_PRESS) == g_defaultMapping()->FLAG_LONG_PRESS)
- return false;
-
- const int keyCode = ev.callMethod<jint>("getKeyCode", "()I");
- auto &deviceMap = deviceIt.value();
-
- if (deviceMap.cancelConfigurationButton != QGamepadManager::ButtonInvalid &&
- (deviceMap.calibrateButton != QGamepadManager::ButtonInvalid ||
- deviceMap.calibrateAxis != QGamepadManager::AxisInvalid)) {
-
- const auto buttonsMapIt = deviceMap.buttonsMap.find(keyCode);
- if (buttonsMapIt != deviceMap.buttonsMap.end() &&
- deviceMap.cancelConfigurationButton == buttonsMapIt.value()) {
- deviceMap.calibrateButton = QGamepadManager::ButtonInvalid;
- deviceMap.calibrateAxis = QGamepadManager::AxisInvalid;
- FunctionEvent::runOnQtThread(this, [this, deviceId]{
- emit configurationCanceled(deviceId);
- });
- return true;
- }
- }
-
- if (deviceMap.calibrateButton != QGamepadManager::ButtonInvalid) {
- deviceMap.buttonsMap[keyCode] = deviceMap.calibrateButton;
- auto but = deviceMap.calibrateButton;
- deviceMap.calibrateButton = QGamepadManager::ButtonInvalid;
- saveData(deviceMap);
- FunctionEvent::runOnQtThread(this, [this, deviceId, but]{
- emit buttonConfigured(deviceId, but);
- });
- }
-
- const auto buttonsMapIt = deviceMap.buttonsMap.find(keyCode);
- if (buttonsMapIt == deviceMap.buttonsMap.end())
- return false;
-
- const auto button = buttonsMapIt.value();
- if (action == g_defaultMapping()->ACTION_DOWN) {
- FunctionEvent::runOnQtThread(this, [this, deviceId, button]{
- emit gamepadButtonPressed(deviceId, button, 1.0);
- });
- } else {
- FunctionEvent::runOnQtThread(this, [this, deviceId, button]{
- emit gamepadButtonReleased(deviceId, button);
- });
- }
- return true;
-}
-
-bool QAndroidGamepadBackend::handleGenericMotionEvent(jobject event)
-{
- // GenericMotionEvent was introduced in API-12
- Q_ASSERT(QtAndroidPrivate::androidSdkVersion() >= 12);
-
- QJNIObjectPrivate ev(event);
- QMutexLocker lock(&m_mutex);
- const int deviceId = ev.callMethod<jint>("getDeviceId", "()I");
- const auto deviceIt = m_devices.find(deviceId);
- if (deviceIt == m_devices.end())
- return false;
-
- auto &deviceMap = deviceIt.value();
- if (deviceMap.calibrateAxis != QGamepadManager::AxisInvalid ||
- deviceMap.calibrateButton != QGamepadManager::ButtonInvalid) {
- double lastValue = 0;
- int lastAxis = -1;
- for (int axis : g_defaultMapping()->allAndroidAxes) {
- double value = ev.callMethod<jfloat>("getAxisValue", "(I)F", axis);
- if (fabs(value) > fabs(lastValue)) {
- lastValue = value;
- lastAxis = axis;
- }
- }
-
- if (!lastValue || lastAxis == -1)
- return false;
-
- if (deviceMap.calibrateAxis != QGamepadManager::AxisInvalid) {
- deviceMap.axisMap[lastAxis].gamepadAxis = deviceMap.calibrateAxis;
- auto axis = deviceMap.calibrateAxis;
- deviceMap.calibrateAxis = QGamepadManager::AxisInvalid;
- saveData(deviceMap);
- FunctionEvent::runOnQtThread(this, [this, deviceId, axis]{
- emit axisConfigured(deviceId, axis);
- });
- } else if (deviceMap.calibrateButton != QGamepadManager::ButtonInvalid &&
- deviceMap.calibrateButton != QGamepadManager::ButtonUp &&
- deviceMap.calibrateButton != QGamepadManager::ButtonDown &&
- deviceMap.calibrateButton != QGamepadManager::ButtonLeft &&
- deviceMap.calibrateButton != QGamepadManager::ButtonRight) {
- auto &axis = deviceMap.axisMap[lastAxis];
- axis.gamepadAxis = QGamepadManager::AxisInvalid;
- setAxisInfo(ev, lastAxis, axis);
- bool save = false;
- if (lastValue == axis.minValue) {
- axis.gamepadMinButton = deviceMap.calibrateButton;
- if (axis.gamepadMaxButton == QGamepadManager::ButtonInvalid)
- axis.gamepadMaxButton = deviceMap.calibrateButton;
- save = true;
- } else if (lastValue == axis.maxValue) {
- axis.gamepadMaxButton = deviceMap.calibrateButton;
- if (axis.gamepadMinButton == QGamepadManager::ButtonInvalid)
- axis.gamepadMinButton = deviceMap.calibrateButton;
- save = true;
- }
-
- if (save) {
- auto but = deviceMap.calibrateButton;
- deviceMap.calibrateButton = QGamepadManager::ButtonInvalid;
- saveData(deviceMap);
- FunctionEvent::runOnQtThread(this, [this, deviceId, but]{
- emit buttonConfigured(deviceId, but);
- });
- }
- }
- }
-
- typedef QPair<QGamepadManager::GamepadAxis, double> GamepadAxisValue;
- QList<GamepadAxisValue> axisValues;
- typedef QPair<QGamepadManager::GamepadButton, double> GamepadButtonValue;
- QList<GamepadButtonValue> buttonValues;
- auto setValue = [&axisValues, &buttonValues](Mapping::AndroidAxisInfo &axisInfo, double value) {
- if (axisInfo.setValue(value)) {
- if (axisInfo.gamepadAxis != QGamepadManager::AxisInvalid) {
- axisValues.push_back(GamepadAxisValue(axisInfo.gamepadAxis, axisInfo.lastValue));
- } else {
- if (axisInfo.lastValue < 0) {
- buttonValues.push_back(GamepadButtonValue(axisInfo.gamepadMinButton, axisInfo.lastValue));
- axisInfo.gamepadLastButton = axisInfo.gamepadMinButton;
- } else if (axisInfo.lastValue > 0) {
- buttonValues.push_back(GamepadButtonValue(axisInfo.gamepadMaxButton, axisInfo.lastValue));
- axisInfo.gamepadLastButton = axisInfo.gamepadMaxButton;
- } else {
- buttonValues.push_back(GamepadButtonValue(axisInfo.gamepadLastButton, 0.0));
- axisInfo.gamepadLastButton = QGamepadManager::ButtonInvalid;
- }
- }
- }
- };
- for (auto it = deviceMap.axisMap.begin(); it != deviceMap.axisMap.end(); ++it) {
- auto &axisInfo = it.value();
- if (axisInfo.flatArea == -1)
- setAxisInfo(ev, it.key(), axisInfo);
- const int historicalValues = ev.callMethod<jint>("getHistorySize", "()I");
- for (int i = 0; i < historicalValues; ++i) {
- double value = ev.callMethod<jfloat>("getHistoricalAxisValue", "(II)F", it.key(), i);
- setValue(axisInfo, value);
- }
- double value = ev.callMethod<jfloat>("getAxisValue", "(I)F", it.key());
- setValue(axisInfo, value);
- }
-
- if (!axisValues.isEmpty()) {
- FunctionEvent::runOnQtThread(this, [this, deviceId, axisValues]{
- for (const auto &axisValue : axisValues)
- emit gamepadAxisMoved(deviceId, axisValue.first, axisValue.second);
- });
- }
-
- if (!buttonValues.isEmpty()) {
- FunctionEvent::runOnQtThread(this, [this, deviceId, buttonValues]{
- for (const auto &buttonValue : buttonValues)
- if (buttonValue.second)
- emit gamepadButtonPressed(deviceId, buttonValue.first, fabs(buttonValue.second));
- else
- emit gamepadButtonReleased(deviceId, buttonValue.first);
- });
- }
-
- return false;
-}
-
-bool QAndroidGamepadBackend::start()
-{
- {
- QMutexLocker lock(&m_mutex);
- if (QtAndroidPrivate::androidSdkVersion() >= 16) {
- if (!m_qtGamepad.isValid())
- m_qtGamepad = QJNIObjectPrivate(qtGamePadClassName, "(Landroid/app/Activity;)V", QtAndroidPrivate::activity());
- m_qtGamepad.callMethod<void>("register", "(J)V", jlong(this));
- }
- }
-
- QJNIObjectPrivate ids = QJNIObjectPrivate::callStaticObjectMethod(inputDeviceClass, "getDeviceIds", "()[I");
- jintArray jarr = jintArray(ids.object());
- QJNIEnvironmentPrivate env;
- size_t sz = env->GetArrayLength(jarr);
- jint *buff = env->GetIntArrayElements(jarr, nullptr);
- for (size_t i = 0; i < sz; ++i)
- addDevice(buff[i]);
- env->ReleaseIntArrayElements(jarr, buff, 0);
- return true;
-}
-
-void QAndroidGamepadBackend::stop()
-{
- QMutexLocker lock(&m_mutex);
- if (QtAndroidPrivate::androidSdkVersion() >= 16 && m_qtGamepad.isValid())
- m_qtGamepad.callMethod<void>("unregister", "()V");
-}
-
-void QAndroidGamepadBackend::saveData(const QAndroidGamepadBackend::Mapping &deviceInfo)
-{
- if (!deviceInfo.productId)
- return ;
-
- QVariantMap settings, data;
- for (auto it = deviceInfo.axisMap.begin(); it != deviceInfo.axisMap.end(); ++it)
- data[QString::number(it.key())] = it.value().dataToSave();
- settings[AXES_KEY] = data;
-
- data.clear();
- for (auto it = deviceInfo.buttonsMap.begin(); it != deviceInfo.buttonsMap.end(); ++it)
- data[QString::number(it.key())] = it.value();
- settings[BUTTONS_KEY] = data;
-
- saveSettings(deviceInfo.productId, settings);
-}
-
-JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void */*reserved*/)
-{
- static bool initialized = false;
- if (initialized)
- return JNI_VERSION_1_6;
- initialized = true;
-
- JNIEnv* env;
- // get the JNIEnv pointer.
- if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK)
- return JNI_ERR;
-
- // search for Java class which declares the native methods
- jclass javaClass = env->FindClass("org/qtproject/qt/android/gamepad/QtGamepad");
- if (!javaClass)
- return JNI_ERR;
-
- // register our native methods
- if (env->RegisterNatives(javaClass, methods,
- sizeof(methods) / sizeof(methods[0])) < 0) {
- return JNI_ERR;
- }
- return JNI_VERSION_1_6;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gamepads/android/src/qandroidgamepadbackend_p.h b/src/plugins/gamepads/android/src/qandroidgamepadbackend_p.h
deleted file mode 100644
index b54f569..0000000
--- a/src/plugins/gamepads/android/src/qandroidgamepadbackend_p.h
+++ /dev/null
@@ -1,135 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 BogDan Vatra <bogdan@kde.org>
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDGAMEPADBACKEND_P_H
-#define QANDROIDGAMEPADBACKEND_P_H
-
-#include <QtCore/QHash>
-#include <QtCore/QMutex>
-#include <QtCore/QSet>
-
-#include <QtCore/private/qjni_p.h>
-#include <QtCore/private/qjnihelpers_p.h>
-
-#include <QtGamepad/QGamepadManager>
-#include <QtGamepad/private/qgamepadbackend_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidGamepadBackend : public QGamepadBackend, public QtAndroidPrivate::GenericMotionEventListener, public QtAndroidPrivate::KeyEventListener
-{
- Q_OBJECT
-public:
- explicit QAndroidGamepadBackend(QObject *parent = nullptr);
- ~QAndroidGamepadBackend();
-
- void addDevice(int deviceId);
- void updateDevice(int deviceId);
- void removeDevice(int deviceId);
-
- // QObject interface
- bool event(QEvent *) override;
-
- // QGamepadBackend interface
- bool isConfigurationNeeded(int deviceId) override;
- bool configureButton(int deviceId, QGamepadManager::GamepadButton button) override;
- bool configureAxis(int deviceId, QGamepadManager::GamepadAxis axis) override;
- bool setCancelConfigureButton(int deviceId, QGamepadManager::GamepadButton button) override;
- void resetConfiguration(int deviceId) override;
-
-
- // KeyEventListener interface
- bool handleKeyEvent(jobject event) override;
-
- // GenericMotionEventListener interface
- bool handleGenericMotionEvent(jobject event) override;
-
-protected:
- bool start() override;
- void stop() override;
-
-public:
- struct Mapping {
- struct AndroidAxisInfo : public AxisInfo<double> {
- AndroidAxisInfo() : AxisInfo(-1.0, 1.0) { }
- AndroidAxisInfo(double minValue, double maxValue) : AxisInfo(minValue, maxValue) { }
-
- inline bool setValue(double value)
- {
- if (minValue != -1.0 && maxValue != 1.0)
- value = AxisInfo::normalized(value);
-
- if (qAbs(value) <= flatArea)
- value = 0;
-
- if (qAbs(qAbs(value) - qAbs(lastValue)) <= fuzz)
- return false;
-
- lastValue = value;
- return true;
- }
- void restoreSavedData(const QVariantMap &value);
- QVariantMap dataToSave() const;
-
- double flatArea = -1;
- double fuzz = 0;
- double lastValue = 0;
- QGamepadManager::GamepadButton gamepadMinButton = QGamepadManager::ButtonInvalid;
- QGamepadManager::GamepadButton gamepadMaxButton = QGamepadManager::ButtonInvalid;
- QGamepadManager::GamepadButton gamepadLastButton = QGamepadManager::ButtonInvalid;
- };
- QHash<int, AndroidAxisInfo> axisMap;
- QHash<int, QGamepadManager::GamepadButton> buttonsMap;
-
- QGamepadManager::GamepadButton calibrateButton = QGamepadManager::ButtonInvalid;
- QGamepadManager::GamepadAxis calibrateAxis = QGamepadManager::AxisInvalid;
- QGamepadManager::GamepadButton cancelConfigurationButton = QGamepadManager::ButtonInvalid;
- int productId = 0;
- bool needsConfigure = false;
- };
-
-private:
- void saveData(const Mapping &deviceInfo);
-
-private:
- QMutex m_mutex;
- QJNIObjectPrivate m_qtGamepad;
- QHash<int, Mapping> m_devices;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDGAMEPADBACKEND_P_H
diff --git a/src/plugins/gamepads/android/src/src.pro b/src/plugins/gamepads/android/src/src.pro
deleted file mode 100644
index 31f8a28..0000000
--- a/src/plugins/gamepads/android/src/src.pro
+++ /dev/null
@@ -1,17 +0,0 @@
-TARGET = androidgamepad
-QT += core-private gamepad gamepad-private
-
-PLUGIN_TYPE = gamepads
-PLUGIN_CLASS_NAME = QAndroidGamepadBackendPlugin
-
-load(qt_plugin)
-
-HEADERS += \
- qandroidgamepadbackend_p.h
-
-SOURCES += \
- main.cpp \
- qandroidgamepadbackend.cpp
-
-DISTFILES += \
- android.json
diff --git a/src/plugins/gamepads/darwin/darwin.json b/src/plugins/gamepads/darwin/darwin.json
deleted file mode 100644
index f72350b..0000000
--- a/src/plugins/gamepads/darwin/darwin.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "Keys": [ "darwin" ]
-}
diff --git a/src/plugins/gamepads/darwin/darwin.pro b/src/plugins/gamepads/darwin/darwin.pro
deleted file mode 100644
index 9a35c75..0000000
--- a/src/plugins/gamepads/darwin/darwin.pro
+++ /dev/null
@@ -1,19 +0,0 @@
-TARGET = darwingamepad
-QT += gamepad gamepad-private
-
-PLUGIN_TYPE = gamepads
-PLUGIN_EXTENDS = gamepad
-PLUGIN_CLASS_NAME = QDarwinGamepadBackendPlugin
-load(qt_plugin)
-
-LIBS += -framework GameController -framework Foundation
-
-HEADERS += qdarwingamepadbackend_p.h
-OBJECTIVE_SOURCES += \
- qdarwingamepadbackend.mm
-
-SOURCES += \
- main.cpp
-
-OTHER_FILES += \
- darwin.json
diff --git a/src/plugins/gamepads/darwin/main.cpp b/src/plugins/gamepads/darwin/main.cpp
deleted file mode 100644
index 87afec1..0000000
--- a/src/plugins/gamepads/darwin/main.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtGamepad/private/qgamepadbackendfactory_p.h>
-#include <QtGamepad/private/qgamepadbackendplugin_p.h>
-
-#include "qdarwingamepadbackend_p.h"
-
-QT_BEGIN_NAMESPACE
-
-class QDarwinGamepadBackendPlugin : public QGamepadBackendPlugin
-{
- Q_OBJECT
- Q_PLUGIN_METADATA(IID QtGamepadBackendFactoryInterface_iid FILE "darwin.json")
-public:
- QGamepadBackend *create(const QString &key, const QStringList &paramList) override;
-};
-
-QGamepadBackend *QDarwinGamepadBackendPlugin::create(const QString &key, const QStringList &paramList) {
- Q_UNUSED(key);
- Q_UNUSED(paramList);
-
- return new QDarwinGamepadBackend();
-}
-
-QT_END_NAMESPACE
-
-#include "main.moc"
diff --git a/src/plugins/gamepads/darwin/qdarwingamepadbackend.mm b/src/plugins/gamepads/darwin/qdarwingamepadbackend.mm
deleted file mode 100644
index 6094a99..0000000
--- a/src/plugins/gamepads/darwin/qdarwingamepadbackend.mm
+++ /dev/null
@@ -1,570 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "qdarwingamepadbackend_p.h"
-
-#include <QtCore/QDebug>
-
-#import <GameController/GameController.h>
-
-@interface QT_MANGLE_NAMESPACE(DarwinGamepadManager) : NSObject
-
-@property (nonatomic, strong) id connectObserver;
-@property (nonatomic, strong) id disconnectObserver;
-
-@end
-
-@implementation QT_MANGLE_NAMESPACE(DarwinGamepadManager)
-{
- QDarwinGamepadBackend *backend;
- NSMutableArray *connectedControllers;
-}
-
--(instancetype)initWithBackend:(QDarwinGamepadBackend *)gamepadBackend
-{
- if ((self = [self init])) {
- backend = gamepadBackend;
- connectedControllers = [[NSMutableArray alloc] init];
- //Setup observers for monitoring controller connections/disconnections
- self.connectObserver = [[NSNotificationCenter defaultCenter] addObserverForName:GCControllerDidConnectNotification
- object:nil
- queue:[NSOperationQueue mainQueue]
- usingBlock:^(NSNotification *note) {
- GCController *controller = (GCController*)note.object;
- [self addMonitoredController:controller];
-
- }];
- self.disconnectObserver = [[NSNotificationCenter defaultCenter] addObserverForName:GCControllerDidDisconnectNotification
- object:nil
- queue:[NSOperationQueue mainQueue]
- usingBlock:^(NSNotification *note) {
- GCController *controller = (GCController*)note.object;
- [self removeMonitoredController:controller];
- }];
- //Set initial controller values
- for (int i = 0; i < 4; ++i)
- [connectedControllers addObject:[NSNull null]];
-
- //Add monitoring for any alrready connected controllers
- for (NSUInteger i = 0; i < [[GCController controllers] count]; ++i) {
- [self addMonitoredController:[GCController controllers][i]];
- }
- }
- return self;
-}
-
--(void)dealloc
-{
- [[NSNotificationCenter defaultCenter] removeObserver:self.connectObserver];
- [[NSNotificationCenter defaultCenter] removeObserver:self.disconnectObserver];
- [connectedControllers release];
- [super dealloc];
-}
-
--(void)addMonitoredController:(GCController *)controller
-{
- int index = -1;
- for (int i = 0; i < 4; ++i) {
- if (connectedControllers[i] == [NSNull null]) {
- [connectedControllers replaceObjectAtIndex: i withObject: controller];
- index = i;
- break;
- }
- }
-
- controller.playerIndex = GCControllerPlayerIndex(index);
-
- QMetaObject::invokeMethod(backend, "darwinGamepadAdded", Qt::AutoConnection, Q_ARG(int, index));
-
- //Pause button handler
- [controller setControllerPausedHandler:^(GCController *controller) {
- Q_UNUSED(controller);
- QMetaObject::invokeMethod(backend, "handlePauseButton", Qt::AutoConnection, Q_ARG(int, index));
- }];
-
- if (controller.extendedGamepad) {
- //leftShoulder
- [controller.extendedGamepad.leftShoulder setValueChangedHandler:^(GCControllerButtonInput *button, float value, BOOL pressed) {
- Q_UNUSED(button);
- if (pressed) {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonL1),
- Q_ARG(double, value));
- } else {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonL1));
- }
- }];
- //rightShoulder
- [controller.extendedGamepad.rightShoulder setValueChangedHandler:^(GCControllerButtonInput *button, float value, BOOL pressed) {
- Q_UNUSED(button);
- if (pressed) {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonR1),
- Q_ARG(double, value));
- } else {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonR1));
- }
- }];
- //dpad
- [controller.extendedGamepad.dpad setValueChangedHandler:^(GCControllerDirectionPad *dpad, float xValue, float yValue) {
- Q_UNUSED(dpad);
- if (xValue > 0) {
- //right
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonRight),
- Q_ARG(double, 1));
- } else if (xValue < 0) {
- //left
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonLeft),
- Q_ARG(double, 1));
- } else {
- //released
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonRight));
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonLeft));
- }
- if (yValue > 0) {
- //up
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonUp),
- Q_ARG(double, 1));
- } else if (yValue < 0) {
- //down
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonDown),
- Q_ARG(double, 1));
- } else {
- //released
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonUp));
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonDown));
- }
- }];
- //buttonA
- [controller.extendedGamepad.buttonA setValueChangedHandler:^(GCControllerButtonInput *button, float value, BOOL pressed) {
- Q_UNUSED(button);
- if (pressed) {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonA),
- Q_ARG(double, value));
- } else {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonA));
- }
- }];
- //buttonB
- [controller.extendedGamepad.buttonB setValueChangedHandler:^(GCControllerButtonInput *button, float value, BOOL pressed) {
- Q_UNUSED(button);
- if (pressed) {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonB),
- Q_ARG(double, value));
- } else {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonB));
- }
- }];
- //buttonX
- [controller.extendedGamepad.buttonX setValueChangedHandler:^(GCControllerButtonInput *button, float value, BOOL pressed) {
- Q_UNUSED(button);
- if (pressed) {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonX),
- Q_ARG(double, value));
- } else {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonX));
- }
- }];
- //buttonY
- [controller.extendedGamepad.buttonY setValueChangedHandler:^(GCControllerButtonInput *button, float value, BOOL pressed) {
- //Invoke slot
- Q_UNUSED(button);
- if (pressed) {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonY),
- Q_ARG(double, value));
- } else {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonY));
- }
- }];
-
- //leftThumbstick
- [controller.extendedGamepad.leftThumbstick setValueChangedHandler:^(GCControllerDirectionPad *dpad, float xValue, float yValue) {
- Q_UNUSED(dpad);
- QMetaObject::invokeMethod(backend, "darwinGamepadAxisMoved", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadAxis, QGamepadManager::AxisLeftX),
- Q_ARG(double, xValue));
- QMetaObject::invokeMethod(backend, "darwinGamepadAxisMoved", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadAxis, QGamepadManager::AxisLeftY),
- Q_ARG(double, -yValue));
- }];
- //rightTumbstick
- [controller.extendedGamepad.rightThumbstick setValueChangedHandler:^(GCControllerDirectionPad *dpad, float xValue, float yValue) {
- Q_UNUSED(dpad);
- QMetaObject::invokeMethod(backend, "darwinGamepadAxisMoved", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadAxis, QGamepadManager::AxisRightX),
- Q_ARG(double, xValue));
- QMetaObject::invokeMethod(backend, "darwinGamepadAxisMoved", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadAxis, QGamepadManager::AxisRightY),
- Q_ARG(double, -yValue));
- }];
- //leftTrigger
- [controller.extendedGamepad.leftTrigger setValueChangedHandler:^(GCControllerButtonInput *button, float value, BOOL pressed) {
- Q_UNUSED(button);
- if (pressed) {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonL2),
- Q_ARG(double, value));
- } else {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonL2));
- }
- }];
- //rightTrigger
- [controller.extendedGamepad.rightTrigger setValueChangedHandler:^(GCControllerButtonInput *button, float value, BOOL pressed) {
- Q_UNUSED(button);
- if (pressed) {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonR2),
- Q_ARG(double, value));
- } else {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonR2));
- }
-
- }];
- } else if (controller.gamepad) {
- //leftShoulder
- [controller.gamepad.leftShoulder setValueChangedHandler:^(GCControllerButtonInput *button, float value, BOOL pressed) {
- Q_UNUSED(button);
- if (pressed) {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonL1),
- Q_ARG(double, value));
- } else {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonL1));
- }
- }];
- //rightShoulder
- [controller.gamepad.rightShoulder setValueChangedHandler:^(GCControllerButtonInput *button, float value, BOOL pressed) {
- Q_UNUSED(button);
- if (pressed) {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonR1),
- Q_ARG(double, value));
- } else {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonR1));
- }
- }];
- //dpad
- [controller.gamepad.dpad setValueChangedHandler:^(GCControllerDirectionPad *dpad, float xValue, float yValue) {
- Q_UNUSED(dpad);
- if (xValue > 0) {
- //right
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonRight),
- Q_ARG(double, 1));
- } else if (xValue < 0) {
- //left
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonLeft),
- Q_ARG(double, 1));
- } else {
- //released
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonRight));
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonLeft));
- }
- if (yValue > 0) {
- //up
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonUp),
- Q_ARG(double, 1));
- } else if (yValue < 0) {
- //down
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonDown),
- Q_ARG(double, 1));
- } else {
- //released
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonUp));
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonDown));
- }
- }];
- //buttonA
- [controller.gamepad.buttonA setValueChangedHandler:^(GCControllerButtonInput *button, float value, BOOL pressed) {
- Q_UNUSED(button);
- if (pressed) {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonA),
- Q_ARG(double, value));
- } else {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonA));
- }
- }];
- //buttonB
- [controller.gamepad.buttonB setValueChangedHandler:^(GCControllerButtonInput *button, float value, BOOL pressed) {
- Q_UNUSED(button);
- if (pressed) {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonB),
- Q_ARG(double, value));
- } else {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonB));
- }
- }];
- //buttonX
- [controller.gamepad.buttonX setValueChangedHandler:^(GCControllerButtonInput *button, float value, BOOL pressed) {
- Q_UNUSED(button);
- if (pressed) {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonX),
- Q_ARG(double, value));
- } else {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonX));
- }
- }];
- //buttonY
- [controller.gamepad.buttonY setValueChangedHandler:^(GCControllerButtonInput *button, float value, BOOL pressed) {
- Q_UNUSED(button);
- if (pressed) {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonY),
- Q_ARG(double, value));
- } else {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonY));
- }
- }];
- }
-#ifdef Q_OS_TVOS
- else if (controller.microGamepad) {
- //leftThumbstick
- [controller.microGamepad.dpad setValueChangedHandler:^(GCControllerDirectionPad *dpad, float xValue, float yValue) {
- Q_UNUSED(dpad);
- QMetaObject::invokeMethod(backend, "darwinGamepadAxisMoved", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadAxis, QGamepadManager::AxisLeftX),
- Q_ARG(double, xValue));
- QMetaObject::invokeMethod(backend, "darwinGamepadAxisMoved", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadAxis, QGamepadManager::AxisLeftY),
- Q_ARG(double, -yValue));
- }];
- //buttonA
- [controller.microGamepad.buttonA setValueChangedHandler:^(GCControllerButtonInput *button, float value, BOOL pressed) {
- Q_UNUSED(button);
- if (pressed) {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonA),
- Q_ARG(double, value));
- } else {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonA));
- }
- }];
- //buttonX
- [controller.microGamepad.buttonX setValueChangedHandler:^(GCControllerButtonInput *button, float value, BOOL pressed) {
- Q_UNUSED(button);
- if (pressed) {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonPressed", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonX),
- Q_ARG(double, value));
- } else {
- QMetaObject::invokeMethod(backend, "darwinGamepadButtonReleased", Qt::AutoConnection,
- Q_ARG(int, index),
- Q_ARG(QGamepadManager::GamepadButton, QGamepadManager::ButtonX));
- }
- }];
- }
-#endif
-}
-
--(void)removeMonitoredController:(GCController *)controller
-{
- int index = -1;
- for (int i = 0; i < 4; ++i) {
- if (connectedControllers[i] == controller) {
- [connectedControllers replaceObjectAtIndex: i withObject: [NSNull null]];
- index = i;
- break;
- }
- }
-
- QMetaObject::invokeMethod(backend, "darwinGamepadRemoved", Qt::AutoConnection, Q_ARG(int, index));
-}
-
-@end
-
-QT_BEGIN_NAMESPACE
-
-QDarwinGamepadBackend::QDarwinGamepadBackend(QObject *parent)
- : QGamepadBackend(parent)
- , m_darwinGamepadManager(nullptr)
- , m_isMonitoringActive(false)
-{
- m_darwinGamepadManager = [[QT_MANGLE_NAMESPACE(DarwinGamepadManager) alloc] initWithBackend:this];
-}
-
-QDarwinGamepadBackend::~QDarwinGamepadBackend()
-{
- [m_darwinGamepadManager release];
-}
-
-bool QDarwinGamepadBackend::start()
-{
- m_isMonitoringActive = true;
- return true;
-}
-
-void QDarwinGamepadBackend::stop()
-{
- m_isMonitoringActive = false;
-}
-
-void QDarwinGamepadBackend::darwinGamepadAdded(int index)
-{
- if (m_isMonitoringActive) {
- emit gamepadAdded(index);
- m_pauseButtonMap.insert(index, false);
- }
-}
-
-void QDarwinGamepadBackend::darwinGamepadRemoved(int index)
-{
- if (m_isMonitoringActive) {
- emit gamepadRemoved(index);
- m_pauseButtonMap.remove(index);
- }
-}
-
-void QDarwinGamepadBackend::darwinGamepadAxisMoved(int index, QGamepadManager::GamepadAxis axis, double value)
-{
- if (m_isMonitoringActive)
- emit gamepadAxisMoved(index, axis, value);
-}
-
-void QDarwinGamepadBackend::darwinGamepadButtonPressed(int index, QGamepadManager::GamepadButton button, double value)
-{
- if (m_isMonitoringActive)
- emit gamepadButtonPressed(index, button, value);
-}
-
-void QDarwinGamepadBackend::darwinGamepadButtonReleased(int index, QGamepadManager::GamepadButton button)
-{
- if (m_isMonitoringActive)
- emit gamepadButtonReleased(index, button);
-}
-
-void QDarwinGamepadBackend::handlePauseButton(int index)
-{
- //If already pressed
- if (m_pauseButtonMap.value(index)) {
- emit gamepadButtonReleased(index, QGamepadManager::ButtonStart);
- m_pauseButtonMap[index] = false;
- } else {
- //If not currently pressed
- emit gamepadButtonPressed(index, QGamepadManager::ButtonStart, 1.0);
- m_pauseButtonMap[index] = true;
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gamepads/darwin/qdarwingamepadbackend_p.h b/src/plugins/gamepads/darwin/qdarwingamepadbackend_p.h
deleted file mode 100644
index 326ccaf..0000000
--- a/src/plugins/gamepads/darwin/qdarwingamepadbackend_p.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDARWINGAMEPADBACKEND_P_H
-#define QDARWINGAMEPADBACKEND_P_H
-
-#include <QtCore/QTimer>
-#include <QtCore/QMap>
-
-#include <QtGamepad/QGamepadManager>
-#include <QtGamepad/private/qgamepadbackend_p.h>
-
-Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(DarwinGamepadManager));
-
-QT_BEGIN_NAMESPACE
-
-class QDarwinGamepadBackend : public QGamepadBackend
-{
- Q_OBJECT
-public:
- explicit QDarwinGamepadBackend(QObject *parent = nullptr);
- ~QDarwinGamepadBackend();
-
-protected:
- bool start() override;
- void stop() override;
-
-public Q_SLOTS:
- void darwinGamepadAdded(int index);
- void darwinGamepadRemoved(int index);
- void darwinGamepadAxisMoved(int index, QGamepadManager::GamepadAxis axis, double value);
- void darwinGamepadButtonPressed(int index, QGamepadManager::GamepadButton button, double value);
- void darwinGamepadButtonReleased(int index, QGamepadManager::GamepadButton button);
- void handlePauseButton(int index);
-
-private:
- QT_MANGLE_NAMESPACE(DarwinGamepadManager) *m_darwinGamepadManager;
- bool m_isMonitoringActive;
- QMap<int, bool> m_pauseButtonMap;
-};
-
-QT_END_NAMESPACE
-
-#endif // QDARWINGAMEPADBACKEND_P_H
diff --git a/src/plugins/gamepads/evdev/evdev.json b/src/plugins/gamepads/evdev/evdev.json
deleted file mode 100644
index 90c6d7d..0000000
--- a/src/plugins/gamepads/evdev/evdev.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "Keys": [ "evdev" ]
-}
diff --git a/src/plugins/gamepads/evdev/evdev.pro b/src/plugins/gamepads/evdev/evdev.pro
deleted file mode 100644
index d819de4..0000000
--- a/src/plugins/gamepads/evdev/evdev.pro
+++ /dev/null
@@ -1,14 +0,0 @@
-TARGET = evdevgamepad
-QT += core-private devicediscovery_support-private gamepad gamepad-private
-
-PLUGIN_TYPE = gamepads
-PLUGIN_CLASS_NAME = QEvdevGamepadBackendPlugin
-load(qt_plugin)
-
-HEADERS += qevdevgamepadbackend_p.h
-SOURCES += \
- qevdevgamepadbackend.cpp \
- main.cpp
-
-OTHER_FILES += \
- evdev.json
diff --git a/src/plugins/gamepads/evdev/main.cpp b/src/plugins/gamepads/evdev/main.cpp
deleted file mode 100644
index 1832ea5..0000000
--- a/src/plugins/gamepads/evdev/main.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtGamepad/private/qgamepadbackendfactory_p.h>
-#include <QtGamepad/private/qgamepadbackendplugin_p.h>
-
-#include "qevdevgamepadbackend_p.h"
-
-QT_BEGIN_NAMESPACE
-
-class QEvdevGamepadBackendPlugin : public QGamepadBackendPlugin
-{
- Q_OBJECT
- Q_PLUGIN_METADATA(IID QtGamepadBackendFactoryInterface_iid FILE "evdev.json")
-public:
- QGamepadBackend *create(const QString &key, const QStringList &paramList) override;
-};
-
-QGamepadBackend *QEvdevGamepadBackendPlugin::create(const QString &key, const QStringList &paramList)
-{
- Q_UNUSED(key);
- Q_UNUSED(paramList);
-
- return new QEvdevGamepadBackend;
-}
-
-QT_END_NAMESPACE
-
-#include "main.moc"
diff --git a/src/plugins/gamepads/evdev/qevdevgamepadbackend.cpp b/src/plugins/gamepads/evdev/qevdevgamepadbackend.cpp
deleted file mode 100644
index e57b2c8..0000000
--- a/src/plugins/gamepads/evdev/qevdevgamepadbackend.cpp
+++ /dev/null
@@ -1,553 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qglobal.h>
-QT_WARNING_DISABLE_GCC("-Wmaybe-uninitialized") // GCC warnings don't make sense, so disable
-
-#include "qevdevgamepadbackend_p.h"
-#include <QtCore/QSocketNotifier>
-#include <QtCore/QLoggingCategory>
-#include <QtCore/QVariant>
-#include <QtDeviceDiscoverySupport/private/qdevicediscovery_p.h>
-#include <QtCore/private/qcore_unix_p.h>
-#include <linux/input.h>
-
-#include <cmath>
-
-QT_BEGIN_NAMESPACE
-
-Q_LOGGING_CATEGORY(lcEGB, "qt.gamepad")
-
-#ifndef BTN_TRIGGER_HAPPY1
-# define BTN_TRIGGER_HAPPY1 0x2c0
-#endif
-#ifndef BTN_TRIGGER_HAPPY2
-# define BTN_TRIGGER_HAPPY2 0x2c1
-#endif
-#ifndef BTN_TRIGGER_HAPPY3
-# define BTN_TRIGGER_HAPPY3 0x2c2
-#endif
-#ifndef BTN_TRIGGER_HAPPY4
-# define BTN_TRIGGER_HAPPY4 0x2c3
-#endif
-
-QEvdevGamepadDevice::EvdevAxisInfo::EvdevAxisInfo()
- : QGamepadBackend::AxisInfo<int>(0, 1, QGamepadManager::AxisInvalid)
-{
-}
-
-QEvdevGamepadDevice::EvdevAxisInfo::EvdevAxisInfo(int fd, quint16 abs, int min, int max, QGamepadManager::GamepadAxis gamepadAxis)
- : QGamepadBackend::AxisInfo<int>(min, max, gamepadAxis)
- , flat(0)
- , gamepadMinButton(QGamepadManager::ButtonInvalid)
- , gamepadMaxButton(QGamepadManager::ButtonInvalid)
- , gamepadLastButton(QGamepadManager::ButtonInvalid)
-{
- setAbsInfo(fd, abs);
-}
-
-double QEvdevGamepadDevice::EvdevAxisInfo::normalized(int value) const
-{
- double val = AxisInfo::normalized(value);
- if (qAbs(val) <= flat)
- val = 0;
- return val;
-}
-
-void QEvdevGamepadDevice::EvdevAxisInfo::setAbsInfo(int fd, int abs)
-{
- input_absinfo absInfo;
- memset(&absInfo, 0, sizeof(input_absinfo));
- if (ioctl(fd, EVIOCGABS(abs), &absInfo) >= 0) {
- minValue = absInfo.minimum;
- maxValue = absInfo.maximum;
- if (maxValue - minValue)
- flat = std::abs(absInfo.flat / double(maxValue - minValue));
- }
-}
-
-void QEvdevGamepadDevice::EvdevAxisInfo::restoreSavedData(int fd, int abs, const QVariantMap &value)
-{
- gamepadAxis = QGamepadManager::GamepadAxis(value[QLatin1String("axis")].toInt());
- gamepadMinButton = QGamepadManager::GamepadButton(value[QLatin1String("minButton")].toInt());
- gamepadMaxButton = QGamepadManager::GamepadButton(value[QLatin1String("maxButton")].toInt());
- setAbsInfo(fd, abs);
-}
-
-QVariantMap QEvdevGamepadDevice::EvdevAxisInfo::dataToSave() const
-{
- QVariantMap data;
- data[QLatin1String("axis")] = gamepadAxis;
- data[QLatin1String("minButton")] = gamepadMinButton;
- data[QLatin1String("maxButton")] = gamepadMaxButton;
- return data;
-}
-
-QEvdevGamepadBackend::QEvdevGamepadBackend()
-{
-}
-
-bool QEvdevGamepadBackend::start()
-{
- qCDebug(lcEGB) << "start";
- QByteArray device = qgetenv("QT_GAMEPAD_DEVICE");
- if (device.isEmpty()) {
- qCDebug(lcEGB) << "Using device discovery";
- m_discovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Joystick, this);
- if (m_discovery) {
- const QStringList devices = m_discovery->scanConnectedDevices();
- for (const QString &devStr : devices) {
- device = devStr.toUtf8();
- m_devices.append(newDevice(device));
- }
- connect(m_discovery, SIGNAL(deviceDetected(QString)), this, SLOT(handleAddedDevice(QString)));
- connect(m_discovery, SIGNAL(deviceRemoved(QString)), this, SLOT(handleRemovedDevice(QString)));
- } else {
- qWarning("No device specified, set QT_GAMEPAD_DEVICE");
- return false;
- }
- } else {
- qCDebug(lcEGB) << "Using device" << device;
- m_devices.append(newDevice(device));
- }
-
- return true;
-}
-
-QEvdevGamepadDevice *QEvdevGamepadBackend::newDevice(const QByteArray &device)
-{
- qCDebug(lcEGB) << "Opening device" << device;
- return new QEvdevGamepadDevice(device, this);
-}
-
-QEvdevGamepadDevice *QEvdevGamepadBackend::device(int deviceId)
-{
- for (QEvdevGamepadDevice *device : qAsConst(m_devices))
- if (device->deviceId() == deviceId)
- return device;
- return nullptr;
-}
-
-void QEvdevGamepadBackend::resetConfiguration(int deviceId)
-{
- if (QEvdevGamepadDevice *dev = device(deviceId))
- return dev->resetConfiguration();
-}
-
-bool QEvdevGamepadBackend::isConfigurationNeeded(int deviceId)
-{
- if (QEvdevGamepadDevice *dev = device(deviceId))
- return dev->isConfigurationNeeded();
- return false;
-}
-
-bool QEvdevGamepadBackend::configureButton(int deviceId, QGamepadManager::GamepadButton button)
-{
- if (QEvdevGamepadDevice *dev = device(deviceId))
- return dev->configureButton(button);
- return false;
-}
-
-bool QEvdevGamepadBackend::configureAxis(int deviceId, QGamepadManager::GamepadAxis axis)
-{
- if (QEvdevGamepadDevice *dev = device(deviceId))
- return dev->configureAxis(axis);
- return false;
-}
-
-bool QEvdevGamepadBackend::setCancelConfigureButton(int deviceId, QGamepadManager::GamepadButton button)
-{
- if (QEvdevGamepadDevice *dev = device(deviceId))
- return dev->setCancelConfigureButton(button);
- return false;
-}
-
-void QEvdevGamepadBackend::stop()
-{
- qCDebug(lcEGB) << "stop";
- qDeleteAll(m_devices);
- m_devices.clear();
-}
-
-void QEvdevGamepadBackend::handleAddedDevice(const QString &device)
-{
- // This does not imply that an actual controller is connected.
- // When connecting the wireless receiver 4 devices will show up right away.
- // Therefore gamepadAdded() will be emitted only later, when something is read.
- qCDebug(lcEGB) << "Connected device" << device;
- m_devices.append(newDevice(device.toUtf8()));
-}
-
-void QEvdevGamepadBackend::handleRemovedDevice(const QString &device)
-{
- qCDebug(lcEGB) << "Disconnected device" << device;
- QByteArray dev = device.toUtf8();
- for (int i = 0; i < m_devices.count(); ++i) {
- if (m_devices[i]->deviceName() == dev) {
- delete m_devices[i];
- m_devices.removeAt(i);
- break;
- }
- }
-}
-
-QEvdevGamepadDevice::QEvdevGamepadDevice(const QByteArray &dev, QEvdevGamepadBackend *backend)
- : m_dev(dev),
- m_backend(backend),
- m_fd(-1),
- m_productId(0),
- m_needsConfigure(true),
- m_notifier(0),
- m_configureButton(QGamepadManager::ButtonInvalid),
- m_configureAxis(QGamepadManager::AxisInvalid)
-{
- openDevice(dev);
-}
-
-QEvdevGamepadDevice::~QEvdevGamepadDevice()
-{
- if (m_fd != -1)
- QT_CLOSE(m_fd);
-
- if (m_productId)
- emit m_backend->gamepadRemoved(m_productId);
-}
-
-void QEvdevGamepadDevice::resetConfiguration()
-{
- m_axisMap.insert(ABS_X, EvdevAxisInfo(m_fd, ABS_X, -32768, 32767, QGamepadManager::AxisLeftX));
- m_axisMap.insert(ABS_Y, EvdevAxisInfo(m_fd, ABS_Y, -32768, 32767, QGamepadManager::AxisLeftY));
- m_axisMap.insert(ABS_RX, EvdevAxisInfo(m_fd, ABS_RX, -32768, 32767, QGamepadManager::AxisRightX));
- m_axisMap.insert(ABS_RY, EvdevAxisInfo(m_fd, ABS_RY, -32768, 32767, QGamepadManager::AxisRightY));
- m_axisMap.insert(ABS_Z, EvdevAxisInfo(m_fd, ABS_Z, 0, 255));
- m_axisMap[ABS_Z].gamepadMinButton = QGamepadManager::ButtonL2;
- m_axisMap[ABS_Z].gamepadMaxButton = QGamepadManager::ButtonL2;
-
- m_axisMap.insert(ABS_RZ, EvdevAxisInfo(m_fd, ABS_RZ, 0, 255));
- m_axisMap[ABS_RZ].gamepadMinButton = QGamepadManager::ButtonR2;
- m_axisMap[ABS_RZ].gamepadMaxButton = QGamepadManager::ButtonR2;
-
- m_axisMap.insert(ABS_HAT0X, EvdevAxisInfo(m_fd, ABS_HAT0X, -1, 1));
- m_axisMap[ABS_HAT0X].gamepadMinButton = QGamepadManager::ButtonLeft;
- m_axisMap[ABS_HAT0X].gamepadMaxButton = QGamepadManager::ButtonRight;
-
- m_axisMap.insert(ABS_HAT0Y, EvdevAxisInfo(m_fd, ABS_HAT0Y, -1, 1));
- m_axisMap[ABS_HAT0Y].gamepadMinButton = QGamepadManager::ButtonUp;
- m_axisMap[ABS_HAT0Y].gamepadMaxButton = QGamepadManager::ButtonDown;
-
- m_buttonsMap[BTN_START] = QGamepadManager::ButtonStart;
- m_buttonsMap[BTN_SELECT] = QGamepadManager::ButtonSelect;
- m_buttonsMap[BTN_MODE] = QGamepadManager::ButtonGuide;
- m_buttonsMap[BTN_X] = QGamepadManager::ButtonX;
- m_buttonsMap[BTN_Y] = QGamepadManager::ButtonY;
- m_buttonsMap[BTN_A] = QGamepadManager::ButtonA;
- m_buttonsMap[BTN_B] = QGamepadManager::ButtonB;
- m_buttonsMap[BTN_TL] = QGamepadManager::ButtonL1;
- m_buttonsMap[BTN_TR] = QGamepadManager::ButtonR1;
- m_buttonsMap[BTN_TL2] = QGamepadManager::ButtonL2;
- m_buttonsMap[BTN_TR2] = QGamepadManager::ButtonR2;
- m_buttonsMap[BTN_THUMB] = m_buttonsMap[BTN_THUMBL] = QGamepadManager::ButtonL3;
- m_buttonsMap[BTN_THUMBR] = QGamepadManager::ButtonR3;
- m_buttonsMap[BTN_TRIGGER_HAPPY1] = QGamepadManager::ButtonLeft;
- m_buttonsMap[BTN_TRIGGER_HAPPY2] = QGamepadManager::ButtonRight;
- m_buttonsMap[BTN_TRIGGER_HAPPY3] = QGamepadManager::ButtonUp;
- m_buttonsMap[BTN_TRIGGER_HAPPY4] = QGamepadManager::ButtonDown;
-
- if (m_productId)
- m_backend->saveSettings(m_productId, QVariant());
-}
-
-bool QEvdevGamepadDevice::isConfigurationNeeded()
-{
- return m_needsConfigure;
-}
-
-bool QEvdevGamepadDevice::configureButton(QGamepadManager::GamepadButton button)
-{
- m_configureButton = button;
- return true;
-}
-
-bool QEvdevGamepadDevice::configureAxis(QGamepadManager::GamepadAxis axis)
-{
- m_configureAxis = axis;
- return true;
-}
-
-bool QEvdevGamepadDevice::setCancelConfigureButton(QGamepadManager::GamepadButton button)
-{
- m_configureCancelButton = button;
- return true;
-}
-
-bool QEvdevGamepadDevice::openDevice(const QByteArray &dev)
-{
- m_fd = QT_OPEN(dev.constData(), O_RDONLY | O_NDELAY, 0);
-
- if (m_fd >= 0) {
- m_notifier = new QSocketNotifier(m_fd, QSocketNotifier::Read, this);
- connect(m_notifier, SIGNAL(activated(int)), this, SLOT(readData()));
- qCDebug(lcEGB) << "Successfully opened" << dev;
- } else {
- qErrnoWarning(errno, "Gamepad: Cannot open input device %s", qPrintable(dev));
- return false;
- }
-
- input_id id;
- if (ioctl(m_fd, EVIOCGID, &id) >= 0) {
- m_productId = id.product;
-
- QVariant settings = m_backend->readSettings(m_productId);
- if (!settings.isNull()) {
- m_needsConfigure = false;
- QVariantMap data = settings.toMap()[QLatin1String("axes")].toMap();
- for (QVariantMap::const_iterator it = data.begin(); it != data.end(); ++it) {
- const int key = it.key().toInt();
- m_axisMap[key].restoreSavedData(m_fd, key, it.value().toMap());
- }
-
- data = settings.toMap()[QLatin1String("buttons")].toMap();
- for (QVariantMap::const_iterator it = data.begin(); it != data.end(); ++it)
- m_buttonsMap[it.key().toInt()] = QGamepadManager::GamepadButton(it.value().toInt());
- }
-
- emit m_backend->gamepadAdded(m_productId);
-
- // same as libevdev::libevdev_set_fd() in libevdev.c
- char buffer[256];
- memset(buffer, 0, sizeof(buffer));
- if (ioctl(m_fd, EVIOCGNAME(sizeof(buffer) - 1), buffer) >= 0)
- emit m_backend->gamepadNamed(m_productId, QString::fromUtf8(buffer));
-
- } else {
- QT_CLOSE(m_fd);
- m_fd = -1;
- return false;
- }
-
- if (m_needsConfigure)
- resetConfiguration();
-
- qCDebug(lcEGB) << "Axis limits:" << m_axisMap;
-
- return true;
-}
-
-QDebug operator<<(QDebug dbg, const QEvdevGamepadDevice::EvdevAxisInfo &axisInfo)
-{
- dbg.nospace() << "AxisInfo(min=" << axisInfo.minValue << ", max=" << axisInfo.maxValue << ")";
- return dbg.space();
-}
-
-void QEvdevGamepadDevice::readData()
-{
- input_event buffer[32];
- int events = 0, n = 0;
- for (; ;) {
- events = QT_READ(m_fd, reinterpret_cast<char*>(buffer) + n, sizeof(buffer) - n);
- if (events <= 0)
- goto err;
- n += events;
- if (n % sizeof(::input_event) == 0)
- break;
- }
-
- n /= sizeof(::input_event);
-
- for (int i = 0; i < n; ++i)
- processInputEvent(&buffer[i]);
-
- return;
-
-err:
- if (!events) {
- qWarning("Gamepad: Got EOF from input device");
- return;
- } else if (events < 0) {
- if (errno != EINTR && errno != EAGAIN) {
- qErrnoWarning(errno, "Gamepad: Could not read from input device");
- if (errno == ENODEV) { // device got disconnected -> stop reading
- delete m_notifier;
- m_notifier = 0;
- QT_CLOSE(m_fd);
- m_fd = -1;
- }
- }
- }
-}
-
-void QEvdevGamepadDevice::saveData()
-{
- if (!m_productId)
- return ;
-
- QVariantMap settings, data;
- for (AxisMap::const_iterator it = m_axisMap.begin(); it != m_axisMap.end(); ++it)
- data[QString::number(it.key())] = it.value().dataToSave();
- settings[QLatin1String("axes")] = data;
-
- data.clear();
- for (ButtonsMap::const_iterator it = m_buttonsMap.begin(); it != m_buttonsMap.end(); ++it)
- data[QString::number(it.key())] = it.value();
-
- settings[QLatin1String("buttons")] = data;
-
- m_backend->saveSettings(m_productId, settings);
-}
-
-void QEvdevGamepadDevice::processInputEvent(input_event *e)
-{
- if (e->type == EV_KEY) {
- QGamepadManager::GamepadButton btn = QGamepadManager::ButtonInvalid;
- ButtonsMap::const_iterator it = m_buttonsMap.find(e->code);
- if (it != m_buttonsMap.end())
- btn = it.value();
-
- const bool pressed = e->value;
- if (m_configureCancelButton != QGamepadManager::ButtonInvalid &&
- m_configureCancelButton != m_configureButton &&
- !pressed && btn == m_configureCancelButton &&
- (m_configureButton != QGamepadManager::ButtonInvalid ||
- m_configureAxis != QGamepadManager::AxisInvalid)) {
- m_configureButton = QGamepadManager::ButtonInvalid;
- m_configureAxis = QGamepadManager::AxisInvalid;
- emit m_backend->configurationCanceled(m_productId);
- return;
- }
-
- if (!pressed && m_configureButton != QGamepadManager::ButtonInvalid) {
- m_buttonsMap[e->code] = m_configureButton;
- QGamepadManager::GamepadButton but = m_configureButton;
- m_configureButton = QGamepadManager::ButtonInvalid;
- saveData();
- emit m_backend->buttonConfigured(m_productId, but);
- }
-
- it = m_buttonsMap.find(e->code);
- if (it != m_buttonsMap.end())
- btn = it.value();
-
- if (btn != QGamepadManager::ButtonInvalid) {
- if (pressed)
- emit m_backend->gamepadButtonPressed(m_productId, btn, 1.0);
- else
- emit m_backend->gamepadButtonReleased(m_productId, btn);
- }
- } else if (e->type == EV_ABS) {
- if (m_configureAxis != QGamepadManager::AxisInvalid) {
- EvdevAxisInfo inf(m_fd, e->code, -32768, 32767, m_configureAxis);
- if (std::abs(inf.normalized(e->value)) == 1) {
- m_axisMap.insert(e->code, EvdevAxisInfo(m_fd, e->code, -32768, 32767, m_configureAxis));
-
- QGamepadManager::GamepadAxis axis = m_configureAxis;
- m_configureAxis = QGamepadManager::AxisInvalid;
-
- saveData();
- emit m_backend->axisConfigured(m_productId, axis);
- } else {
- return;
- }
- }
-
- AxisMap::iterator it = m_axisMap.find(e->code);
- if (m_configureButton != QGamepadManager::ButtonInvalid) {
- EvdevAxisInfo axisInfo;
- if (it != m_axisMap.end())
- axisInfo = it.value();
- else
- axisInfo = EvdevAxisInfo(m_fd, e->code);
-
- axisInfo.gamepadAxis = QGamepadManager::AxisInvalid;
-
- bool save = false;
- if (e->value == axisInfo.minValue) {
- axisInfo.gamepadMinButton = m_configureButton;
- if (axisInfo.gamepadMaxButton != QGamepadManager::ButtonInvalid)
- axisInfo.gamepadMaxButton = m_configureButton;
- save = true;
- } else if (e->value == axisInfo.maxValue) {
- axisInfo.gamepadMaxButton = m_configureButton;
- if (axisInfo.gamepadMinButton != QGamepadManager::ButtonInvalid)
- axisInfo.gamepadMinButton = m_configureButton;
- save = true;
- }
-
- if (save) {
- QGamepadManager::GamepadButton but = m_configureButton;
- m_configureButton = QGamepadManager::ButtonInvalid;
- if (but == QGamepadManager::ButtonL2 || but == QGamepadManager::ButtonR2)
- m_axisMap.insert(e->code, axisInfo);
- saveData();
- emit m_backend->buttonConfigured(m_productId, but);
- }
- }
-
- it = m_axisMap.find(e->code);
- if (it == m_axisMap.end())
- return;
-
- EvdevAxisInfo &info = it.value();
-
- double val = info.normalized(e->value);
-
- if (info.gamepadAxis != QGamepadManager::AxisInvalid)
- emit m_backend->gamepadAxisMoved(m_productId, info.gamepadAxis, val);
-
- if (info.gamepadMaxButton == info.gamepadMinButton &&
- info.gamepadMaxButton != QGamepadManager::ButtonInvalid) {
- if (val)
- emit m_backend->gamepadButtonPressed(m_productId, info.gamepadMaxButton, std::abs(val));
- else
- emit m_backend->gamepadButtonReleased(m_productId, info.gamepadMaxButton);
- } else {
- if (info.gamepadMaxButton != QGamepadManager::ButtonInvalid
- && val == 1.0) {
- info.gamepadLastButton = info.gamepadMaxButton;
- emit m_backend->gamepadButtonPressed(m_productId, info.gamepadMaxButton, val);
- } else if (info.gamepadMinButton != QGamepadManager::ButtonInvalid
- && val == -1.0) {
- info.gamepadLastButton = info.gamepadMinButton;
- emit m_backend->gamepadButtonPressed(m_productId, info.gamepadMinButton, -val);
- } else if (!val && info.gamepadLastButton != QGamepadManager::ButtonInvalid) {
- QGamepadManager::GamepadButton but = info.gamepadLastButton;
- info.gamepadLastButton = QGamepadManager::ButtonInvalid;
- emit m_backend->gamepadButtonReleased(m_productId, but);
- }
- }
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gamepads/evdev/qevdevgamepadbackend_p.h b/src/plugins/gamepads/evdev/qevdevgamepadbackend_p.h
deleted file mode 100644
index 35e2fbd..0000000
--- a/src/plugins/gamepads/evdev/qevdevgamepadbackend_p.h
+++ /dev/null
@@ -1,138 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QEVDEVGAMEPADBACKEND_P_H
-#define QEVDEVGAMEPADBACKEND_P_H
-
-#include <QtGamepad/QGamepadManager>
-#include <QtGamepad/private/qgamepadbackend_p.h>
-#include <QtCore/QHash>
-#include <QtCore/QList>
-
-struct input_event;
-
-QT_BEGIN_NAMESPACE
-
-class QSocketNotifier;
-class QDeviceDiscovery;
-class QEvdevGamepadBackend;
-
-class QEvdevGamepadDevice : public QObject
-{
- Q_OBJECT
-
-public:
- QEvdevGamepadDevice(const QByteArray &dev, QEvdevGamepadBackend *backend);
- ~QEvdevGamepadDevice();
- QByteArray deviceName() const { return m_dev; }
- int deviceId() const { return m_productId; }
- void resetConfiguration();
- bool isConfigurationNeeded();
- bool configureButton(QGamepadManager::GamepadButton button);
- bool configureAxis(QGamepadManager::GamepadAxis axis);
- bool setCancelConfigureButton(QGamepadManager::GamepadButton button);
-
-private Q_SLOTS:
- void readData();
-
-private:
- void saveData();
- void processInputEvent(input_event *e);
- bool openDevice(const QByteArray &dev);
-
- QByteArray m_dev;
- QEvdevGamepadBackend *m_backend;
- int m_fd;
- int m_productId;
- bool m_needsConfigure;
- QSocketNotifier *m_notifier;
- struct EvdevAxisInfo : public QGamepadBackend::AxisInfo<int>
- {
- EvdevAxisInfo();
- EvdevAxisInfo(int fd, quint16 abs, int minValue = 0, int maxValue = 1, QGamepadManager::GamepadAxis gamepadAxis = QGamepadManager::AxisInvalid);
- double normalized(int value) const override;
- void setAbsInfo(int fd, int abs);
- void restoreSavedData(int fd, int abs, const QVariantMap &value);
- QVariantMap dataToSave() const;
- double flat;
- QGamepadManager::GamepadButton gamepadMinButton;
- QGamepadManager::GamepadButton gamepadMaxButton;
- QGamepadManager::GamepadButton gamepadLastButton;
- };
- typedef QHash<int, EvdevAxisInfo> AxisMap;
- AxisMap m_axisMap;
-
- friend QDebug operator<<(QDebug dbg, const QEvdevGamepadDevice::EvdevAxisInfo &axisInfo);
-
- typedef QHash<int, QGamepadManager::GamepadButton> ButtonsMap;
- ButtonsMap m_buttonsMap;
-
- QGamepadManager::GamepadButton m_configureButton;
- QGamepadManager::GamepadAxis m_configureAxis;
- QGamepadManager::GamepadButton m_configureCancelButton;
-};
-
-QDebug operator<<(QDebug dbg, const QEvdevGamepadDevice::EvdevAxisInfo &axisInfo);
-
-class QEvdevGamepadBackend : public QGamepadBackend
-{
- Q_OBJECT
-
-public:
- QEvdevGamepadBackend();
- bool start() override;
- void stop() override;
- void resetConfiguration(int deviceId) override;
- bool isConfigurationNeeded(int deviceId) override;
- bool configureButton(int deviceId, QGamepadManager::GamepadButton button) override;
- bool configureAxis(int deviceId, QGamepadManager::GamepadAxis axis) override;
- bool setCancelConfigureButton(int deviceId, QGamepadManager::GamepadButton button) override;
-
-private slots:
- void handleAddedDevice(const QString &device);
- void handleRemovedDevice(const QString &device);
-
-private:
- QEvdevGamepadDevice *newDevice(const QByteArray &device);
- QEvdevGamepadDevice *device(int deviceId);
-
- QDeviceDiscovery *m_discovery;
- QList<QEvdevGamepadDevice *> m_devices;
-};
-
-QT_END_NAMESPACE
-
-#endif // QEVDEVGAMEPADBACKEND_P_H
diff --git a/src/plugins/gamepads/gamepads.pro b/src/plugins/gamepads/gamepads.pro
deleted file mode 100644
index 2151b79..0000000
--- a/src/plugins/gamepads/gamepads.pro
+++ /dev/null
@@ -1,7 +0,0 @@
-TEMPLATE = subdirs
-QT_FOR_CONFIG += gui-private gamepad-private
-qtConfig(sdl2): SUBDIRS += sdl2
-!android: qtConfig(evdev): SUBDIRS += evdev
-win32: SUBDIRS += xinput
-darwin: !watchos: SUBDIRS += darwin
-android: !android-embedded: SUBDIRS += android
diff --git a/src/plugins/gamepads/sdl2/main.cpp b/src/plugins/gamepads/sdl2/main.cpp
deleted file mode 100644
index 30b0ceb..0000000
--- a/src/plugins/gamepads/sdl2/main.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtGamepad/private/qgamepadbackendfactory_p.h>
-#include <QtGamepad/private/qgamepadbackendplugin_p.h>
-
-#include "qsdlgamepadbackend_p.h"
-
-QT_BEGIN_NAMESPACE
-
-class QSdl2GamepadBackendPlugin : public QGamepadBackendPlugin
-{
- Q_OBJECT
- Q_PLUGIN_METADATA(IID QtGamepadBackendFactoryInterface_iid FILE "sdl2.json")
-public:
- QGamepadBackend *create(const QString &key, const QStringList &paramList) override;
-};
-
-QGamepadBackend *QSdl2GamepadBackendPlugin::create(const QString &key, const QStringList &paramList) {
- Q_UNUSED(key);
- Q_UNUSED(paramList);
-
- return new QSdlGamepadBackend();
-}
-
-QT_END_NAMESPACE
-
-#include "main.moc"
diff --git a/src/plugins/gamepads/sdl2/qsdlgamepadbackend.cpp b/src/plugins/gamepads/sdl2/qsdlgamepadbackend.cpp
deleted file mode 100644
index 6a7cee6..0000000
--- a/src/plugins/gamepads/sdl2/qsdlgamepadbackend.cpp
+++ /dev/null
@@ -1,210 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "qsdlgamepadbackend_p.h"
-
-#include <QtCore/QDebug>
-
-#include <SDL.h>
-// Reset bool redefinition from SDL header
-#undef bool
-
-QT_BEGIN_NAMESPACE
-
-QSdlGamepadBackend::QSdlGamepadBackend(QObject *parent)
- : QGamepadBackend(parent)
-{
- connect(&m_eventLoopTimer, SIGNAL(timeout()), this, SLOT(pumpSdlEventLoop()));
-}
-
-QSdlGamepadBackend::~QSdlGamepadBackend()
-{
-}
-
-void QSdlGamepadBackend::pumpSdlEventLoop()
-{
- SDL_Event event;
- while (SDL_PollEvent(&event)) {
- if (event.type == SDL_CONTROLLERAXISMOTION) {
- SDL_ControllerAxisEvent axisEvent = event.caxis;
- //qDebug() << axisEvent.timestamp << "Axis Event: " << axisEvent.which << axisEvent.axis << axisEvent.value;
- double value;
- if (axisEvent.value >= 0)
- value = axisEvent.value / 32767.0;
- else
- value = axisEvent.value / 32768.0;
- switch (axisEvent.axis) {
- case SDL_CONTROLLER_AXIS_LEFTX:
- emit gamepadAxisMoved(m_instanceIdForIndex[axisEvent.which], QGamepadManager::AxisLeftX, value);
- break;
- case SDL_CONTROLLER_AXIS_LEFTY:
- emit gamepadAxisMoved(m_instanceIdForIndex[axisEvent.which], QGamepadManager::AxisLeftY, value);
- break;
- case SDL_CONTROLLER_AXIS_RIGHTX:
- emit gamepadAxisMoved(m_instanceIdForIndex[axisEvent.which], QGamepadManager::AxisRightX, value);
- break;
- case SDL_CONTROLLER_AXIS_RIGHTY:
- emit gamepadAxisMoved(m_instanceIdForIndex[axisEvent.which], QGamepadManager::AxisRightY, value);
- break;
- case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
- if (value == 0)
- emit gamepadButtonReleased(m_instanceIdForIndex[axisEvent.which], QGamepadManager::ButtonL2);
- else
- emit gamepadButtonPressed(m_instanceIdForIndex[axisEvent.which], QGamepadManager::ButtonL2, value);
- break;
- case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
- if (value == 0)
- emit gamepadButtonReleased(m_instanceIdForIndex[axisEvent.which], QGamepadManager::ButtonR2);
- else
- emit gamepadButtonPressed(m_instanceIdForIndex[axisEvent.which], QGamepadManager::ButtonR2, value);
- break;
- default:
- break;
- }
-
- } else if (event.type == SDL_CONTROLLERBUTTONDOWN) {
- SDL_ControllerButtonEvent buttonEvent = event.cbutton;
- //qDebug() << buttonEvent.timestamp << "Button Press: " << buttonEvent.which << buttonEvent.button << buttonEvent.state;
- emit gamepadButtonPressed(m_instanceIdForIndex[buttonEvent.which], translateButton(buttonEvent.button), 1.0);
- } else if (event.type == SDL_CONTROLLERBUTTONUP) {
- SDL_ControllerButtonEvent buttonEvent = event.cbutton;
- //qDebug() << buttonEvent.timestamp << "Button Release: " << buttonEvent.which << buttonEvent.button << buttonEvent.state;
- emit gamepadButtonReleased(m_instanceIdForIndex[buttonEvent.which], translateButton(buttonEvent.button));
- } else if (event.type == SDL_CONTROLLERDEVICEADDED) {
- SDL_ControllerDeviceEvent deviceEvent = event.cdevice;
- //qDebug() << deviceEvent.timestamp << "Controller Added: " << deviceEvent.which;
- addController(deviceEvent.which);
- } else if (event.type == SDL_CONTROLLERDEVICEREMOVED) {
- SDL_ControllerDeviceEvent deviceEvent = event.cdevice;
-
- int index = m_instanceIdForIndex[deviceEvent.which];
- SDL_GameControllerClose(m_indexForController[index]);
- emit gamepadRemoved(index);
- m_indexForController.remove(index);
- m_instanceIdForIndex.remove(deviceEvent.which);
-
- } else if (event.type == SDL_CONTROLLERDEVICEREMAPPED) {
- //SDL_ControllerDeviceEvent deviceEvent = event.cdevice;
- //qDebug() << deviceEvent.timestamp << "Controller Remapped: " << deviceEvent.which;
- }
- }
-}
-
-bool QSdlGamepadBackend::start()
-{
- //Initialize SDL with necessary subsystems for gamepad support
- if (SDL_Init(SDL_INIT_GAMECONTROLLER | SDL_INIT_JOYSTICK)) {
- qDebug() << SDL_GetError();
- return false;
- }
-
- m_eventLoopTimer.start(16);
- for (int i = 0; i < SDL_NumJoysticks() ; i++)
- addController(i);
-
- return true;
-}
-
-void QSdlGamepadBackend::stop()
-{
- m_eventLoopTimer.stop();
- SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER | SDL_INIT_JOYSTICK);
-}
-
-QGamepadManager::GamepadButton QSdlGamepadBackend::translateButton(int button)
-{
- switch (button) {
- case SDL_CONTROLLER_BUTTON_A:
- return QGamepadManager::ButtonA;
- case SDL_CONTROLLER_BUTTON_B:
- return QGamepadManager::ButtonB;
- case SDL_CONTROLLER_BUTTON_X:
- return QGamepadManager::ButtonX;
- case SDL_CONTROLLER_BUTTON_Y:
- return QGamepadManager::ButtonY;
- case SDL_CONTROLLER_BUTTON_BACK:
- return QGamepadManager::ButtonSelect;
- case SDL_CONTROLLER_BUTTON_GUIDE:
- return QGamepadManager::ButtonGuide;
- case SDL_CONTROLLER_BUTTON_START:
- return QGamepadManager::ButtonStart;
- case SDL_CONTROLLER_BUTTON_LEFTSTICK:
- return QGamepadManager::ButtonL3;
- case SDL_CONTROLLER_BUTTON_RIGHTSTICK:
- return QGamepadManager::ButtonR3;
- case SDL_CONTROLLER_BUTTON_LEFTSHOULDER:
- return QGamepadManager::ButtonL1;
- case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
- return QGamepadManager::ButtonR1;
- case SDL_CONTROLLER_BUTTON_DPAD_UP:
- return QGamepadManager::ButtonUp;
- case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
- return QGamepadManager::ButtonDown;
- case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
- return QGamepadManager::ButtonLeft;
- case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
- return QGamepadManager::ButtonRight;
- default:
- return QGamepadManager::ButtonInvalid;
- }
-}
-
-void QSdlGamepadBackend::addController(int index)
-{
- char GUID[100];
- SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(index), GUID, 100);
- if (!SDL_IsGameController(index))
- return;
-
- SDL_GameController *controller = SDL_GameControllerOpen(index);
- if (controller) {
- m_indexForController.insert(index, controller);
-
- SDL_Joystick *joystick = SDL_GameControllerGetJoystick(controller);
-
- int instanceID = SDL_JoystickInstanceID(joystick);
- m_instanceIdForIndex.insert(instanceID, index);
-
- const char *name = SDL_JoystickName(joystick);
-
- //qDebug() << "Controller " << index << " added with instanceId: " << instanceID;
- emit gamepadAdded(index);
-
- if (name)
- emit gamepadNamed(index, QString::fromUtf8(name));
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gamepads/sdl2/qsdlgamepadbackend_p.h b/src/plugins/gamepads/sdl2/qsdlgamepadbackend_p.h
deleted file mode 100644
index dfd7176..0000000
--- a/src/plugins/gamepads/sdl2/qsdlgamepadbackend_p.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QSDLGAMEPADBACKEND_P_H
-#define QSDLGAMEPADBACKEND_P_H
-
-#include <QtCore/QTimer>
-#include <QtCore/QMap>
-
-#include <SDL_gamecontroller.h>
-
-#include <QtGamepad/QGamepadManager>
-#include <QtGamepad/private/qgamepadbackend_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class QSdlGamepadBackend : public QGamepadBackend
-{
- Q_OBJECT
-public:
- explicit QSdlGamepadBackend(QObject *parent = nullptr);
- ~QSdlGamepadBackend();
-
-private Q_SLOTS:
- void pumpSdlEventLoop();
-
-protected:
- bool start() override;
- void stop() override;
-
-private:
- QGamepadManager::GamepadButton translateButton(int button);
- void addController(int index);
- QTimer m_eventLoopTimer;
- QMap<int, SDL_GameController*> m_indexForController;
- QMap<int, int> m_instanceIdForIndex;
-};
-
-QT_END_NAMESPACE
-
-#endif // QSDLGAMEPADBACKEND_P_H
diff --git a/src/plugins/gamepads/sdl2/sdl2.json b/src/plugins/gamepads/sdl2/sdl2.json
deleted file mode 100644
index d2bd585..0000000
--- a/src/plugins/gamepads/sdl2/sdl2.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "Keys": [ "sdl2" ]
-}
diff --git a/src/plugins/gamepads/sdl2/sdl2.pro b/src/plugins/gamepads/sdl2/sdl2.pro
deleted file mode 100644
index 91715a3..0000000
--- a/src/plugins/gamepads/sdl2/sdl2.pro
+++ /dev/null
@@ -1,17 +0,0 @@
-TARGET = sdl2gamepad
-QT += gamepad gamepad-private
-
-PLUGIN_TYPE = gamepads
-PLUGIN_CLASS_NAME = QSdl2GamepadBackendPlugin
-load(qt_plugin)
-
-QMAKE_USE += sdl2
-
-HEADERS += qsdlgamepadbackend_p.h
-SOURCES += \
- qsdlgamepadbackend.cpp \
- main.cpp
-
-OTHER_FILES += \
- sdl2.json
-
diff --git a/src/plugins/gamepads/xinput/main.cpp b/src/plugins/gamepads/xinput/main.cpp
deleted file mode 100644
index c157cfd..0000000
--- a/src/plugins/gamepads/xinput/main.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtGamepad/private/qgamepadbackendfactory_p.h>
-#include <QtGamepad/private/qgamepadbackendplugin_p.h>
-
-#include "qxinputgamepadbackend_p.h"
-
-QT_BEGIN_NAMESPACE
-
-class QXInputGamepadBackendPlugin : public QGamepadBackendPlugin
-{
- Q_OBJECT
- Q_PLUGIN_METADATA(IID QtGamepadBackendFactoryInterface_iid FILE "xinput.json")
-public:
- QGamepadBackend *create(const QString &key, const QStringList &paramList) override;
-};
-
-QGamepadBackend *QXInputGamepadBackendPlugin::create(const QString &key, const QStringList &paramList)
-{
- Q_UNUSED(key);
- Q_UNUSED(paramList);
-
- return new QXInputGamepadBackend;
-}
-
-QT_END_NAMESPACE
-
-#include "main.moc"
diff --git a/src/plugins/gamepads/xinput/qxinputgamepadbackend.cpp b/src/plugins/gamepads/xinput/qxinputgamepadbackend.cpp
deleted file mode 100644
index 4d042c9..0000000
--- a/src/plugins/gamepads/xinput/qxinputgamepadbackend.cpp
+++ /dev/null
@@ -1,291 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "qxinputgamepadbackend_p.h"
-#include <QtCore/QLoggingCategory>
-#include <QtCore/QThread>
-#include <qmath.h>
-#include <windows.h>
-
-QT_BEGIN_NAMESPACE
-
-Q_LOGGING_CATEGORY(lcXGB, "qt.gamepad")
-
-#define POLL_SLEEP_MS 5
-#define POLL_SLOT_CHECK_MS 4000
-
-#define XUSER_MAX_COUNT 4
-
-#define XINPUT_GAMEPAD_DPAD_UP 0x0001
-#define XINPUT_GAMEPAD_DPAD_DOWN 0x0002
-#define XINPUT_GAMEPAD_DPAD_LEFT 0x0004
-#define XINPUT_GAMEPAD_DPAD_RIGHT 0x0008
-#define XINPUT_GAMEPAD_START 0x0010
-#define XINPUT_GAMEPAD_BACK 0x0020
-#define XINPUT_GAMEPAD_LEFT_THUMB 0x0040
-#define XINPUT_GAMEPAD_RIGHT_THUMB 0x0080
-#define XINPUT_GAMEPAD_LEFT_SHOULDER 0x0100
-#define XINPUT_GAMEPAD_RIGHT_SHOULDER 0x0200
-#define XINPUT_GAMEPAD_A 0x1000
-#define XINPUT_GAMEPAD_B 0x2000
-#define XINPUT_GAMEPAD_X 0x4000
-#define XINPUT_GAMEPAD_Y 0x8000
-
-#define XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE 7849
-#define XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE 8689
-#define XINPUT_GAMEPAD_TRIGGER_THRESHOLD 30
-
-struct XINPUT_GAMEPAD
-{
- unsigned short wButtons;
- unsigned char bLeftTrigger;
- unsigned char bRightTrigger;
- short sThumbLX;
- short sThumbLY;
- short sThumbRX;
- short sThumbRY;
-};
-
-struct XINPUT_STATE
-{
- unsigned long dwPacketNumber;
- XINPUT_GAMEPAD Gamepad;
-};
-
-typedef DWORD (WINAPI *XInputGetState_t)(DWORD dwUserIndex, XINPUT_STATE *pState);
-static XInputGetState_t XInputGetState;
-
-class QXInputThread : public QThread
-{
-public:
- QXInputThread(QXInputGamepadBackend *backend);
- void run() override;
- void signalQuit() { m_quit.fetchAndStoreAcquire(1); }
-
-private:
- void dispatch(int idx, XINPUT_GAMEPAD *state);
-
- QXInputGamepadBackend *m_backend;
- QAtomicInt m_quit;
- struct Controller {
- bool connected;
- int skippedPolls;
- unsigned long lastPacketNumber;
- // State cache. Only want to emit signals for values that really change.
- unsigned short buttons;
- unsigned char triggers[2];
- double axis[2][2];
- } m_controllers[XUSER_MAX_COUNT];
-};
-
-QXInputThread::QXInputThread(QXInputGamepadBackend *backend)
- : m_backend(backend),
- m_quit(false)
-{
- memset(m_controllers, 0, sizeof(m_controllers));
-}
-
-void QXInputThread::dispatch(int idx, XINPUT_GAMEPAD *state)
-{
- static const struct ButtonMap {
- unsigned short xbutton;
- QGamepadManager::GamepadButton qbutton;
- } buttonMap[] = {
- { XINPUT_GAMEPAD_DPAD_UP, QGamepadManager::ButtonUp },
- { XINPUT_GAMEPAD_DPAD_DOWN, QGamepadManager::ButtonDown },
- { XINPUT_GAMEPAD_DPAD_LEFT, QGamepadManager::ButtonLeft },
- { XINPUT_GAMEPAD_DPAD_RIGHT, QGamepadManager::ButtonRight },
- { XINPUT_GAMEPAD_START, QGamepadManager::ButtonStart },
- { XINPUT_GAMEPAD_BACK, QGamepadManager::ButtonSelect },
- { XINPUT_GAMEPAD_LEFT_SHOULDER, QGamepadManager::ButtonL1 },
- { XINPUT_GAMEPAD_RIGHT_SHOULDER, QGamepadManager::ButtonR1 },
- { XINPUT_GAMEPAD_LEFT_THUMB, QGamepadManager::ButtonL3 },
- { XINPUT_GAMEPAD_RIGHT_THUMB, QGamepadManager::ButtonR3 },
- { XINPUT_GAMEPAD_A, QGamepadManager::ButtonA },
- { XINPUT_GAMEPAD_B, QGamepadManager::ButtonB },
- { XINPUT_GAMEPAD_X, QGamepadManager::ButtonX },
- { XINPUT_GAMEPAD_Y, QGamepadManager::ButtonY }
- };
- for (uint i = 0; i < sizeof(buttonMap) / sizeof(ButtonMap); ++i) {
- const unsigned short xb = buttonMap[i].xbutton;
- unsigned short isDown = state->wButtons & xb;
- if (isDown != (m_controllers[idx].buttons & xb)) {
- if (isDown) {
- m_controllers[idx].buttons |= xb;
- emit m_backend->gamepadButtonPressed(idx, buttonMap[i].qbutton, 1);
- } else {
- m_controllers[idx].buttons &= ~xb;
- emit m_backend->gamepadButtonReleased(idx, buttonMap[i].qbutton);
- }
- }
- }
-
- if (m_controllers[idx].triggers[0] != state->bLeftTrigger) {
- m_controllers[idx].triggers[0] = state->bLeftTrigger;
- const double value = state->bLeftTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD
- ? (state->bLeftTrigger - XINPUT_GAMEPAD_TRIGGER_THRESHOLD)
- / (255.0 - XINPUT_GAMEPAD_TRIGGER_THRESHOLD)
- : 0.0;
- if (!qFuzzyIsNull(value))
- emit m_backend->gamepadButtonPressed(idx, QGamepadManager::ButtonL2, value);
- else
- emit m_backend->gamepadButtonReleased(idx, QGamepadManager::ButtonL2);
- }
- if (m_controllers[idx].triggers[1] != state->bRightTrigger) {
- m_controllers[idx].triggers[1] = state->bRightTrigger;
- const double value = state->bRightTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD
- ? (state->bRightTrigger - XINPUT_GAMEPAD_TRIGGER_THRESHOLD)
- / (255.0 - XINPUT_GAMEPAD_TRIGGER_THRESHOLD)
- : 0.0;
- if (!qFuzzyIsNull(value))
- emit m_backend->gamepadButtonPressed(idx, QGamepadManager::ButtonR2, value);
- else
- emit m_backend->gamepadButtonReleased(idx, QGamepadManager::ButtonR2);
- }
-
- double x, y;
- if (qSqrt(state->sThumbLX * state->sThumbLX + state->sThumbLY * state->sThumbLY) > XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) {
- x = 2 * (state->sThumbLX + 32768.0) / 65535.0 - 1.0;
- y = 2 * (-state->sThumbLY + 32768.0) / 65535.0 - 1.0;
- } else {
- x = y = 0;
- }
- if (m_controllers[idx].axis[0][0] != x) {
- m_controllers[idx].axis[0][0] = x;
- emit m_backend->gamepadAxisMoved(idx, QGamepadManager::AxisLeftX, x);
- }
- if (m_controllers[idx].axis[0][1] != y) {
- m_controllers[idx].axis[0][1] = y;
- emit m_backend->gamepadAxisMoved(idx, QGamepadManager::AxisLeftY, y);
- }
- if (qSqrt(state->sThumbRX * state->sThumbRX + state->sThumbRY * state->sThumbRY) > XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) {
- x = 2 * (state->sThumbRX + 32768.0) / 65535.0 - 1.0;
- y = 2 * (-state->sThumbRY + 32768.0) / 65535.0 - 1.0;
- } else {
- x = y = 0;
- }
- if (m_controllers[idx].axis[1][0] != x) {
- m_controllers[idx].axis[1][0] = x;
- emit m_backend->gamepadAxisMoved(idx, QGamepadManager::AxisRightX, x);
- }
- if (m_controllers[idx].axis[1][1] != y) {
- m_controllers[idx].axis[1][1] = y;
- emit m_backend->gamepadAxisMoved(idx, QGamepadManager::AxisRightY, y);
- }
-}
-
-void QXInputThread::run()
-{
- qCDebug(lcXGB, "XInput thread running");
- bool firstPoll = true;
- while (!m_quit.testAndSetAcquire(1, 0)) {
- for (int i = 0; i < XUSER_MAX_COUNT; ++i) {
- Controller *controller = m_controllers + i;
-
- if (!firstPoll && !controller->connected && controller->skippedPolls < POLL_SLOT_CHECK_MS / POLL_SLEEP_MS) {
- controller->skippedPolls++;
- continue;
- }
-
- firstPoll = false;
- controller->skippedPolls = 0;
- XINPUT_STATE state;
- memset(&state, 0, sizeof(state));
-
- if (XInputGetState(i, &state) == ERROR_SUCCESS) {
- if (controller->connected) {
- if (controller->lastPacketNumber != state.dwPacketNumber) {
- controller->lastPacketNumber = state.dwPacketNumber;
- dispatch(i, &state.Gamepad);
- }
- } else {
- controller->connected = true;
- controller->lastPacketNumber = state.dwPacketNumber;
- emit m_backend->gamepadAdded(i);
- dispatch(i, &state.Gamepad);
- }
- } else {
- if (controller->connected) {
- controller->connected = false;
- emit m_backend->gamepadRemoved(i);
- }
- }
- }
-
- Sleep(POLL_SLEEP_MS);
- }
- qCDebug(lcXGB, "XInput thread stopping");
-}
-
-QXInputGamepadBackend::QXInputGamepadBackend()
- : m_thread(0)
-{
-}
-
-bool QXInputGamepadBackend::start()
-{
- qCDebug(lcXGB) << "start";
-
- m_lib.setFileName(QStringLiteral("xinput1_4.dll"));
- if (!m_lib.load()) {
- m_lib.setFileName(QStringLiteral("xinput1_3.dll"));
- m_lib.load();
- }
-
- if (m_lib.isLoaded()) {
- qCDebug(lcXGB, "Loaded XInput library %s", qPrintable(m_lib.fileName()));
- XInputGetState = (XInputGetState_t) m_lib.resolve("XInputGetState");
- if (XInputGetState) {
- m_thread = new QXInputThread(this);
- m_thread->start();
- } else {
- qWarning("Failed to resolve XInputGetState");
- }
- } else {
- qWarning("Failed to load XInput library %s", qPrintable(m_lib.fileName()));
- }
-
- return m_lib.isLoaded();
-}
-
-void QXInputGamepadBackend::stop()
-{
- qCDebug(lcXGB) << "stop";
- m_thread->signalQuit();
- m_thread->wait();
- XInputGetState = 0;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gamepads/xinput/qxinputgamepadbackend_p.h b/src/plugins/gamepads/xinput/qxinputgamepadbackend_p.h
deleted file mode 100644
index 28f5b23..0000000
--- a/src/plugins/gamepads/xinput/qxinputgamepadbackend_p.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef QXINPUTGAMEPADBACKEND_P_H
-#define QXINPUTGAMEPADBACKEND_P_H
-
-#include <QtGamepad/QGamepadManager>
-#include <QtGamepad/private/qgamepadbackend_p.h>
-#include <QtCore/QLibrary>
-
-QT_BEGIN_NAMESPACE
-
-class QXInputThread;
-
-class QXInputGamepadBackend : public QGamepadBackend
-{
- Q_OBJECT
-
-public:
- QXInputGamepadBackend();
- bool start() override;
- void stop() override;
-
-private:
- QXInputThread *m_thread;
- QLibrary m_lib;
-};
-
-QT_END_NAMESPACE
-
-#endif // QXINPUTGAMEPADBACKEND_P_H
diff --git a/src/plugins/gamepads/xinput/xinput.json b/src/plugins/gamepads/xinput/xinput.json
deleted file mode 100644
index f8e3fb2..0000000
--- a/src/plugins/gamepads/xinput/xinput.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "Keys": [ "xinput" ]
-}
diff --git a/src/plugins/gamepads/xinput/xinput.pro b/src/plugins/gamepads/xinput/xinput.pro
deleted file mode 100644
index 5dac854..0000000
--- a/src/plugins/gamepads/xinput/xinput.pro
+++ /dev/null
@@ -1,14 +0,0 @@
-TARGET = xinputgamepad
-QT += gamepad gamepad-private
-
-PLUGIN_TYPE = gamepads
-PLUGIN_CLASS_NAME = QXInputGamepadBackendPlugin
-load(qt_plugin)
-
-HEADERS += qxinputgamepadbackend_p.h
-SOURCES += \
- qxinputgamepadbackend.cpp \
- main.cpp
-
-OTHER_FILES += \
- xinput.json