From c2d142e11249e2c9a5d416cd324df936b4fe0377 Mon Sep 17 00:00:00 2001 From: Takayama Fumihiko Date: Sat, 23 Sep 2023 09:56:02 +0900 Subject: [PATCH] Add game_pad_stick_converter --- .../include/grabber/device_grabber.hpp | 7 +++ .../game_pad_stick_converter.hpp | 43 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/core/grabber/include/grabber/device_grabber_details/game_pad_stick_converter.hpp diff --git a/src/core/grabber/include/grabber/device_grabber.hpp b/src/core/grabber/include/grabber/device_grabber.hpp index e8d5e4dd9..0c24d0359 100644 --- a/src/core/grabber/include/grabber/device_grabber.hpp +++ b/src/core/grabber/include/grabber/device_grabber.hpp @@ -6,6 +6,7 @@ #include "constants.hpp" #include "device_grabber_details/entry.hpp" #include "device_grabber_details/fn_function_keys_manipulator_manager.hpp" +#include "device_grabber_details/game_pad_stick_converter.hpp" #include "device_grabber_details/simple_modifications_manipulator_manager.hpp" #include "event_tap_utility.hpp" #include "filesystem_utility.hpp" @@ -51,6 +52,8 @@ class device_grabber final : public pqrs::dispatcher::extra::dispatcher_client { notification_message_manager_ = std::make_shared( constants::get_notification_message_file_path()); + game_pad_stick_converter_ = std::make_shared(); + simple_modifications_manipulator_manager_ = std::make_shared(); complex_modifications_manipulator_manager_ = std::make_shared(); fn_function_keys_manipulator_manager_ = std::make_shared(); @@ -445,6 +448,8 @@ class device_grabber final : public pqrs::dispatcher::extra::dispatcher_client { post_event_to_virtual_devices_manipulator_manager_ = nullptr; virtual_hid_device_service_client_ = nullptr; + game_pad_stick_converter_ = nullptr; + notification_message_manager_ = nullptr; hat_switch_converter::get_global_hat_switch_converter()->clear(); @@ -1111,6 +1116,8 @@ class device_grabber final : public pqrs::dispatcher::extra::dispatcher_client { std::shared_ptr merged_input_event_queue_; + std::shared_ptr game_pad_stick_converter_; + std::shared_ptr simple_modifications_manipulator_manager_; std::shared_ptr simple_modifications_applied_event_queue_; diff --git a/src/core/grabber/include/grabber/device_grabber_details/game_pad_stick_converter.hpp b/src/core/grabber/include/grabber/device_grabber_details/game_pad_stick_converter.hpp new file mode 100644 index 000000000..187b93275 --- /dev/null +++ b/src/core/grabber/include/grabber/device_grabber_details/game_pad_stick_converter.hpp @@ -0,0 +1,43 @@ +#pragma once + +#include "types/device_id.hpp" +#include +#include +#include + +namespace krbn { +namespace grabber { +namespace device_grabber_details { +// +// game_pad_stick_converter takes value_arrived data as input and outputs poinitng motion. +// This conversion is necessary because it is difficult to use game pad sticks as natural pointing devices due to the following characteristics. +// +// - The game pad's stick only sends events when the value changes. +// We want the pointer to move while the stick is tilted, even if the value does not change. +// So we need to send events periodically with a timer. +// - The game pad's stick may send events slightly in the opposite direction when it is released and returns to neutral. +// This event should be properly ignored. +// - The game pad's stick may have a value in the neutral state. The deadzone must be properly set and ignored neutral values. +// +class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatcher_client { +public: + game_pad_stick_converter(void) + : dispatcher_client(), + timer_(*this) { + } + + ~game_pad_stick_converter(void) { + detach_from_dispatcher([this] { + timer_.stop(); + }); + } + + void convert(std::shared_ptr event_queue) { + } + +private: + pqrs::dispatcher::extra::timer timer_; +}; +} // namespace device_grabber_details +} // namespace grabber +} // namespace krbn