Skip to content

Commit

Permalink
Moved game_pad_stick_converter_ to device_grabber_details::entry from…
Browse files Browse the repository at this point in the history
… device_grabber
  • Loading branch information
tekezo committed May 3, 2024
1 parent 441fec4 commit e07a1de
Show file tree
Hide file tree
Showing 3 changed files with 248 additions and 310 deletions.
35 changes: 2 additions & 33 deletions src/core/grabber/include/grabber/device_grabber.hpp
Expand Up @@ -6,7 +6,6 @@
#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"
Expand Down Expand Up @@ -50,8 +49,6 @@ class device_grabber final : public pqrs::dispatcher::extra::dispatcher_client {
notification_message_manager_ = std::make_shared<notification_message_manager>(
constants::get_notification_message_file_path());

game_pad_stick_converter_ = std::make_shared<device_grabber_details::game_pad_stick_converter>(core_configuration_);

simple_modifications_manipulator_manager_ = std::make_shared<device_grabber_details::simple_modifications_manipulator_manager>();
complex_modifications_manipulator_manager_ = std::make_shared<manipulator::manipulator_manager>();
fn_function_keys_manipulator_manager_ = std::make_shared<device_grabber_details::fn_function_keys_manipulator_manager>();
Expand Down Expand Up @@ -226,17 +223,8 @@ class device_grabber final : public pqrs::dispatcher::extra::dispatcher_client {
core_configuration_);
entries_[device_id] = entry;

entry->hid_queue_values_arrived.connect([this](auto&& entry, auto&& event_queue, auto&& hid_values) {
entry->hid_queue_values_arrived.connect([this](auto&& entry, auto&& event_queue) {
values_arrived(entry, event_queue);

//
// game pad stick to pointing motion
//

if (entry.seized()) {
game_pad_stick_converter_->convert(entry.get_device_properties(),
hid_values);
}
});

entry->get_hid_queue_value_monitor()->started.connect([this, device_id] {
Expand Down Expand Up @@ -277,8 +265,6 @@ class device_grabber final : public pqrs::dispatcher::extra::dispatcher_client {
}
});

game_pad_stick_converter_->register_device(entry->get_device_properties());

// ----------------------------------------

output_devices_json();
Expand Down Expand Up @@ -322,8 +308,6 @@ class device_grabber final : public pqrs::dispatcher::extra::dispatcher_client {
// Unregister device
//

game_pad_stick_converter_->unregister_device(device_id);

if (notification_message_manager_) {
notification_message_manager_->async_erase_device(device_id);
}
Expand Down Expand Up @@ -409,16 +393,6 @@ class device_grabber final : public pqrs::dispatcher::extra::dispatcher_client {
});

power_management_monitor_->async_start();

//
// game_pad_stick_converter_
//

game_pad_stick_converter_->pointing_motion_arrived.connect([this](auto&& entry) {
merged_input_event_queue_->push_back_entry(entry);

krbn_notification_center::get_instance().enqueue_input_event_arrived(*this);
});
}

virtual ~device_grabber(void) {
Expand All @@ -439,8 +413,6 @@ 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();
Expand Down Expand Up @@ -480,10 +452,9 @@ class device_grabber final : public pqrs::dispatcher::extra::dispatcher_client {
core_configuration_ = core_configuration;

for (auto&& e : entries_) {
e.second->set_core_configuration(core_configuration);
e.second->set_weak_core_configuration(core_configuration);
}

game_pad_stick_converter_->set_core_configuration(core_configuration);
manipulator_managers_connector_.set_manipulator_environment_core_configuration(core_configuration);

logger_unique_filter_.reset();
Expand Down Expand Up @@ -1030,8 +1001,6 @@ class device_grabber final : public pqrs::dispatcher::extra::dispatcher_client {

std::shared_ptr<event_queue::queue> merged_input_event_queue_;

std::shared_ptr<device_grabber_details::game_pad_stick_converter> game_pad_stick_converter_;

std::shared_ptr<device_grabber_details::simple_modifications_manipulator_manager> simple_modifications_manipulator_manager_;
std::shared_ptr<event_queue::queue> simple_modifications_applied_event_queue_;

Expand Down
54 changes: 35 additions & 19 deletions src/core/grabber/include/grabber/device_grabber_details/entry.hpp
Expand Up @@ -4,6 +4,7 @@
#include "device_properties.hpp"
#include "device_utility.hpp"
#include "event_queue.hpp"
#include "game_pad_stick_converter.hpp"
#include "hid_keyboard_caps_lock_led_state_manager.hpp"
#include "hid_queue_values_converter.hpp"
#include "iokit_utility.hpp"
Expand All @@ -23,8 +24,7 @@ class entry final : public pqrs::dispatcher::extra::dispatcher_client {
//

nod::signal<void(entry&,
std::shared_ptr<event_queue::queue> event_queue,
const std::vector<pqrs::osx::iokit_hid_value>& hid_values)>
std::shared_ptr<event_queue::queue> event_queue)>
hid_queue_values_arrived;

//
Expand All @@ -35,10 +35,10 @@ class entry final : public pqrs::dispatcher::extra::dispatcher_client {

entry(device_id device_id,
IOHIDDeviceRef device,
std::weak_ptr<const core_configuration::core_configuration> core_configuration) : dispatcher_client(),
device_id_(device_id),
core_configuration_(core_configuration),
disabled_(false) {
std::weak_ptr<const core_configuration::core_configuration> weak_core_configuration) : dispatcher_client(),
device_id_(device_id),
weak_core_configuration_(weak_core_configuration),
disabled_(false) {
device_properties_ = device_properties(device_id,
device);

Expand All @@ -48,6 +48,16 @@ class entry final : public pqrs::dispatcher::extra::dispatcher_client {

caps_lock_led_state_manager_ = std::make_shared<krbn::hid_keyboard_caps_lock_led_state_manager>(device);

game_pad_stick_converter_ = std::make_unique<game_pad_stick_converter>(device_properties_,
weak_core_configuration_);
game_pad_stick_converter_->pointing_motion_arrived.connect([this](auto&& event_queue_entry) {
auto event_queue = std::make_shared<event_queue::queue>();
event_queue->push_back_entry(event_queue_entry);

hid_queue_values_arrived(*this,
event_queue);
});

hid_queue_value_monitor_ = std::make_shared<pqrs::osx::iokit_hid_queue_value_monitor>(pqrs::dispatcher::extra::get_shared_dispatcher(),
pqrs::cf::run_loop_thread::extra::get_shared_run_loop_thread(),
device);
Expand All @@ -74,8 +84,15 @@ class entry final : public pqrs::dispatcher::extra::dispatcher_client {
device_id_,
pressed_keys_manager_);
hid_queue_values_arrived(*this,
event_queue,
hid_values);
event_queue);

//
// game pad stick to pointing motion
//

if (seized()) {
game_pad_stick_converter_->convert(hid_values);
}
});

device_name_ = iokit_utility::make_device_name_for_log(device_id,
Expand All @@ -86,6 +103,7 @@ class entry final : public pqrs::dispatcher::extra::dispatcher_client {
~entry(void) {
detach_from_dispatcher([this] {
hid_queue_value_monitor_ = nullptr;
game_pad_stick_converter_ = nullptr;
caps_lock_led_state_manager_ = nullptr;
});
}
Expand All @@ -94,14 +112,11 @@ class entry final : public pqrs::dispatcher::extra::dispatcher_client {
return device_id_;
}

void set_core_configuration(std::weak_ptr<const core_configuration::core_configuration> core_configuration) {
core_configuration_ = core_configuration;

//
// Update caps_lock_led_state_manager state
//
void set_weak_core_configuration(std::weak_ptr<const core_configuration::core_configuration> weak_core_configuration) {
weak_core_configuration_ = weak_core_configuration;

control_caps_lock_led_state_manager();
game_pad_stick_converter_->set_weak_core_configuration(weak_core_configuration);
}

const device_properties& get_device_properties(void) const {
Expand Down Expand Up @@ -155,7 +170,7 @@ class entry final : public pqrs::dispatcher::extra::dispatcher_client {
return false;
}

if (auto c = core_configuration_.lock()) {
if (auto c = weak_core_configuration_.lock()) {
return c->get_selected_profile().get_device_disable_built_in_keyboard_if_exists(
device_properties_.get_device_identifiers());
}
Expand All @@ -164,7 +179,7 @@ class entry final : public pqrs::dispatcher::extra::dispatcher_client {
}

bool determine_is_built_in_keyboard(void) const {
if (auto c = core_configuration_.lock()) {
if (auto c = weak_core_configuration_.lock()) {
return device_utility::determine_is_built_in_keyboard(*c, device_properties_);
}

Expand Down Expand Up @@ -240,7 +255,7 @@ class entry final : public pqrs::dispatcher::extra::dispatcher_client {
return true;
}

if (auto c = core_configuration_.lock()) {
if (auto c = weak_core_configuration_.lock()) {
return !(c->get_selected_profile().get_device_ignore(device_properties_.get_device_identifiers()));
}

Expand All @@ -254,7 +269,7 @@ class entry final : public pqrs::dispatcher::extra::dispatcher_client {
}

if (caps_lock_led_state_manager_) {
if (auto c = core_configuration_.lock()) {
if (auto c = weak_core_configuration_.lock()) {
if (c->get_selected_profile().get_device_manipulate_caps_lock_led(device_properties_.get_device_identifiers())) {
if (seized()) {
caps_lock_led_state_manager_->async_start();
Expand All @@ -268,12 +283,13 @@ class entry final : public pqrs::dispatcher::extra::dispatcher_client {
}

device_id device_id_;
std::weak_ptr<const core_configuration::core_configuration> core_configuration_;
std::weak_ptr<const core_configuration::core_configuration> weak_core_configuration_;
device_properties device_properties_;
std::shared_ptr<probable_stuck_events_manager> probable_stuck_events_manager_;
std::shared_ptr<pressed_keys_manager> pressed_keys_manager_;
std::shared_ptr<hid_keyboard_caps_lock_led_state_manager> caps_lock_led_state_manager_;
std::shared_ptr<pqrs::osx::iokit_hid_queue_value_monitor> hid_queue_value_monitor_;
std::unique_ptr<game_pad_stick_converter> game_pad_stick_converter_;
hid_queue_values_converter hid_queue_values_converter_;
std::string device_name_;
std::string device_short_name_;
Expand Down

0 comments on commit e07a1de

Please sign in to comment.