diff --git a/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp b/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp index 10be6d8..bab0f99 100644 --- a/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp +++ b/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp @@ -22,6 +22,8 @@ #include "Common/StringUtil.h" #include "Common/Thread.h" #include "InputCommon/ControllerInterface/ControllerInterface.h" +#include "VideoCommon/Present.h" +#include "VideoCommon/FramebufferManager.h" namespace ciface::evdev { @@ -101,15 +101,7 @@ protected: { if (const char* code_name = libevdev_event_code_get_name(EV_KEY, m_code)) { - const auto name = StripWhitespace(code_name); - - for (auto remove_prefix : {"BTN_", "KEY_"}) - { - if (name.starts_with(remove_prefix)) - return std::string(name.substr(std::strlen(remove_prefix))); - } - - return std::string(name); + return std::string(code_name); } else { @@ -148,9 +143,30 @@ public: ControlState GetState() const final override { int value = 0; + float ratio = 1.0; libevdev_fetch_event_value(m_dev, EV_ABS, m_code, &value); - return (value - m_base) / m_range; + // margins + if(g_presenter != NULL) { + if( ((float) g_framebuffer_manager->GetEFBWidth()) / ((float) g_framebuffer_manager->GetEFBHeight()) > ((float) g_presenter->GetTargetRectangle().GetWidth()) / ((float) g_presenter->GetTargetRectangle().GetHeight())) { + if(m_code == ABS_Y) { + int sw = g_presenter->GetTargetRectangle().GetWidth(); + int sh = g_presenter->GetTargetRectangle().GetHeight(); + int tw = g_presenter->GetBackbufferWidth(); + int th = g_presenter->GetBackbufferHeight(); + ratio = ((float)sw) / ((float)sh) / ((float)tw) * ((float)th); + } + } else { + if(m_code == ABS_X) { + int sw = g_presenter->GetTargetRectangle().GetWidth(); + int sh = g_presenter->GetTargetRectangle().GetHeight(); + int tw = g_presenter->GetBackbufferWidth(); + int th = g_presenter->GetBackbufferHeight(); + ratio = ((float)sh) / ((float)sw) / ((float)th) * ((float)tw); + } + } + } + return (value - m_base) * ratio / m_range; } protected: @@ -552,7 +568,6 @@ bool evdevDevice::AddNode(std::string devnode, int fd, libevdev* dev) m_name = potential_new_name; const bool is_motion_device = libevdev_has_property(dev, INPUT_PROP_ACCELEROMETER); - const bool is_pointing_device = libevdev_has_property(dev, INPUT_PROP_BUTTONPAD); // If a device has BTN_JOYSTICK it probably uses event codes counting up from 0x120 // which have very useless and wrong names. @@ -565,21 +580,7 @@ bool evdevDevice::AddNode(std::string devnode, int fd, libevdev* dev) { if (libevdev_has_event_code(dev, EV_KEY, key)) { - if (is_pointing_device || is_motion_device) - { - // This node will probably be combined with another with regular buttons. - // We don't want to match "Button 0" names here as it will name clash. - AddInput(new NamedButtonWithNoBackwardsCompat(num_buttons, key, dev)); - } - else if (has_sensible_button_names) - { - AddInput(new NamedButton(num_buttons, key, dev)); - } - else - { - AddInput(new NumberedButton(num_buttons, key, dev)); - } - + AddInput(new NamedButton(num_buttons, key, dev)); ++num_buttons; } } @@ -615,24 +616,6 @@ bool evdevDevice::AddNode(std::string devnode, int fd, libevdev* dev) return true; } - if (is_pointing_device) - { - auto add_cursor_input = [&num_axis, dev, this](int code) { - if (libevdev_has_event_code(dev, EV_ABS, code)) - { - AddInput(new CursorInput(num_axis, code, false, dev)); - AddInput(new CursorInput(num_axis, code, true, dev)); - - ++num_axis; - } - }; - - add_cursor_input(ABS_X); - add_cursor_input(ABS_Y); - - return true; - } - // Axes beyond ABS_MISC have strange behavior (for multi-touch) which we do not handle. const int abs_axis_code_count = ABS_MISC;