From 38b01d176a266ac67e2473f16c645760a991fb66 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Thu, 17 Jan 2013 15:40:44 -0600 Subject: Start to make possible use of "full analog surface". (useful for triggers on some silly physical gamepads) --- .../ControllerInterface/ControllerInterface.cpp | 4 +-- .../Src/ControllerInterface/ControllerInterface.h | 32 +++++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) (limited to 'Source/Core/InputCommon/Src/ControllerInterface') diff --git a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp index 82cfe2469e..e6877f5731 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp @@ -461,7 +461,7 @@ ControllerInterface::Device::Control* ControllerInterface::InputReference::Detec i = device->Inputs().begin(), e = device->Inputs().end(); for (std::vector::iterator state = states.begin(); i != e; ++i) - *state++ = ((*i)->GetState() > INPUT_DETECT_THRESHOLD); + *state++ = ((*i)->GetState() > (1 - INPUT_DETECT_THRESHOLD)); while (time < ms) { @@ -477,7 +477,7 @@ ControllerInterface::Device::Control* ControllerInterface::InputReference::Detec if (false == *state) return *i; } - else + else if ((*i)->GetState() < (1 - INPUT_DETECT_THRESHOLD)) *state = false; } Common::SleepCurrentThread(10); time += 10; diff --git a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.h b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.h index 7c5a236d75..b846bb56e8 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.h +++ b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.h @@ -87,7 +87,7 @@ public: Input* ToInput() { return this; } }; - + // // Output // @@ -122,6 +122,36 @@ public: protected: void AddInput(Input* const i); void AddOutput(Output* const o); + + class FullAnalogSurface : public Input + { + public: + FullAnalogSurface(Input* low, Input* high) + : m_low(*low), m_high(*high) + {} + + ControlState GetState() const + { + return (1 + m_high.GetState() - m_low.GetState()) / 2; + } + + std::string GetName() const + { + return m_low.GetName() + *m_high.GetName().rbegin(); + } + + private: + Input& m_low; + Input& m_high; + }; + + void AddAnalogInputs(Input* low, Input* high) + { + AddInput(low); + AddInput(high); + AddInput(new FullAnalogSurface(low, high)); + AddInput(new FullAnalogSurface(high, low)); + } private: std::vector m_inputs; -- cgit v1.2.3 From f97d2a93c4167a4b6aec0ae69536395380d427e3 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Thu, 17 Jan 2013 15:41:18 -0600 Subject: Add "full analog surface" support in DInput,OSX,SDL backends. (should not be needed for XInput) --- .../InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp | 4 ++-- Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm | 4 ++-- Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'Source/Core/InputCommon/Src/ControllerInterface') diff --git a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp index af6ee7e77c..9bc5364e76 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp +++ b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp @@ -267,8 +267,8 @@ Joystick::Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVI const LONG& ax = (&m_state_in.lX)[offset]; // each axis gets a negative and a positive input instance associated with it - AddInput(new Axis(offset, ax, base, range.lMin-base)); - AddInput(new Axis(offset, ax, base, range.lMax-base)); + AddAnalogInputs(new Axis(offset, ax, base, range.lMin-base), + new Axis(offset, ax, base, range.lMax-base)); } } diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm index 129a5f38e0..60c0cc8c50 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm +++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm @@ -64,8 +64,8 @@ Joystick::Joystick(IOHIDDeviceRef device, std::string name, int index) AddInput(new Hat(e, m_device, Hat::down)); AddInput(new Hat(e, m_device, Hat::left)); } else { - AddInput(new Axis(e, m_device, Axis::negative)); - AddInput(new Axis(e, m_device, Axis::positive)); + AddAnalogInputs(new Axis(e, m_device, Axis::negative), + new Axis(e, m_device, Axis::positive)); } } CFRelease(axes); diff --git a/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp index c7c6898ecd..5473f7bcb3 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp @@ -86,8 +86,8 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsi for (u8 i = 0; i != SDL_JoystickNumAxes(m_joystick); ++i) { // each axis gets a negative and a positive input instance associated with it - AddInput(new Axis(i, m_joystick, -32768)); - AddInput(new Axis(i, m_joystick, 32767)); + AddAnalogInputs(new Axis(i, m_joystick, -32768), + new Axis(i, m_joystick, 32767)); } #ifdef USE_SDL_HAPTIC -- cgit v1.2.3 From 2f28d938cf640390cd8979c6104f3dbe8795e1e6 Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Thu, 17 Jan 2013 23:32:07 -0800 Subject: Add support for the mouse cursor and mouse clicking events on OS X. --- .../ControllerInterface/ControllerInterface.cpp | 2 +- .../InputCommon/Src/ControllerInterface/OSX/OSX.h | 2 +- .../InputCommon/Src/ControllerInterface/OSX/OSX.mm | 8 ++- .../Src/ControllerInterface/OSX/OSXKeyboard.h | 32 ++++++++++- .../Src/ControllerInterface/OSX/OSXKeyboard.mm | 67 +++++++++++++++++++++- 5 files changed, 105 insertions(+), 6 deletions(-) (limited to 'Source/Core/InputCommon/Src/ControllerInterface') diff --git a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp index e6877f5731..8e96231674 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp @@ -45,7 +45,7 @@ void ControllerInterface::Initialize() ciface::Xlib::Init(m_devices, m_hwnd); #endif #ifdef CIFACE_USE_OSX - ciface::OSX::Init(m_devices); + ciface::OSX::Init(m_devices, m_hwnd); #endif #ifdef CIFACE_USE_SDL ciface::SDL::Init(m_devices); diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.h b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.h index 0458d87e1d..225906c35d 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.h +++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.h @@ -7,7 +7,7 @@ namespace ciface namespace OSX { -void Init(std::vector& devices); +void Init(std::vector& devices, void *window); void DeInit(); void DeviceElementDebugPrint(const void *, void *); diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.mm b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.mm index bf4f49bac6..aef8f283c1 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.mm +++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.mm @@ -1,5 +1,6 @@ #include #include +#include #include "../ControllerInterface.h" #include "OSX.h" @@ -131,6 +132,7 @@ void DeviceDebugPrint(IOHIDDeviceRef device) #endif } +static void *g_window; static void DeviceMatching_callback(void* inContext, IOReturn inResult, @@ -150,7 +152,7 @@ static void DeviceMatching_callback(void* inContext, if (IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard)) devices->push_back(new Keyboard(inIOHIDDeviceRef, - name, kbd_name_counts[name]++)); + name, kbd_name_counts[name]++, g_window)); #if 0 else if (IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse)) @@ -162,13 +164,15 @@ static void DeviceMatching_callback(void* inContext, name, joy_name_counts[name]++)); } -void Init(std::vector& devices) +void Init(std::vector& devices, void *window) { HIDManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); if (!HIDManager) NSLog(@"Failed to create HID Manager reference"); + g_window = window; + IOHIDManagerSetDeviceMatching(HIDManager, NULL); // Callbacks for acquisition or loss of a matching device diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.h b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.h index 1a7fcd045b..d59651c98a 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.h +++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.h @@ -21,21 +21,51 @@ private: const IOHIDDeviceRef m_device; std::string m_name; }; + class Cursor : public Input + { + public: + std::string GetName() const; + bool IsDetectable() { return false; } + Cursor(u8 index, const float& axis, const bool positive) : m_index(index), m_axis(axis), m_positive(positive) {} + ControlState GetState() const; + private: + const float& m_axis; + const u8 m_index; + const bool m_positive; + }; + class Button : public Input + { + public: + std::string GetName() const; + Button(u8 index, const unsigned char& button) : m_index(index), m_button(button) {} + ControlState GetState() const; + private: + const unsigned char& m_button; + const u8 m_index; + }; public: bool UpdateInput(); bool UpdateOutput(); - Keyboard(IOHIDDeviceRef device, std::string name, int index); + Keyboard(IOHIDDeviceRef device, std::string name, int index, void *window); std::string GetName() const; std::string GetSource() const; int GetId() const; private: + struct + { + float x, y; + } m_cursor; + const IOHIDDeviceRef m_device; const std::string m_device_name; int m_index; + void *m_window; + uint32_t m_windowid; + unsigned char m_mousebuttons[3]; }; } diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.mm b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.mm index 7543d507dd..56e360019a 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.mm +++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.mm @@ -1,5 +1,7 @@ #include #include +#include +#include // wxWidgets #include "../ControllerInterface.h" #include "OSXKeyboard.h" @@ -9,10 +11,11 @@ namespace ciface namespace OSX { -Keyboard::Keyboard(IOHIDDeviceRef device, std::string name, int index) +Keyboard::Keyboard(IOHIDDeviceRef device, std::string name, int index, void *window) : m_device(device) , m_device_name(name) , m_index(index) + , m_window(window) { // This class should only recieve Keyboard or Keypad devices // Now, filter on just the buttons we can handle sanely @@ -39,10 +42,48 @@ Keyboard::Keyboard(IOHIDDeviceRef device, std::string name, int index) } CFRelease(elements); } + + m_windowid = [[(NSView *)(((wxWindow *)window)->GetHandle()) window] windowNumber]; + + // cursor, with a hax for-loop + for (unsigned int i=0; i<4; ++i) + AddInput(new Cursor(!!(i&2), (&m_cursor.x)[i/2], !!(i&1))); + + for (u8 i = 0; i < sizeof(m_mousebuttons) / sizeof(m_mousebuttons[0]); ++i) + AddInput(new Button(i, m_mousebuttons[i])); } bool Keyboard::UpdateInput() { + CGRect bounds = CGRectZero; + uint32_t windowid[1] = { m_windowid }; + CFArrayRef windowArray = CFArrayCreate(NULL, (const void **) windowid, 1, NULL); + CFArrayRef windowDescriptions = CGWindowListCreateDescriptionFromArray(windowArray); + CFDictionaryRef windowDescription = (CFDictionaryRef) CFArrayGetValueAtIndex((CFArrayRef) windowDescriptions, 0); + + if (CFDictionaryContainsKey(windowDescription, kCGWindowBounds)) + { + CFDictionaryRef boundsDictionary = (CFDictionaryRef) CFDictionaryGetValue(windowDescription, kCGWindowBounds); + + if (boundsDictionary != NULL) + CGRectMakeWithDictionaryRepresentation(boundsDictionary, &bounds); + } + + CFRelease(windowArray); + + CGEventRef event = CGEventCreate(nil); + CGPoint loc = CGEventGetLocation(event); + CFRelease(event); + + loc.x -= bounds.origin.x; + loc.y -= bounds.origin.y; + m_cursor.x = loc.x / bounds.size.width * 2 - 1.0; + m_cursor.y = loc.y / bounds.size.height * 2 - 1.0; + + m_mousebuttons[0] = CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonLeft); + m_mousebuttons[1] = CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonRight); + m_mousebuttons[2] = CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonCenter); + return true; } @@ -201,10 +242,34 @@ ControlState Keyboard::Key::GetState() const return 0; } +ControlState Keyboard::Cursor::GetState() const +{ + return std::max(0.0f, ControlState(m_axis) / (m_positive ? 1.0f : -1.0f)); +} + +ControlState Keyboard::Button::GetState() const +{ + return (m_button != 0); +} + +std::string Keyboard::Cursor::GetName() const +{ + static char tmpstr[] = "Cursor .."; + tmpstr[7] = (char)('X' + m_index); + tmpstr[8] = (m_positive ? '+' : '-'); + return tmpstr; +} + +std::string Keyboard::Button::GetName() const +{ + return std::string("Click ") + char('0' + m_index); +} + std::string Keyboard::Key::GetName() const { return m_name; } + } } -- cgit v1.2.3 From f506783c37b2bd7b50bf86015a030d7e0a74ff29 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Tue, 5 Feb 2013 13:51:08 -0600 Subject: Number "unknown" axes in OSX rather than call them all "unk". --- .../InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'Source/Core/InputCommon/Src/ControllerInterface') diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm index 60c0cc8c50..0d89c2e393 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm +++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm @@ -121,7 +121,9 @@ Joystick::Axis::Axis(IOHIDElementRef element, IOHIDDeviceRef device, direction d // Need to parse the element a bit first std::string description("unk"); - switch (IOHIDElementGetUsage(m_element)) { + int const usage = IOHIDElementGetUsage(m_element); + switch (usage) + { case kHIDUsage_GD_X: description = "X"; break; @@ -146,6 +148,13 @@ Joystick::Axis::Axis(IOHIDElementRef element, IOHIDDeviceRef device, direction d case kHIDUsage_Csmr_ACPan: description = "Pan"; break; + default: + { + std::ostringstream s; + s << usage; + description = s.str(); + break; + } } m_name = std::string("Axis ") + description; -- cgit v1.2.3 From 708fed92c851ada9dbe191b20eafa14c378ca664 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Tue, 5 Feb 2013 15:32:13 -0600 Subject: Clean up SDL includes a bit. Maybe fix an SDL2 problem. --- Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp | 8 +++++++- Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.h | 12 ++---------- 2 files changed, 9 insertions(+), 11 deletions(-) (limited to 'Source/Core/InputCommon/Src/ControllerInterface') diff --git a/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp index 5473f7bcb3..b521032e9c 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp @@ -325,7 +325,13 @@ bool Joystick::UpdateOutput() std::string Joystick::GetName() const { - return StripSpaces(SDL_JoystickName(m_sdl_index)); + return StripSpaces( +#if SDL_VERSION_ATLEAST(2, 0, 0) + SDL_JoystickNameForIndex(m_sdl_index) +#else + SDL_JoystickName(m_sdl_index) +#endif + ); } std::string Joystick::GetSource() const diff --git a/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.h b/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.h index 139e9f232d..fa770c403d 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.h +++ b/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.h @@ -5,22 +5,14 @@ #include -#ifdef _WIN32 - #include -#else - #include -#endif +#include #if SDL_VERSION_ATLEAST(1, 3, 0) #define USE_SDL_HAPTIC #endif #ifdef USE_SDL_HAPTIC - #ifdef _WIN32 - #include - #else - #include - #endif + #include #define SDL_INIT_FLAGS SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC #else #define SDL_INIT_FLAGS SDL_INIT_JOYSTICK -- cgit v1.2.3 From ef9d7fb789ec88b249c33a9119fb40069e68619e Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Tue, 5 Feb 2013 21:07:09 -0600 Subject: Fix compilation with SDL2. (based on a patch from matthewharveys) Fixes issue 5971. --- .../InputCommon/Src/ControllerInterface/SDL/SDL.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'Source/Core/InputCommon/Src/ControllerInterface') diff --git a/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp index b521032e9c..c5ee3af23f 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp @@ -17,6 +17,15 @@ namespace ciface { namespace SDL { + +std::string GetJoystickName(int index) +{ +#if SDL_VERSION_ATLEAST(2, 0, 0) + return SDL_JoystickNameForIndex(index); +#else + return SDL_JoystickName(index); +#endif +} void Init( std::vector& devices ) { @@ -32,7 +41,7 @@ void Init( std::vector& devices ) SDL_Joystick* dev = SDL_JoystickOpen(i); if (dev) { - Joystick* js = new Joystick(dev, i, name_counts[SDL_JoystickName(i)]++); + Joystick* js = new Joystick(dev, i, name_counts[GetJoystickName(i)]++); // only add if it has some inputs/outputs if (js->Inputs().size() || js->Outputs().size()) devices.push_back( js ); @@ -325,13 +334,7 @@ bool Joystick::UpdateOutput() std::string Joystick::GetName() const { - return StripSpaces( -#if SDL_VERSION_ATLEAST(2, 0, 0) - SDL_JoystickNameForIndex(m_sdl_index) -#else - SDL_JoystickName(m_sdl_index) -#endif - ); + return StripSpaces(GetJoystickName(m_sdl_index)); } std::string Joystick::GetSource() const -- cgit v1.2.3