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