Skip to content

Commit

Permalink
Improve adjust_pointing_motion_value to prevent adjusted values from …
Browse files Browse the repository at this point in the history
…becoming 0 when multiplier is too small
  • Loading branch information
tekezo committed Dec 30, 2024
1 parent 630ffc9 commit 6088d66
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/share/event_queue/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(static_cast<double>(value.get_integer_value() * multiplier));
auto integer_value = value.get_integer_value();
auto v = static_cast<int>(static_cast<double>(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));
}

Expand Down

0 comments on commit 6088d66

Please sign in to comment.