From f79659bb4050373d07dc7e5f8b9bc4d63325bf4e Mon Sep 17 00:00:00 2001 From: Takayama Fumihiko Date: Mon, 30 Dec 2024 17:55:11 +0900 Subject: [PATCH 01/11] Add pointing_motion_xy_multiplier, pointing_motion_wheels_multiplier --- .../include/grabber/device_grabber.hpp | 4 +- .../grabber/device_grabber_details/entry.hpp | 65 ++++++------- .../game_pad_stick_converter.hpp | 70 +++++++------- .../details/profile/device.hpp | 28 ++++++ src/share/event_queue/utility.hpp | 36 ++++++- .../json/errors/profile_device_errors.jsonc | 20 ++++ .../core_configuration/src/device_test.hpp | 16 ++++ .../src/event_queue_utility_test.hpp | 96 ++++++++++++++++++- 8 files changed, 251 insertions(+), 84 deletions(-) diff --git a/src/core/grabber/include/grabber/device_grabber.hpp b/src/core/grabber/include/grabber/device_grabber.hpp index 641030793..1254fd206 100644 --- a/src/core/grabber/include/grabber/device_grabber.hpp +++ b/src/core/grabber/include/grabber/device_grabber.hpp @@ -224,7 +224,7 @@ class device_grabber final : public pqrs::dispatcher::extra::dispatcher_client { auto entry = std::make_shared(device_id, *device_ptr, - memory_utility::make_weak(core_configuration_)); + core_configuration_); entries_[device_id] = entry; entry->hid_queue_values_arrived.connect([this](auto&& entry, auto&& event_queue) { @@ -455,7 +455,7 @@ class device_grabber final : public pqrs::dispatcher::extra::dispatcher_client { core_configuration_ = core_configuration; for (auto&& e : entries_) { - e.second->set_weak_core_configuration(core_configuration); + e.second->set_core_configuration(core_configuration); } manipulator_managers_connector_.set_manipulator_environment_core_configuration(core_configuration); diff --git a/src/core/grabber/include/grabber/device_grabber_details/entry.hpp b/src/core/grabber/include/grabber/device_grabber_details/entry.hpp index 747047431..637bcc37e 100644 --- a/src/core/grabber/include/grabber/device_grabber_details/entry.hpp +++ b/src/core/grabber/include/grabber/device_grabber_details/entry.hpp @@ -35,12 +35,13 @@ class entry final : public pqrs::dispatcher::extra::dispatcher_client { entry(device_id device_id, IOHIDDeviceRef device, - std::weak_ptr weak_core_configuration) : dispatcher_client(), - device_id_(device_id), - weak_core_configuration_(weak_core_configuration), - device_properties_(device_properties::make_device_properties(device_id, - device)), - disabled_(false) { + gsl::not_null> core_configuration) + : dispatcher_client(), + device_id_(device_id), + core_configuration_(core_configuration), + device_properties_(device_properties::make_device_properties(device_id, + device)), + disabled_(false) { probable_stuck_events_manager_ = std::make_shared(); pressed_keys_manager_ = std::make_shared(); @@ -61,7 +62,7 @@ class entry final : public pqrs::dispatcher::extra::dispatcher_client { if (device_properties_->get_device_identifiers().get_is_game_pad()) { game_pad_stick_converter_ = std::make_unique(device_properties_, - weak_core_configuration_); + core_configuration_); game_pad_stick_converter_->pointing_motion_arrived.connect([this](auto&& event_queue_entry) { auto event_queue = std::make_shared(); event_queue->push_back_entry(event_queue_entry); @@ -78,10 +79,16 @@ class entry final : public pqrs::dispatcher::extra::dispatcher_client { game_pad_stick_converter_ = nullptr; }); hid_queue_value_monitor_->values_arrived.connect([this](auto&& values_ptr) { + auto d = core_configuration_->get_selected_profile().get_device(device_properties_->get_device_identifiers()); + auto hid_values = hid_queue_values_converter_.make_hid_values(device_id_, values_ptr); auto event_queue = event_queue::utility::make_queue(device_properties_, - hid_values); + hid_values, + event_queue::utility::make_queue_parameters{ + .pointing_motion_xy_multiplier = d->get_pointing_motion_xy_multiplier(), + .pointing_motion_wheels_multiplier = d->get_pointing_motion_wheels_multiplier(), + }); event_queue = event_queue::utility::insert_device_keys_and_pointing_buttons_are_released_event(event_queue, device_id_, @@ -116,13 +123,13 @@ class entry final : public pqrs::dispatcher::extra::dispatcher_client { } // This method should be called in the shared dispatcher thread. - void set_weak_core_configuration(std::weak_ptr weak_core_configuration) { - weak_core_configuration_ = weak_core_configuration; + void set_core_configuration(gsl::not_null> core_configuration) { + core_configuration_ = core_configuration; control_caps_lock_led_state_manager(); if (game_pad_stick_converter_) { - game_pad_stick_converter_->set_weak_core_configuration(weak_core_configuration); + game_pad_stick_converter_->set_core_configuration(core_configuration); } } @@ -177,20 +184,12 @@ class entry final : public pqrs::dispatcher::extra::dispatcher_client { return false; } - if (auto c = weak_core_configuration_.lock()) { - auto d = c->get_selected_profile().get_device(device_properties_->get_device_identifiers()); - return d->get_disable_built_in_keyboard_if_exists(); - } - - return false; + auto d = core_configuration_->get_selected_profile().get_device(device_properties_->get_device_identifiers()); + return d->get_disable_built_in_keyboard_if_exists(); } bool determine_is_built_in_keyboard(void) const { - if (auto c = weak_core_configuration_.lock()) { - return device_utility::determine_is_built_in_keyboard(*c, *device_properties_); - } - - return false; + return device_utility::determine_is_built_in_keyboard(*core_configuration_, *device_properties_); } void async_start_queue_value_monitor(grabbable_state::state state) { @@ -254,12 +253,8 @@ class entry final : public pqrs::dispatcher::extra::dispatcher_client { return true; } - if (auto c = weak_core_configuration_.lock()) { - auto d = c->get_selected_profile().get_device(device_properties_->get_device_identifiers()); - return !(d->get_ignore()); - } - - return false; + auto d = core_configuration_->get_selected_profile().get_device(device_properties_->get_device_identifiers()); + return !(d->get_ignore()); } private: @@ -269,13 +264,11 @@ class entry final : public pqrs::dispatcher::extra::dispatcher_client { } if (caps_lock_led_state_manager_) { - if (auto c = weak_core_configuration_.lock()) { - auto d = c->get_selected_profile().get_device(device_properties_->get_device_identifiers()); - if (d->get_manipulate_caps_lock_led()) { - if (seized()) { - caps_lock_led_state_manager_->async_start(); - return; - } + auto d = core_configuration_->get_selected_profile().get_device(device_properties_->get_device_identifiers()); + if (d->get_manipulate_caps_lock_led()) { + if (seized()) { + caps_lock_led_state_manager_->async_start(); + return; } } @@ -284,7 +277,7 @@ class entry final : public pqrs::dispatcher::extra::dispatcher_client { } device_id device_id_; - std::weak_ptr weak_core_configuration_; + gsl::not_null> core_configuration_; gsl::not_null> device_properties_; std::shared_ptr probable_stuck_events_manager_; std::shared_ptr pressed_keys_manager_; 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 index 7c9c7aeb7..8165351f4 100644 --- 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 @@ -252,9 +252,10 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche // game_pad_stick_converter(gsl::not_null> device_properties, - std::weak_ptr weak_core_configuration) + gsl::not_null> core_configuration) : dispatcher_client(), device_properties_(device_properties), + core_configuration_(core_configuration), continued_movement_timer_(*this), continued_movement_timer_count_(0), continued_movement_mode_(continued_movement_mode::none), @@ -266,7 +267,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche wheels_delta_magnitude_(0.0), wheels_absolute_magnitude_(0.0), wheels_continued_movement_(false) { - set_weak_core_configuration(weak_core_configuration); + set_core_configuration(core_configuration); xy_.values_updated.connect([this](void) { auto interval = xy_.get_continued_movement_interval_milliseconds(); @@ -321,12 +322,34 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche integer_value); } - void set_weak_core_configuration(std::weak_ptr weak_core_configuration) { - weak_core_configuration_ = weak_core_configuration; + void set_core_configuration(gsl::not_null> core_configuration) { + core_configuration_ = core_configuration; - if (auto c = weak_core_configuration_.lock()) { - update_configurations(*c); - } + // + // Propagate the changes + // + + auto d = core_configuration_->get_selected_profile().get_device(device_properties_->get_device_identifiers()); + + xy_.set_deadzone(d->get_game_pad_xy_stick_deadzone()); + xy_.set_delta_magnitude_detection_threshold(d->get_game_pad_xy_stick_delta_magnitude_detection_threshold()); + xy_.set_continued_movement_absolute_magnitude_threshold(d->get_game_pad_xy_stick_continued_movement_absolute_magnitude_threshold()); + xy_.set_continued_movement_interval_milliseconds(d->get_game_pad_xy_stick_continued_movement_interval_milliseconds()); + + wheels_.set_deadzone(d->get_game_pad_wheels_stick_deadzone()); + wheels_.set_delta_magnitude_detection_threshold(d->get_game_pad_wheels_stick_delta_magnitude_detection_threshold()); + wheels_.set_continued_movement_absolute_magnitude_threshold(d->get_game_pad_wheels_stick_continued_movement_absolute_magnitude_threshold()); + wheels_.set_continued_movement_interval_milliseconds(d->get_game_pad_wheels_stick_continued_movement_interval_milliseconds()); + + x_formula_string_ = d->get_game_pad_stick_x_formula(); + y_formula_string_ = d->get_game_pad_stick_y_formula(); + vertical_wheel_formula_string_ = d->get_game_pad_stick_vertical_wheel_formula(); + horizontal_wheel_formula_string_ = d->get_game_pad_stick_horizontal_wheel_formula(); + + x_formula_ = make_xy_formula_expression(x_formula_string_); + y_formula_ = make_xy_formula_expression(y_formula_string_); + vertical_wheel_formula_ = make_wheels_formula_expression(vertical_wheel_formula_string_); + horizontal_wheel_formula_ = make_wheels_formula_expression(horizontal_wheel_formula_string_); } // This method should be called in the shared dispatcher thread. @@ -338,12 +361,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche } } - auto c = weak_core_configuration_.lock(); - if (!c) { - return; - } - - auto device = c->get_selected_profile().get_device(device_properties_->get_device_identifiers()); + auto device = core_configuration_->get_selected_profile().get_device(device_properties_->get_device_identifiers()); bool swap_sticks = device->get_game_pad_swap_sticks(); for (const auto& v : hid_values) { @@ -406,30 +424,6 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche } private: - void update_configurations(const core_configuration::core_configuration& core_configuration) { - auto d = core_configuration.get_selected_profile().get_device(device_properties_->get_device_identifiers()); - - xy_.set_deadzone(d->get_game_pad_xy_stick_deadzone()); - xy_.set_delta_magnitude_detection_threshold(d->get_game_pad_xy_stick_delta_magnitude_detection_threshold()); - xy_.set_continued_movement_absolute_magnitude_threshold(d->get_game_pad_xy_stick_continued_movement_absolute_magnitude_threshold()); - xy_.set_continued_movement_interval_milliseconds(d->get_game_pad_xy_stick_continued_movement_interval_milliseconds()); - - wheels_.set_deadzone(d->get_game_pad_wheels_stick_deadzone()); - wheels_.set_delta_magnitude_detection_threshold(d->get_game_pad_wheels_stick_delta_magnitude_detection_threshold()); - wheels_.set_continued_movement_absolute_magnitude_threshold(d->get_game_pad_wheels_stick_continued_movement_absolute_magnitude_threshold()); - wheels_.set_continued_movement_interval_milliseconds(d->get_game_pad_wheels_stick_continued_movement_interval_milliseconds()); - - x_formula_string_ = d->get_game_pad_stick_x_formula(); - y_formula_string_ = d->get_game_pad_stick_y_formula(); - vertical_wheel_formula_string_ = d->get_game_pad_stick_vertical_wheel_formula(); - horizontal_wheel_formula_string_ = d->get_game_pad_stick_horizontal_wheel_formula(); - - x_formula_ = make_xy_formula_expression(x_formula_string_); - y_formula_ = make_xy_formula_expression(y_formula_string_); - vertical_wheel_formula_ = make_wheels_formula_expression(vertical_wheel_formula_string_); - horizontal_wheel_formula_ = make_wheels_formula_expression(horizontal_wheel_formula_string_); - } - exprtk_utility::expression_t make_xy_formula_expression(const std::string& formula) { return exprtk_utility::compile(formula, {}, @@ -624,7 +618,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche } gsl::not_null> device_properties_; - std::weak_ptr weak_core_configuration_; + gsl::not_null> core_configuration_; stick xy_; stick wheels_; diff --git a/src/share/core_configuration/details/profile/device.hpp b/src/share/core_configuration/details/profile/device.hpp index 01d804420..5f5423252 100644 --- a/src/share/core_configuration/details/profile/device.hpp +++ b/src/share/core_configuration/details/profile/device.hpp @@ -40,6 +40,14 @@ class device final { disable_built_in_keyboard_if_exists_, false); + helper_values_.push_back_value("pointing_motion_xy_multiplier", + pointing_motion_xy_multiplier_, + 1.0); + + helper_values_.push_back_value("pointing_motion_wheels_multiplier", + pointing_motion_wheels_multiplier_, + 1.0); + helper_values_.push_back_value("mouse_flip_x", mouse_flip_x_, false); @@ -350,6 +358,24 @@ cos(radian) * m; coordinate_between_properties(); } + const double& get_pointing_motion_xy_multiplier(void) const { + return pointing_motion_xy_multiplier_; + } + void set_pointing_motion_xy_multiplier(double value) { + pointing_motion_xy_multiplier_ = value; + + coordinate_between_properties(); + } + + const double& get_pointing_motion_wheels_multiplier(void) const { + return pointing_motion_wheels_multiplier_; + } + void set_pointing_motion_wheels_multiplier(double value) { + pointing_motion_wheels_multiplier_ = value; + + coordinate_between_properties(); + } + const bool& get_mouse_flip_x(void) const { return mouse_flip_x_; } @@ -605,6 +631,8 @@ cos(radian) * m; bool manipulate_caps_lock_led_; bool treat_as_built_in_keyboard_; bool disable_built_in_keyboard_if_exists_; + double pointing_motion_xy_multiplier_; + double pointing_motion_wheels_multiplier_; bool mouse_flip_x_; bool mouse_flip_y_; bool mouse_flip_vertical_wheel_; diff --git a/src/share/event_queue/utility.hpp b/src/share/event_queue/utility.hpp index 707389ae2..918e7fb6a 100644 --- a/src/share/event_queue/utility.hpp +++ b/src/share/event_queue/utility.hpp @@ -8,8 +8,20 @@ namespace krbn { namespace event_queue { namespace utility { +struct make_queue_parameters final { + double pointing_motion_xy_multiplier = 1.0; + double pointing_motion_wheels_multiplier = 1.0; +}; + +static inline int adjust_pointing_motion_value(const pqrs::osx::iokit_hid_value& value, + double multiplier) { + auto v = static_cast(static_cast(value.get_integer_value() * multiplier)); + return std::min(127, std::max(-127, v)); +} + static inline std::shared_ptr make_queue(gsl::not_null> device_properties, - const std::vector& hid_values) { + const std::vector& hid_values, + const make_queue_parameters& parameters) { auto result = std::make_shared(); // The pointing motion usage (hid_usage::gd_x, hid_usage::gd_y, etc.) are splitted from one HID report. @@ -75,7 +87,18 @@ static inline std::shared_ptr make_queue(gsl::not_null(v.get_integer_value()); + pointing_motion_x = adjust_pointing_motion_value(v, + parameters.pointing_motion_xy_multiplier); + + // if (!device_properties->get_device_identifiers().get_is_virtual_device()) { + if (auto max = v.get_logical_max()) { + logger::get_logger()->info("logical_max: {0}", *max); + } + if (auto min = v.get_logical_min()) { + logger::get_logger()->info("logical_min: {0}", *min); + } + logger::get_logger()->info("x: {0}", v.get_integer_value()); + //} } else if (v.conforms_to(pqrs::hid::usage_page::generic_desktop, pqrs::hid::usage::generic_desktop::y) && @@ -84,7 +107,8 @@ static inline std::shared_ptr make_queue(gsl::not_null(v.get_integer_value()); + pointing_motion_y = adjust_pointing_motion_value(v, + parameters.pointing_motion_xy_multiplier); } else if (v.conforms_to(pqrs::hid::usage_page::generic_desktop, pqrs::hid::usage::generic_desktop::wheel)) { @@ -92,7 +116,8 @@ static inline std::shared_ptr make_queue(gsl::not_null(v.get_integer_value()); + pointing_motion_vertical_wheel = adjust_pointing_motion_value(v, + parameters.pointing_motion_wheels_multiplier); } else if (v.conforms_to(pqrs::hid::usage_page::consumer, pqrs::hid::usage::consumer::ac_pan)) { @@ -100,7 +125,8 @@ static inline std::shared_ptr make_queue(gsl::not_null(v.get_integer_value()); + pointing_motion_horizontal_wheel = adjust_pointing_motion_value(v, + parameters.pointing_motion_wheels_multiplier); } else if (v.conforms_to(pqrs::hid::usage_page::leds, pqrs::hid::usage::led::caps_lock)) { diff --git a/tests/src/core_configuration/json/errors/profile_device_errors.jsonc b/tests/src/core_configuration/json/errors/profile_device_errors.jsonc index 7e357d44d..458bc50fd 100644 --- a/tests/src/core_configuration/json/errors/profile_device_errors.jsonc +++ b/tests/src/core_configuration/json/errors/profile_device_errors.jsonc @@ -55,6 +55,26 @@ "error": "`disable_built_in_keyboard_if_exists` must be boolean, but is `null`" }, + // pointing_motion_xy_multiplier + + { + "class": "devices", + "input": { + "pointing_motion_xy_multiplier": null + }, + "error": "`pointing_motion_xy_multiplier` must be number, but is `null`" + }, + + // pointing_motion_wheels_multiplier + + { + "class": "devices", + "input": { + "pointing_motion_wheels_multiplier": null + }, + "error": "`pointing_motion_wheels_multiplier` must be number, but is `null`" + }, + // mouse_flip_x { diff --git a/tests/src/core_configuration/src/device_test.hpp b/tests/src/core_configuration/src/device_test.hpp index b4ffd459f..e88cf7288 100644 --- a/tests/src/core_configuration/src/device_test.hpp +++ b/tests/src/core_configuration/src/device_test.hpp @@ -140,6 +140,14 @@ void run_device_test(void) { expect(false == device.get_manipulate_caps_lock_led()); expect(false == device.get_treat_as_built_in_keyboard()); expect(false == device.get_disable_built_in_keyboard_if_exists()); + { + auto& v = device.get_pointing_motion_xy_multiplier(); + expect(device.find_default_value(v) == v); + } + { + auto& v = device.get_pointing_motion_wheels_multiplier(); + expect(device.find_default_value(v) == v); + } { auto& v = device.get_game_pad_xy_stick_deadzone(); expect(device.find_default_value(v) == v); @@ -204,6 +212,8 @@ void run_device_test(void) { {"ignore", true}, {"manipulate_caps_lock_led", false}, {"treat_as_built_in_keyboard", false}, + {"pointing_motion_xy_multiplier", 2.0}, + {"pointing_motion_wheels_multiplier", 0.5}, {"game_pad_xy_stick_deadzone", 0.2}, {"game_pad_xy_stick_delta_magnitude_detection_threshold", 0.1}, {"game_pad_xy_stick_continued_movement_absolute_magnitude_threshold", 0.5}, @@ -229,6 +239,8 @@ void run_device_test(void) { expect(device.get_manipulate_caps_lock_led() == false); expect(device.get_treat_as_built_in_keyboard() == false); expect(device.get_disable_built_in_keyboard_if_exists() == true); + expect(device.get_pointing_motion_xy_multiplier() == 2.0); + expect(device.get_pointing_motion_wheels_multiplier() == 0.5); expect(device.get_game_pad_xy_stick_deadzone() == 0.2); expect(device.get_game_pad_xy_stick_delta_magnitude_detection_threshold() == 0.1); expect(device.get_game_pad_xy_stick_continued_movement_absolute_magnitude_threshold() == 0.5); @@ -373,6 +385,8 @@ void run_device_test(void) { {"ignore", true}, {"manipulate_caps_lock_led", false}, {"treat_as_built_in_keyboard", true}, + {"pointing_motion_xy_multiplier", 2.0}, + {"pointing_motion_wheels_multiplier", 0.5}, {"mouse_discard_horizontal_wheel", true}, {"mouse_discard_vertical_wheel", true}, {"mouse_discard_x", true}, @@ -438,6 +452,8 @@ void run_device_test(void) { {"mouse_flip_y", true}, {"mouse_swap_wheels", true}, {"mouse_swap_xy", true}, + {"pointing_motion_xy_multiplier", 2.0}, + {"pointing_motion_wheels_multiplier", 0.5}, {"treat_as_built_in_keyboard", true}, }); expect(device.to_json() == expected) << UT_SHOW_LINE; 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 e39ba26b4..fb7a5ee41 100644 --- a/tests/src/event_queue/src/event_queue_utility_test.hpp +++ b/tests/src/event_queue/src/event_queue_utility_test.hpp @@ -115,7 +115,8 @@ void run_event_queue_utility_test(void) { auto device_properties = krbn::device_properties::make_device_properties(krbn::device_id(1), nullptr); auto queue = krbn::event_queue::utility::make_queue(device_properties, - hid_values); + hid_values, + krbn::event_queue::utility::make_queue_parameters()); assert(queue->get_entries().size() == 8); { @@ -184,6 +185,93 @@ void run_event_queue_utility_test(void) { } }; + "utility::make_queue pointing_motion_xy_multiplier, pointing_motion_wheels_multiplier"_test = [] { + std::vector hid_values; + + hid_values.emplace_back(pqrs::osx::iokit_hid_value(krbn::absolute_time_point(1000), + 10, + pqrs::hid::usage_page::generic_desktop, + pqrs::hid::usage::generic_desktop::x, + std::nullopt, // logical_max + std::nullopt // logical_min + )); + hid_values.emplace_back(pqrs::osx::iokit_hid_value(krbn::absolute_time_point(1000), + 20, + pqrs::hid::usage_page::generic_desktop, + pqrs::hid::usage::generic_desktop::y, + std::nullopt, // logical_max + std::nullopt // logical_min + )); + hid_values.emplace_back(pqrs::osx::iokit_hid_value(krbn::absolute_time_point(1000), + 30, + pqrs::hid::usage_page::generic_desktop, + pqrs::hid::usage::generic_desktop::wheel, + std::nullopt, // logical_max + std::nullopt // logical_min + )); + hid_values.emplace_back(pqrs::osx::iokit_hid_value(krbn::absolute_time_point(1000), + 40, + pqrs::hid::usage_page::consumer, + pqrs::hid::usage::consumer::ac_pan, + std::nullopt, // logical_max + std::nullopt // logical_min + )); + + 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::x, + std::nullopt, // logical_max + std::nullopt // logical_min + )); + hid_values.emplace_back(pqrs::osx::iokit_hid_value(krbn::absolute_time_point(2000), + -20, + pqrs::hid::usage_page::generic_desktop, + pqrs::hid::usage::generic_desktop::y, + std::nullopt, // logical_max + std::nullopt // logical_min + )); + hid_values.emplace_back(pqrs::osx::iokit_hid_value(krbn::absolute_time_point(2000), + -30, + pqrs::hid::usage_page::generic_desktop, + pqrs::hid::usage::generic_desktop::wheel, + std::nullopt, // logical_max + std::nullopt // logical_min + )); + hid_values.emplace_back(pqrs::osx::iokit_hid_value(krbn::absolute_time_point(2000), + -40, + pqrs::hid::usage_page::consumer, + pqrs::hid::usage::consumer::ac_pan, + std::nullopt, // logical_max + std::nullopt // logical_min + )); + + auto device_properties = krbn::device_properties::make_device_properties(krbn::device_id(1), + nullptr); + auto queue = krbn::event_queue::utility::make_queue(device_properties, + hid_values, + krbn::event_queue::utility::make_queue_parameters{ + .pointing_motion_xy_multiplier = 2.0, + .pointing_motion_wheels_multiplier = 0.5, + }); + assert(queue->get_entries().size() == 2); + + { + 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_pointing_motion() == krbn::pointing_motion(20, 40, 15, 20)); + expect(e.get_event_type() == krbn::event_type::single); + } + { + 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(2000)); + expect(e.get_event().get_pointing_motion() == krbn::pointing_motion(-20, -40, -15, -20)); + expect(e.get_event_type() == krbn::event_type::single); + } + }; + "utility::make_queue not game_pad"_test = [] { std::vector hid_values; @@ -221,7 +309,8 @@ void run_event_queue_utility_test(void) { auto device_properties = krbn::device_properties::make_device_properties(krbn::device_id(1), nullptr); auto queue = krbn::event_queue::utility::make_queue(device_properties, - hid_values); + hid_values, + krbn::event_queue::utility::make_queue_parameters()); assert(0_ul == queue->get_entries().size()); }; @@ -265,7 +354,8 @@ void run_event_queue_utility_test(void) { }); auto queue = krbn::event_queue::utility::make_queue(device_properties, - hid_values); + hid_values, + krbn::event_queue::utility::make_queue_parameters()); assert(4_ul == queue->get_entries().size()); { From c6477e02ecf6e3e9a86601b4be7ddc82ec60704b Mon Sep 17 00:00:00 2001 From: Takayama Fumihiko Date: Mon, 30 Dec 2024 18:08:26 +0900 Subject: [PATCH 02/11] Remove debug message --- src/share/event_queue/utility.hpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/share/event_queue/utility.hpp b/src/share/event_queue/utility.hpp index 918e7fb6a..6c097407d 100644 --- a/src/share/event_queue/utility.hpp +++ b/src/share/event_queue/utility.hpp @@ -90,16 +90,6 @@ static inline std::shared_ptr make_queue(gsl::not_nullget_device_identifiers().get_is_virtual_device()) { - if (auto max = v.get_logical_max()) { - logger::get_logger()->info("logical_max: {0}", *max); - } - if (auto min = v.get_logical_min()) { - logger::get_logger()->info("logical_min: {0}", *min); - } - logger::get_logger()->info("x: {0}", v.get_integer_value()); - //} - } else if (v.conforms_to(pqrs::hid::usage_page::generic_desktop, pqrs::hid::usage::generic_desktop::y) && !is_game_pad) { From fb47b981a803cdaec5d68f7b0c016a6cb5a31e64 Mon Sep 17 00:00:00 2001 From: Takayama Fumihiko Date: Mon, 30 Dec 2024 18:59:25 +0900 Subject: [PATCH 03/11] Add pointing_motion_xy_multiplier, pointing_motion_wheels_multiplier to libkrbn --- src/lib/libkrbn/include/libkrbn/libkrbn.h | 8 +++++ src/lib/libkrbn/src/libkrbn_configuration.cpp | 36 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/lib/libkrbn/include/libkrbn/libkrbn.h b/src/lib/libkrbn/include/libkrbn/libkrbn.h index b58bba5d1..26c3bf4ff 100644 --- a/src/lib/libkrbn/include/libkrbn/libkrbn.h +++ b/src/lib/libkrbn/include/libkrbn/libkrbn.h @@ -218,6 +218,14 @@ void libkrbn_core_configuration_set_selected_profile_device_treat_as_built_in_ke bool libkrbn_core_configuration_get_selected_profile_device_disable_built_in_keyboard_if_exists(const libkrbn_device_identifiers* device_identifiers); void libkrbn_core_configuration_set_selected_profile_device_disable_built_in_keyboard_if_exists(const libkrbn_device_identifiers* device_identifiers, bool value); +double libkrbn_core_configuration_get_selected_profile_device_pointing_motion_xy_multiplier(const libkrbn_device_identifiers* device_identifiers); +void libkrbn_core_configuration_set_selected_profile_device_pointing_motion_xy_multiplier(const libkrbn_device_identifiers* device_identifiers, + double value); +double libkrbn_core_configuration_pointing_motion_xy_multiplier_default_value(void); +double libkrbn_core_configuration_get_selected_profile_device_pointing_motion_wheels_multiplier(const libkrbn_device_identifiers* device_identifiers); +void libkrbn_core_configuration_set_selected_profile_device_pointing_motion_wheels_multiplier(const libkrbn_device_identifiers* device_identifiers, + double value); +double libkrbn_core_configuration_pointing_motion_wheels_multiplier_default_value(void); bool libkrbn_core_configuration_get_selected_profile_device_mouse_flip_x(const libkrbn_device_identifiers* device_identifiers); void libkrbn_core_configuration_set_selected_profile_device_mouse_flip_x(const libkrbn_device_identifiers* device_identifiers, bool value); diff --git a/src/lib/libkrbn/src/libkrbn_configuration.cpp b/src/lib/libkrbn/src/libkrbn_configuration.cpp index f598cf839..c589982bd 100644 --- a/src/lib/libkrbn/src/libkrbn_configuration.cpp +++ b/src/lib/libkrbn/src/libkrbn_configuration.cpp @@ -663,6 +663,42 @@ void libkrbn_core_configuration_set_selected_profile_device_disable_built_in_key d->set_disable_built_in_keyboard_if_exists(value); } +double libkrbn_core_configuration_get_selected_profile_device_pointing_motion_xy_multiplier(const libkrbn_device_identifiers* device_identifiers) { + auto c = get_current_core_configuration(); + auto d = c->get_selected_profile().get_device(libkrbn_cpp::make_device_identifiers(device_identifiers)); + return d->get_pointing_motion_xy_multiplier(); +} + +void libkrbn_core_configuration_set_selected_profile_device_pointing_motion_xy_multiplier(const libkrbn_device_identifiers* device_identifiers, + double value) { + auto c = get_current_core_configuration(); + auto d = c->get_selected_profile().get_device(libkrbn_cpp::make_device_identifiers(device_identifiers)); + d->set_pointing_motion_xy_multiplier(value); +} + +double libkrbn_core_configuration_pointing_motion_xy_multiplier_default_value(void) { + return empty_device->find_default_value( + empty_device->get_pointing_motion_xy_multiplier()); +} + +double libkrbn_core_configuration_get_selected_profile_device_pointing_motion_wheels_multiplier(const libkrbn_device_identifiers* device_identifiers) { + auto c = get_current_core_configuration(); + auto d = c->get_selected_profile().get_device(libkrbn_cpp::make_device_identifiers(device_identifiers)); + return d->get_pointing_motion_wheels_multiplier(); +} + +void libkrbn_core_configuration_set_selected_profile_device_pointing_motion_wheels_multiplier(const libkrbn_device_identifiers* device_identifiers, + double value) { + auto c = get_current_core_configuration(); + auto d = c->get_selected_profile().get_device(libkrbn_cpp::make_device_identifiers(device_identifiers)); + d->set_pointing_motion_wheels_multiplier(value); +} + +double libkrbn_core_configuration_pointing_motion_wheels_multiplier_default_value(void) { + return empty_device->find_default_value( + empty_device->get_pointing_motion_wheels_multiplier()); +} + // // mouse_flip_XXX // From 7555ad1d0509ab9294d094293fa750575ec4c56e Mon Sep 17 00:00:00 2001 From: Takayama Fumihiko Date: Mon, 30 Dec 2024 19:00:12 +0900 Subject: [PATCH 04/11] Update image (capsule.portrait -> computermouse) --- src/apps/SettingsWindow/src/View/DeviceSelectorView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/SettingsWindow/src/View/DeviceSelectorView.swift b/src/apps/SettingsWindow/src/View/DeviceSelectorView.swift index 5abc4d135..edf1a5eaa 100644 --- a/src/apps/SettingsWindow/src/View/DeviceSelectorView.swift +++ b/src/apps/SettingsWindow/src/View/DeviceSelectorView.swift @@ -55,7 +55,7 @@ struct DeviceSelectorView: View { Image(systemName: "keyboard") } if connectedDevice.isPointingDevice { - Image(systemName: "capsule.portrait") + Image(systemName: "computermouse") } if connectedDevice.isGamePad { Image(systemName: "gamecontroller") From c8d139604756bff7c399c0cd0c3d3a7b86108ea8 Mon Sep 17 00:00:00 2001 From: Takayama Fumihiko Date: Mon, 30 Dec 2024 19:00:37 +0900 Subject: [PATCH 05/11] Add pointingMotionXYMultiplier, pointingMotionWheelsMultiplier --- .../Models/ConnectedDeviceSetting.swift | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/apps/share/swift/LibKrbn/Models/ConnectedDeviceSetting.swift b/src/apps/share/swift/LibKrbn/Models/ConnectedDeviceSetting.swift index 9809fb520..a0232532b 100644 --- a/src/apps/share/swift/LibKrbn/Models/ConnectedDeviceSetting.swift +++ b/src/apps/share/swift/LibKrbn/Models/ConnectedDeviceSetting.swift @@ -32,6 +32,14 @@ extension LibKrbn { libkrbn_core_configuration_get_selected_profile_device_disable_built_in_keyboard_if_exists( connectedDevice.libkrbnDeviceIdentifiers) + pointingMotionXYMultiplier = + libkrbn_core_configuration_get_selected_profile_device_pointing_motion_xy_multiplier( + connectedDevice.libkrbnDeviceIdentifiers) + + pointingMotionWheelsMultiplier = + libkrbn_core_configuration_get_selected_profile_device_pointing_motion_wheels_multiplier( + connectedDevice.libkrbnDeviceIdentifiers) + // // mouseFlipXXX // @@ -204,6 +212,28 @@ extension LibKrbn { } } + @Published var pointingMotionXYMultiplier: Double = 1.0 { + didSet { + if didSetEnabled { + libkrbn_core_configuration_set_selected_profile_device_pointing_motion_xy_multiplier( + connectedDevice.libkrbnDeviceIdentifiers, pointingMotionXYMultiplier) + + Settings.shared.save() + } + } + } + + @Published var pointingMotionWheelsMultiplier: Double = 1.0 { + didSet { + if didSetEnabled { + libkrbn_core_configuration_set_selected_profile_device_pointing_motion_wheels_multiplier( + connectedDevice.libkrbnDeviceIdentifiers, pointingMotionWheelsMultiplier) + + Settings.shared.save() + } + } + } + @Published var mouseFlipX: Bool = false { didSet { if didSetEnabled { From 38b76cf672645994ad9eabcf00e0d832524cd6fe Mon Sep 17 00:00:00 2001 From: Takayama Fumihiko Date: Mon, 30 Dec 2024 20:54:44 +0900 Subject: [PATCH 06/11] Add DevicesMouseFlagsView.swift --- .../src/View/DevicesMouseFlagsView.swift | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/apps/SettingsWindow/src/View/DevicesMouseFlagsView.swift diff --git a/src/apps/SettingsWindow/src/View/DevicesMouseFlagsView.swift b/src/apps/SettingsWindow/src/View/DevicesMouseFlagsView.swift new file mode 100644 index 000000000..fab534db4 --- /dev/null +++ b/src/apps/SettingsWindow/src/View/DevicesMouseFlagsView.swift @@ -0,0 +1,104 @@ +import SwiftUI + +struct DevicesMouseFlagsView: View { + @ObservedObject var connectedDeviceSetting: LibKrbn.ConnectedDeviceSetting + + var body: some View { + GroupBox(label: Text("Mouse Flags")) { + HStack(alignment: .top, spacing: 60.0) { + VStack(alignment: .leading, spacing: 6.0) { + Toggle(isOn: $connectedDeviceSetting.mouseFlipX) { + Text("Flip mouse X") + .frame(maxWidth: .infinity, alignment: .leading) + } + .switchToggleStyle(controlSize: .mini, font: .callout) + + Toggle(isOn: $connectedDeviceSetting.mouseFlipY) { + Text("Flip mouse Y") + .frame(maxWidth: .infinity, alignment: .leading) + } + .switchToggleStyle(controlSize: .mini, font: .callout) + + Toggle(isOn: $connectedDeviceSetting.mouseFlipVerticalWheel) { + Text("Flip mouse vertical wheel") + .frame(maxWidth: .infinity, alignment: .leading) + } + .switchToggleStyle(controlSize: .mini, font: .callout) + + Toggle(isOn: $connectedDeviceSetting.mouseFlipHorizontalWheel) { + Text("Flip mouse horizontal wheel") + .frame(maxWidth: .infinity, alignment: .leading) + } + .switchToggleStyle(controlSize: .mini, font: .callout) + } + .frame(width: 200.0) + + VStack(alignment: .leading, spacing: 6.0) { + Toggle(isOn: $connectedDeviceSetting.mouseDiscardX) { + Text("Discard mouse X") + .frame(maxWidth: .infinity, alignment: .leading) + } + .switchToggleStyle(controlSize: .mini, font: .callout) + + Toggle(isOn: $connectedDeviceSetting.mouseDiscardY) { + Text("Discard mouse Y") + .frame(maxWidth: .infinity, alignment: .leading) + } + .switchToggleStyle(controlSize: .mini, font: .callout) + + Toggle(isOn: $connectedDeviceSetting.mouseDiscardVerticalWheel) { + Text("Discard mouse vertical wheel") + .frame(maxWidth: .infinity, alignment: .leading) + } + .switchToggleStyle(controlSize: .mini, font: .callout) + + Toggle(isOn: $connectedDeviceSetting.mouseDiscardHorizontalWheel) { + Text("Discard mouse horizontal wheel") + .frame(maxWidth: .infinity, alignment: .leading) + } + .switchToggleStyle(controlSize: .mini, font: .callout) + } + .frame(width: 220.0) + + VStack(alignment: .leading, spacing: 6.0) { + Toggle(isOn: $connectedDeviceSetting.mouseSwapXY) { + Text("Swap mouse X and Y") + .frame(maxWidth: .infinity, alignment: .leading) + } + .switchToggleStyle(controlSize: .mini, font: .callout) + + Toggle(isOn: $connectedDeviceSetting.mouseSwapWheels) { + Text("Swap mouse wheels") + .frame(maxWidth: .infinity, alignment: .leading) + } + .switchToggleStyle(controlSize: .mini, font: .callout) + } + .frame(width: 160.0) + } + .padding() + } + } +} + +struct DevicesMouseFlagsView_Previews: PreviewProvider { + @State static var connectedDevice = LibKrbn.ConnectedDevice( + index: 0, + manufacturerName: "", + productName: "", + transport: "", + vendorId: 0, + productId: 0, + deviceAddress: "", + isKeyboard: false, + isPointingDevice: true, + isGamePad: false, + isVirtualDevice: false, + isBuiltInKeyboard: false, + isAppleDevice: false + ) + @State static var connectedDeviceSetting = LibKrbn.ConnectedDeviceSetting(connectedDevice) + + static var previews: some View { + DevicesMouseFlagsView(connectedDeviceSetting: connectedDeviceSetting) + } +} From 15c3166ba3a9130214b13803ea7bc17f657db260 Mon Sep 17 00:00:00 2001 From: Takayama Fumihiko Date: Mon, 30 Dec 2024 20:55:43 +0900 Subject: [PATCH 07/11] Update image (capsule.portrait -> computermouse) --- src/apps/SettingsWindow/src/View/DevicesView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/SettingsWindow/src/View/DevicesView.swift b/src/apps/SettingsWindow/src/View/DevicesView.swift index 73d72501f..979b1ad3c 100644 --- a/src/apps/SettingsWindow/src/View/DevicesView.swift +++ b/src/apps/SettingsWindow/src/View/DevicesView.swift @@ -111,7 +111,7 @@ struct DevicesView: View { Image(systemName: "keyboard") } if connectedDevice.isPointingDevice { - Image(systemName: "capsule.portrait") + Image(systemName: "computermouse") } if connectedDevice.isGamePad { Image(systemName: "gamecontroller") From 36b790c41a825686d17d4df3ae70ce491a2da89e Mon Sep 17 00:00:00 2001 From: Takayama Fumihiko Date: Mon, 30 Dec 2024 21:02:57 +0900 Subject: [PATCH 08/11] Use DevicesMouseFlagsView --- .../src/View/DevicesGamePadSettingsView.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/apps/SettingsWindow/src/View/DevicesGamePadSettingsView.swift b/src/apps/SettingsWindow/src/View/DevicesGamePadSettingsView.swift index 02243f011..197962a3a 100644 --- a/src/apps/SettingsWindow/src/View/DevicesGamePadSettingsView.swift +++ b/src/apps/SettingsWindow/src/View/DevicesGamePadSettingsView.swift @@ -4,8 +4,6 @@ struct DevicesGamePadSettingsView: View { @ObservedObject var connectedDeviceSetting: LibKrbn.ConnectedDeviceSetting @Binding var showing: Bool - @ObservedObject private var settings = LibKrbn.Settings.shared - var body: some View { ZStack(alignment: .topLeading) { VStack(alignment: .leading, spacing: 12.0) { @@ -156,7 +154,7 @@ struct DevicesGamePadSettingsView: View { @ObservedObject var connectedDeviceSetting: LibKrbn.ConnectedDeviceSetting var body: some View { - VStack(alignment: .leading) { + VStack(alignment: .leading, spacing: 40.0) { HStack { Toggle(isOn: $connectedDeviceSetting.gamePadSwapSticks) { Text("Swap gamepad XY and wheels sticks") @@ -166,6 +164,8 @@ struct DevicesGamePadSettingsView: View { Spacer() } + DevicesMouseFlagsView(connectedDeviceSetting: connectedDeviceSetting) + Spacer() } } From 4fadac49daae44a45ab3f16f5f567a7d7d747689 Mon Sep 17 00:00:00 2001 From: Takayama Fumihiko Date: Mon, 30 Dec 2024 21:15:54 +0900 Subject: [PATCH 09/11] Add DevicesMouseSettingsView.swift --- .../src/View/DevicesMouseSettingsView.swift | 90 +++++++++++++++++ .../SettingsWindow/src/View/DevicesView.swift | 98 ++++--------------- 2 files changed, 107 insertions(+), 81 deletions(-) create mode 100644 src/apps/SettingsWindow/src/View/DevicesMouseSettingsView.swift diff --git a/src/apps/SettingsWindow/src/View/DevicesMouseSettingsView.swift b/src/apps/SettingsWindow/src/View/DevicesMouseSettingsView.swift new file mode 100644 index 000000000..88f537a56 --- /dev/null +++ b/src/apps/SettingsWindow/src/View/DevicesMouseSettingsView.swift @@ -0,0 +1,90 @@ +import SwiftUI + +struct DevicesMouseSettingsView: View { + @ObservedObject var connectedDeviceSetting: LibKrbn.ConnectedDeviceSetting + @Binding var showing: Bool + + @ObservedObject private var settings = LibKrbn.Settings.shared + + var body: some View { + ZStack(alignment: .topLeading) { + VStack(alignment: .leading, spacing: 12.0) { + Text( + "\(connectedDeviceSetting.connectedDevice.productName) (\(connectedDeviceSetting.connectedDevice.manufacturerName))" + ) + .padding(.leading, 40) + .padding(.top, 20) + + GroupBox(label: Text("Multiplier")) { + Grid(alignment: .leadingFirstTextBaseline) { + GridRow { + Text("XY movement multiplier:") + + DoubleTextField( + value: $connectedDeviceSetting.pointingMotionXYMultiplier, + range: 0...10000, + step: 0.1, + maximumFractionDigits: 1, + width: 60) + + Text( + "(Default: \(String(format: "%.01f", libkrbn_core_configuration_pointing_motion_xy_multiplier_default_value()))" + ) + } + + GridRow { + Text("Wheels multiplier:") + + DoubleTextField( + value: $connectedDeviceSetting.pointingMotionWheelsMultiplier, + range: 0...10000, + step: 0.1, + maximumFractionDigits: 1, + width: 60) + + Text( + "(Default: \(String(format: "%.01f", libkrbn_core_configuration_pointing_motion_wheels_multiplier_default_value()))" + ) + } + } + } + + DevicesMouseFlagsView(connectedDeviceSetting: connectedDeviceSetting) + + Spacer() + } + + SheetCloseButton { + showing = false + } + } + .padding() + .frame(width: 1000, height: 600) + } +} + +struct DevicesMouseSettingsView_Previews: PreviewProvider { + @State static var connectedDevice = LibKrbn.ConnectedDevice( + index: 0, + manufacturerName: "", + productName: "", + transport: "", + vendorId: 0, + productId: 0, + deviceAddress: "", + isKeyboard: false, + isPointingDevice: true, + isGamePad: false, + isVirtualDevice: false, + isBuiltInKeyboard: false, + isAppleDevice: false + ) + @State static var connectedDeviceSetting = LibKrbn.ConnectedDeviceSetting(connectedDevice) + @State static var showing = true + + static var previews: some View { + DevicesMouseSettingsView( + connectedDeviceSetting: connectedDeviceSetting, + showing: $showing) + } +} diff --git a/src/apps/SettingsWindow/src/View/DevicesView.swift b/src/apps/SettingsWindow/src/View/DevicesView.swift index 979b1ad3c..7c1347e31 100644 --- a/src/apps/SettingsWindow/src/View/DevicesView.swift +++ b/src/apps/SettingsWindow/src/View/DevicesView.swift @@ -241,91 +241,27 @@ struct DevicesView: View { struct MouseSettings: View { @ObservedObject var connectedDeviceSetting: LibKrbn.ConnectedDeviceSetting - - @ObservedObject private var settings = LibKrbn.Settings.shared + @State var showing = false var body: some View { VStack { - if connectedDeviceSetting.connectedDevice.isPointingDevice - || connectedDeviceSetting.connectedDevice.isGamePad + if connectedDeviceSetting.modifyEvents + && connectedDeviceSetting.connectedDevice.isPointingDevice { - if connectedDeviceSetting.modifyEvents { - HStack(alignment: .top, spacing: 15.0) { - VStack(alignment: .leading, spacing: 2.0) { - Toggle(isOn: $connectedDeviceSetting.mouseFlipX) { - Text("Flip mouse X") - .frame(maxWidth: .infinity, alignment: .leading) - } - .switchToggleStyle(controlSize: .mini, font: .callout) - - Toggle(isOn: $connectedDeviceSetting.mouseFlipY) { - Text("Flip mouse Y") - .frame(maxWidth: .infinity, alignment: .leading) - } - .switchToggleStyle(controlSize: .mini, font: .callout) - - Toggle(isOn: $connectedDeviceSetting.mouseFlipVerticalWheel) { - Text("Flip mouse vertical wheel") - .frame(maxWidth: .infinity, alignment: .leading) - } - .switchToggleStyle(controlSize: .mini, font: .callout) - - Toggle(isOn: $connectedDeviceSetting.mouseFlipHorizontalWheel) { - Text("Flip mouse horizontal wheel") - .frame(maxWidth: .infinity, alignment: .leading) - } - .switchToggleStyle(controlSize: .mini, font: .callout) - } - .frame(width: 200.0) - - Divider() - - VStack(alignment: .leading, spacing: 2.0) { - Toggle(isOn: $connectedDeviceSetting.mouseDiscardX) { - Text("Discard mouse X") - .frame(maxWidth: .infinity, alignment: .leading) - } - .switchToggleStyle(controlSize: .mini, font: .callout) - - Toggle(isOn: $connectedDeviceSetting.mouseDiscardY) { - Text("Discard mouse Y") - .frame(maxWidth: .infinity, alignment: .leading) - } - .switchToggleStyle(controlSize: .mini, font: .callout) - - Toggle(isOn: $connectedDeviceSetting.mouseDiscardVerticalWheel) { - Text("Discard mouse vertical wheel") - .frame(maxWidth: .infinity, alignment: .leading) - } - .switchToggleStyle(controlSize: .mini, font: .callout) - - Toggle(isOn: $connectedDeviceSetting.mouseDiscardHorizontalWheel) { - Text("Discard mouse horizontal wheel") - .frame(maxWidth: .infinity, alignment: .leading) - } - .switchToggleStyle(controlSize: .mini, font: .callout) - } - .frame(width: 220.0) - - Divider() - - VStack(alignment: .leading, spacing: 2.0) { - Toggle(isOn: $connectedDeviceSetting.mouseSwapXY) { - Text("Swap mouse X and Y") - .frame(maxWidth: .infinity, alignment: .leading) - } - .switchToggleStyle(controlSize: .mini, font: .callout) - - Toggle(isOn: $connectedDeviceSetting.mouseSwapWheels) { - Text("Swap mouse wheels") - .frame(maxWidth: .infinity, alignment: .leading) - } - .switchToggleStyle(controlSize: .mini, font: .callout) - } - .frame(width: 160.0) - - Spacer() + Button( + action: { + showing = true + }, + label: { + Label("Open mouse settings", systemImage: "computermouse") + .buttonLabelStyle() } + ) + .sheet(isPresented: $showing) { + DevicesMouseSettingsView( + connectedDeviceSetting: connectedDeviceSetting, + showing: $showing + ) } } } @@ -338,7 +274,7 @@ struct DevicesView: View { var body: some View { VStack { - if connectedDeviceSetting.connectedDevice.isGamePad { + if connectedDeviceSetting.modifyEvents && connectedDeviceSetting.connectedDevice.isGamePad { Button( action: { showing = true From 630ffc9eb25c24203aa9d606180474e76ffd5867 Mon Sep 17 00:00:00 2001 From: Takayama Fumihiko Date: Mon, 30 Dec 2024 21:26:36 +0900 Subject: [PATCH 10/11] Tweak DevicesMouseSettingsView layout --- .../SettingsWindow/src/View/DevicesMouseSettingsView.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/apps/SettingsWindow/src/View/DevicesMouseSettingsView.swift b/src/apps/SettingsWindow/src/View/DevicesMouseSettingsView.swift index 88f537a56..f9d5457c8 100644 --- a/src/apps/SettingsWindow/src/View/DevicesMouseSettingsView.swift +++ b/src/apps/SettingsWindow/src/View/DevicesMouseSettingsView.swift @@ -8,7 +8,7 @@ struct DevicesMouseSettingsView: View { var body: some View { ZStack(alignment: .topLeading) { - VStack(alignment: .leading, spacing: 12.0) { + VStack(alignment: .leading, spacing: 40.0) { Text( "\(connectedDeviceSetting.connectedDevice.productName) (\(connectedDeviceSetting.connectedDevice.manufacturerName))" ) @@ -47,6 +47,7 @@ struct DevicesMouseSettingsView: View { ) } } + .padding() } DevicesMouseFlagsView(connectedDeviceSetting: connectedDeviceSetting) From 6088d66a2c201338ec1bd0d2f4df2fce6d0a6f0f Mon Sep 17 00:00:00 2001 From: Takayama Fumihiko Date: Mon, 30 Dec 2024 21:41:54 +0900 Subject: [PATCH 11/11] Improve adjust_pointing_motion_value to prevent adjusted values from becoming 0 when multiplier is too small --- src/share/event_queue/utility.hpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/share/event_queue/utility.hpp b/src/share/event_queue/utility.hpp index 6c097407d..dedfc6dfb 100644 --- a/src/share/event_queue/utility.hpp +++ b/src/share/event_queue/utility.hpp @@ -15,7 +15,19 @@ struct make_queue_parameters final { static inline int adjust_pointing_motion_value(const pqrs::osx::iokit_hid_value& value, double multiplier) { - auto v = static_cast(static_cast(value.get_integer_value() * multiplier)); + auto integer_value = value.get_integer_value(); + auto v = static_cast(static_cast(integer_value * multiplier)); + + if (v == 0) { + // To prevent all adjusted values from becoming 0 when an extremely small value is specified for the multiplier, + // ensure that the value is at least 1 or -1. + if (integer_value > 0) { + return 1; + } else if (integer_value < 0) { + return -1; + } + } + return std::min(127, std::max(-127, v)); }