diff --git a/src/share/event_queue/utility.hpp b/src/share/event_queue/utility.hpp index 7585c6283..71742e352 100644 --- a/src/share/event_queue/utility.hpp +++ b/src/share/event_queue/utility.hpp @@ -94,40 +94,6 @@ static inline std::shared_ptr make_queue(const device_properties& device_ pointing_motion_time_stamp = v.get_time_stamp(); pointing_motion_horizontal_wheel = static_cast(v.get_integer_value()); - } else if (v.conforms_to(pqrs::hid::usage_page::generic_desktop, - pqrs::hid::usage::generic_desktop::hat_switch)) { - // Convert hat switch to dpad. - auto pairs = hat_switch_converter::get_global_hat_switch_converter()->to_dpad_events(device_properties.get_device_id(), - v.get_integer_value()); - for (const auto& pair : pairs) { - event_queue::event event(pair.first); - result->emplace_back_entry(device_properties.get_device_id(), - event_time_stamp(v.get_time_stamp()), - event, - pair.second, - event, - event_origin, - state::original); - } - - } else if (v.conforms_to(pqrs::hid::usage_page::generic_desktop, - pqrs::hid::usage::generic_desktop::rz)) { - // Convert vertical wheel - if (pointing_motion_vertical_wheel) { - emplace_back_pointing_motion_event(); - } - pointing_motion_time_stamp = v.get_time_stamp(); - pointing_motion_vertical_wheel = static_cast(v.get_integer_value()); - - } else if (v.conforms_to(pqrs::hid::usage_page::generic_desktop, - pqrs::hid::usage::generic_desktop::z)) { - // Convert horizontal wheel - if (pointing_motion_horizontal_wheel) { - emplace_back_pointing_motion_event(); - } - pointing_motion_time_stamp = v.get_time_stamp(); - pointing_motion_horizontal_wheel = -static_cast(v.get_integer_value()); - } else if (v.conforms_to(pqrs::hid::usage_page::leds, pqrs::hid::usage::led::caps_lock)) { auto event = event_queue::event::make_caps_lock_state_changed_event(v.get_integer_value()); @@ -138,6 +104,44 @@ static inline std::shared_ptr make_queue(const device_properties& device_ event, event_origin, state::virtual_event); + + } else if (auto is_game_pad = device_properties.get_is_game_pad()) { + if (*is_game_pad) { + if (v.conforms_to(pqrs::hid::usage_page::generic_desktop, + pqrs::hid::usage::generic_desktop::hat_switch)) { + // Convert hat switch to dpad. + auto pairs = hat_switch_converter::get_global_hat_switch_converter()->to_dpad_events(device_properties.get_device_id(), + v.get_integer_value()); + for (const auto& pair : pairs) { + event_queue::event event(pair.first); + result->emplace_back_entry(device_properties.get_device_id(), + event_time_stamp(v.get_time_stamp()), + event, + pair.second, + event, + event_origin, + state::original); + } + + } else if (v.conforms_to(pqrs::hid::usage_page::generic_desktop, + pqrs::hid::usage::generic_desktop::rz)) { + // Convert vertical wheel + if (pointing_motion_vertical_wheel) { + emplace_back_pointing_motion_event(); + } + pointing_motion_time_stamp = v.get_time_stamp(); + pointing_motion_vertical_wheel = static_cast(v.get_integer_value()); + + } else if (v.conforms_to(pqrs::hid::usage_page::generic_desktop, + pqrs::hid::usage::generic_desktop::z)) { + // Convert horizontal wheel + if (pointing_motion_horizontal_wheel) { + emplace_back_pointing_motion_event(); + } + pointing_motion_time_stamp = v.get_time_stamp(); + pointing_motion_horizontal_wheel = -static_cast(v.get_integer_value()); + } + } } } } diff --git a/tests/src/event_queue/src/event_queue_utility_test.hpp b/tests/src/event_queue/src/event_queue_utility_test.hpp index 894c92182..0f20ac28a 100644 --- a/tests/src/event_queue/src/event_queue_utility_test.hpp +++ b/tests/src/event_queue/src/event_queue_utility_test.hpp @@ -143,6 +143,112 @@ void run_event_queue_utility_test(void) { } }; + "utility::make_queue not game_pad"_test = [] { + std::vector hid_values; + + hid_values.emplace_back(pqrs::osx::iokit_hid_value(krbn::absolute_time_point(1000), + 1, + pqrs::hid::usage_page::generic_desktop, + pqrs::hid::usage::generic_desktop::hat_switch)); + hid_values.emplace_back(pqrs::osx::iokit_hid_value(krbn::absolute_time_point(1001), + -1, + pqrs::hid::usage_page::generic_desktop, + pqrs::hid::usage::generic_desktop::hat_switch)); + + hid_values.emplace_back(pqrs::osx::iokit_hid_value(krbn::absolute_time_point(2000), + 10, + pqrs::hid::usage_page::generic_desktop, + pqrs::hid::usage::generic_desktop::z)); + + hid_values.emplace_back(pqrs::osx::iokit_hid_value(krbn::absolute_time_point(3000), + 10, + pqrs::hid::usage_page::generic_desktop, + pqrs::hid::usage::generic_desktop::rz)); + + auto device_properties = krbn::device_properties(krbn::device_id(1), + nullptr); + auto queue = krbn::event_queue::utility::make_queue(device_properties, + hid_values, + krbn::event_origin::grabbed_device); + expect(0_ul == queue->get_entries().size()); + }; + + "utility::make_queue game_pad"_test = [] { + std::vector hid_values; + + hid_values.emplace_back(pqrs::osx::iokit_hid_value(krbn::absolute_time_point(1000), + 1, + pqrs::hid::usage_page::generic_desktop, + pqrs::hid::usage::generic_desktop::hat_switch)); + hid_values.emplace_back(pqrs::osx::iokit_hid_value(krbn::absolute_time_point(1001), + -1, + pqrs::hid::usage_page::generic_desktop, + pqrs::hid::usage::generic_desktop::hat_switch)); + + hid_values.emplace_back(pqrs::osx::iokit_hid_value(krbn::absolute_time_point(2000), + 10, + pqrs::hid::usage_page::generic_desktop, + pqrs::hid::usage::generic_desktop::z)); + + hid_values.emplace_back(pqrs::osx::iokit_hid_value(krbn::absolute_time_point(3000), + 20, + pqrs::hid::usage_page::generic_desktop, + pqrs::hid::usage::generic_desktop::rz)); + + auto device_properties = krbn::device_properties(krbn::device_id(1), + nullptr); + device_properties.set_is_game_pad(true); + + auto queue = krbn::event_queue::utility::make_queue(device_properties, + hid_values, + krbn::event_origin::grabbed_device); + expect(5_ul == queue->get_entries().size()); + + { + auto& e = queue->get_entries()[0]; + expect(e.get_device_id() == krbn::device_id(1)); + expect(e.get_event_time_stamp().get_time_stamp() == krbn::absolute_time_point(1000)); + expect(e.get_event().get_if()->get_usage_pair() == + pqrs::hid::usage_pair(pqrs::hid::usage_page::generic_desktop, + pqrs::hid::usage::generic_desktop::dpad_up)); + expect(e.get_event_type() == krbn::event_type::key_down); + } + { + auto& e = queue->get_entries()[1]; + expect(e.get_device_id() == krbn::device_id(1)); + expect(e.get_event_time_stamp().get_time_stamp() == krbn::absolute_time_point(1000)); + expect(e.get_event().get_if()->get_usage_pair() == + pqrs::hid::usage_pair(pqrs::hid::usage_page::generic_desktop, + pqrs::hid::usage::generic_desktop::dpad_right)); + expect(e.get_event_type() == krbn::event_type::key_down); + } + { + auto& e = queue->get_entries()[2]; + expect(e.get_device_id() == krbn::device_id(1)); + expect(e.get_event_time_stamp().get_time_stamp() == krbn::absolute_time_point(1001)); + expect(e.get_event().get_if()->get_usage_pair() == + pqrs::hid::usage_pair(pqrs::hid::usage_page::generic_desktop, + pqrs::hid::usage::generic_desktop::dpad_up)); + expect(e.get_event_type() == krbn::event_type::key_up); + } + { + auto& e = queue->get_entries()[3]; + expect(e.get_device_id() == krbn::device_id(1)); + expect(e.get_event_time_stamp().get_time_stamp() == krbn::absolute_time_point(1001)); + expect(e.get_event().get_if()->get_usage_pair() == + pqrs::hid::usage_pair(pqrs::hid::usage_page::generic_desktop, + pqrs::hid::usage::generic_desktop::dpad_right)); + expect(e.get_event_type() == krbn::event_type::key_up); + } + { + auto& e = queue->get_entries()[4]; + expect(e.get_device_id() == krbn::device_id(1)); + expect(e.get_event_time_stamp().get_time_stamp() == krbn::absolute_time_point(3000)); + expect(e.get_event().get_pointing_motion() == krbn::pointing_motion(0, 0, 20, -10)); + expect(e.get_event_type() == krbn::event_type::single); + } + }; + "utility::insert_device_keys_and_pointing_buttons_are_released_event"_test = [] { krbn::event_queue::event a_event( krbn::momentary_switch_event(pqrs::hid::usage_page::keyboard_or_keypad,