2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2010 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2014-02-10 18:54:46 +00:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2017-11-04 14:37:03 +00:00
|
|
|
#include <atomic>
|
2017-02-19 08:00:00 +00:00
|
|
|
#include <functional>
|
2017-11-10 20:29:25 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <mutex>
|
2014-02-17 10:18:15 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "InputCommon/ControllerInterface/Device.h"
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
// enable disable sources
|
|
|
|
#ifdef _WIN32
|
2016-06-24 08:43:46 +00:00
|
|
|
#define CIFACE_USE_XINPUT
|
|
|
|
#define CIFACE_USE_DINPUT
|
2010-07-16 19:17:35 +00:00
|
|
|
#endif
|
|
|
|
#if defined(HAVE_X11) && HAVE_X11
|
2016-06-24 08:43:46 +00:00
|
|
|
#define CIFACE_USE_XLIB
|
2010-07-16 19:17:35 +00:00
|
|
|
#endif
|
2010-04-02 09:41:43 +00:00
|
|
|
#if defined(__APPLE__)
|
2016-06-24 08:43:46 +00:00
|
|
|
#define CIFACE_USE_OSX
|
2010-04-02 09:41:43 +00:00
|
|
|
#endif
|
2015-06-29 00:17:35 +00:00
|
|
|
#if defined(HAVE_LIBEVDEV) && defined(HAVE_LIBUDEV)
|
2016-06-24 08:43:46 +00:00
|
|
|
#define CIFACE_USE_EVDEV
|
2015-06-29 00:17:35 +00:00
|
|
|
#endif
|
2015-10-25 03:20:03 +00:00
|
|
|
#if defined(USE_PIPES)
|
2016-06-24 08:43:46 +00:00
|
|
|
#define CIFACE_USE_PIPES
|
2015-10-25 03:20:03 +00:00
|
|
|
#endif
|
2013-06-17 00:07:10 +00:00
|
|
|
|
2010-04-02 02:48:24 +00:00
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// ControllerInterface
|
2010-04-02 02:48:24 +00:00
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// Some crazy shit I made to control different device inputs and outputs
|
|
|
|
// from lots of different sources, hopefully more easily.
|
2010-04-02 02:48:24 +00:00
|
|
|
//
|
2014-09-05 00:41:42 +00:00
|
|
|
class ControllerInterface : public ciface::Core::DeviceContainer
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
|
|
|
public:
|
2016-06-24 08:43:46 +00:00
|
|
|
ControllerInterface() : m_is_init(false), m_hwnd(nullptr) {}
|
|
|
|
void Initialize(void* const hwnd);
|
2016-10-16 20:39:05 +00:00
|
|
|
void RefreshDevices();
|
2016-06-24 08:43:46 +00:00
|
|
|
void Shutdown();
|
2016-06-25 19:46:39 +00:00
|
|
|
void AddDevice(std::shared_ptr<ciface::Core::Device> device);
|
2016-07-14 15:45:59 +00:00
|
|
|
void RemoveDevice(std::function<bool(const ciface::Core::Device*)> callback);
|
2016-06-24 08:43:46 +00:00
|
|
|
bool IsInit() const { return m_is_init; }
|
|
|
|
void UpdateInput();
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2017-11-04 14:36:30 +00:00
|
|
|
void RegisterDevicesChangedCallback(std::function<void(void)> callback);
|
|
|
|
void InvokeDevicesChangedCallbacks() const;
|
2016-06-13 09:11:47 +00:00
|
|
|
|
2010-04-02 02:48:24 +00:00
|
|
|
private:
|
2017-11-04 14:36:30 +00:00
|
|
|
std::vector<std::function<void()>> m_devices_changed_callbacks;
|
2017-11-10 20:29:25 +00:00
|
|
|
mutable std::mutex m_callbacks_mutex;
|
2016-06-24 08:43:46 +00:00
|
|
|
bool m_is_init;
|
2017-11-04 14:37:03 +00:00
|
|
|
std::atomic<bool> m_is_populating_devices{false};
|
2016-06-24 08:43:46 +00:00
|
|
|
void* m_hwnd;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
|
|
|
|
2010-10-12 19:42:29 +00:00
|
|
|
extern ControllerInterface g_controller_interface;
|