BsMacOSInput.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2017 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include <IOKit/hid/IOHIDLib.h>
  6. namespace bs
  7. {
  8. /** Available types of devices supported by the HIDManager. */
  9. enum class HIDType
  10. {
  11. Keyboard,
  12. Mouse,
  13. Gamepad
  14. };
  15. /**
  16. * Contains information about a single element of an input device (e.g. a button, an axis), as reported by the
  17. * HIDManager.
  18. */
  19. struct HIDElement
  20. {
  21. IOHIDElementRef ref;
  22. IOHIDElementCookie cookie;
  23. INT32 min, max;
  24. mutable INT32 detectedMin, detectedMax;
  25. UINT32 usage;
  26. };
  27. /** Contains information about a single input device and its elements, as reported by the HIDManager. */
  28. struct HIDDevice
  29. {
  30. IOHIDDeviceRef ref;
  31. IOHIDQueueRef queueRef;
  32. String name;
  33. UINT32 id;
  34. Vector<HIDElement> axes;
  35. Vector<HIDElement> buttons;
  36. Vector<HIDElement> hats;
  37. };
  38. /** Contains information about all enumerated input devices for a specific HIDManager. */
  39. struct HIDData
  40. {
  41. Vector<HIDDevice> devices;
  42. HIDType type;
  43. Input* owner = nullptr;
  44. };
  45. /**
  46. * Provides access to the low level IO HID manager. Enumerates available input devices and reports their input to the
  47. * Input object.
  48. */
  49. class HIDManager
  50. {
  51. public:
  52. /**
  53. * Constructs a new HID manager object.
  54. *
  55. * @param type Determines what category of input devices will this manager enumerate and report events for.
  56. * @param input Input object that will by called by the HID manager when input events occur.
  57. */
  58. HIDManager(HIDType type, Input* input);
  59. ~HIDManager();
  60. /**
  61. * Checks if any new input events have been generates and reports them to the Input object.
  62. *
  63. * @param[in] device Device to read events from. If null, the events are read from all devices of the
  64. * compatible type.
  65. * @param[in] ignoreEvents If true the system will not trigger any external events for the reported input. This
  66. * can be useful for situations where input is disabled, like an out-of-focus window.
  67. */
  68. void capture(IOHIDDeviceRef device, bool ignoreEvents = false);
  69. private:
  70. IOHIDManagerRef mHIDManager = nullptr;
  71. HIDData mData;
  72. };
  73. /** Information about a gamepad. */
  74. struct GamepadInfo
  75. {
  76. UINT32 id;
  77. String name;
  78. IOHIDDeviceRef deviceRef;
  79. HIDManager* hid;
  80. };
  81. /**
  82. * Data specific to MacOS implementation of the input system. Can be passed to platform specific implementations of
  83. * the individual device types.
  84. */
  85. struct InputPrivateData
  86. {
  87. Vector<GamepadInfo> gamepadInfos;
  88. HIDManager* gamepadHIDManager;
  89. };
  90. }