various fixes for scroll wheel

*fix using scroll delta instead axis code
*fix lost registering low res axis if it will be used
*fix duplicate inverting direction of delta
*make scroll behavior more responsive
*fix and imprv logging
This commit is contained in:
glempi 2023-11-05 07:34:57 +03:00
parent 94f6dbab53
commit 1edf7b9ba0
2 changed files with 38 additions and 10 deletions

View File

@ -44,19 +44,29 @@ AxisGesture::AxisGesture(Device* device, config::AxisGesture& config,
const auto& axis = std::get<std::string>(_config.axis.value()); const auto& axis = std::get<std::string>(_config.axis.value());
try { try {
_input_axis = _device->virtualInput()->toAxisCode(axis); _input_axis = _device->virtualInput()->toAxisCode(axis);
logPrintf(INFO, "axis %d %s", _input_axis, axis.c_str());
} catch (InputDevice::InvalidEventCode& e) { } catch (InputDevice::InvalidEventCode& e) {
logPrintf(WARN, "Invalid axis %s."); logPrintf(WARN, "Invalid axis %s.", axis.c_str());
} }
} }
} }
if (_input_axis.has_value()) if (_input_axis.has_value())
_device->virtualInput()->registerAxis(_input_axis.value()); registerAxis(_input_axis.value());
}
void AxisGesture::registerAxis(uint axis) {
_device->virtualInput()->registerAxis(axis);
int low_res_axis = InputDevice::getLowResAxis(axis);
if (low_res_axis != -1) {
_device->virtualInput()->registerAxis(low_res_axis);
}
} }
void AxisGesture::press(bool init_threshold) { void AxisGesture::press(bool init_threshold) {
std::shared_lock lock(_config_mutex); std::shared_lock lock(_config_mutex);
logPrintf(RAWREPORT, "press %d %d\n", _axis, init_threshold);
if (init_threshold) { if (init_threshold) {
_axis = (int32_t) (_config.threshold.value_or(defaults::gesture_threshold)); _axis = (int32_t) (_config.threshold.value_or(defaults::gesture_threshold));
} else { } else {
@ -76,12 +86,14 @@ void AxisGesture::move(int16_t axis) {
if (!_input_axis.has_value()) if (!_input_axis.has_value())
return; return;
const auto threshold = _config.threshold.value_or( const auto threshold = _config.threshold.value_or(
defaults::gesture_threshold); defaults::gesture_threshold);
int32_t new_axis = _axis + axis; int32_t new_axis = _axis + axis;
int low_res_axis = InputDevice::getLowResAxis(axis); int low_res_axis = InputDevice::getLowResAxis(_input_axis.value());
int hires_remainder = _hires_remainder; int hires_remainder = _hires_remainder;
if (new_axis > threshold) { if (new_axis > threshold) {
double move = axis; double move = axis;
if (_axis < threshold) if (_axis < threshold)
@ -102,21 +114,34 @@ void AxisGesture::move(int16_t axis) {
_axis_remainder -= int_remainder; _axis_remainder -= int_remainder;
} }
if (negative_multiplier)
move_floor = -move_floor;
if (low_res_axis != -1) { if (low_res_axis != -1) {
int lowres_movement, hires_movement = (int) move_floor; int lowres_movement = 0;
int hires_movement = (int) move_floor;
_device->virtualInput()->moveAxis(_input_axis.value(), hires_movement); _device->virtualInput()->moveAxis(_input_axis.value(), hires_movement);
hires_remainder += hires_movement; hires_remainder += hires_movement;
if (abs(hires_remainder) >= 60) { if (abs(hires_remainder) >= 1) {
lowres_movement = hires_remainder / 120; lowres_movement = hires_remainder / 120;
if (lowres_movement == 0) if (lowres_movement == 0) {
lowres_movement = hires_remainder > 0 ? 1 : -1; lowres_movement = hires_remainder > 0 ? 1 : -1;
}
if ((lowres_movement > 0 && negative_multiplier) ||
(lowres_movement < 0 && !negative_multiplier))
{
lowres_movement = 0;
}
hires_remainder -= lowres_movement * 120; hires_remainder -= lowres_movement * 120;
_device->virtualInput()->moveAxis(low_res_axis, lowres_movement); _device->virtualInput()->moveAxis(low_res_axis, lowres_movement);
} }
logPrintf(RAWREPORT, "move %ld [%.2f], l_mv:%d h_mv:%d code:%d/%d;"
" axis %d/%d; new_axis %d; hires_rem %d th %d neg %d mv %.1f\n",
time(NULL), _config.axis_multiplier.value_or(1), lowres_movement, hires_movement,
_input_axis.value(), low_res_axis, axis, _axis, new_axis, hires_remainder,
threshold, negative_multiplier, move);
_hires_remainder = hires_remainder; _hires_remainder = hires_remainder;
} else { } else {
_device->virtualInput()->moveAxis(_input_axis.value(), (int) move_floor); _device->virtualInput()->moveAxis(_input_axis.value(), (int) move_floor);
@ -164,7 +189,7 @@ void AxisGesture::setAxis(const std::string& axis) {
} else { } else {
_input_axis = _device->virtualInput()->toAxisCode(axis); _input_axis = _device->virtualInput()->toAxisCode(axis);
_config.axis = axis; _config.axis = axis;
_device->virtualInput()->registerAxis(_input_axis.value()); registerAxis(_input_axis.value());
} }
setHiresMultiplier(_hires_multiplier); setHiresMultiplier(_hires_multiplier);
} }

View File

@ -48,6 +48,9 @@ namespace logid::actions {
void setThreshold(int threshold); void setThreshold(int threshold);
protected:
void registerAxis(uint axis);
protected: protected:
int32_t _axis{}; int32_t _axis{};
double _axis_remainder{}; double _axis_remainder{};