Support HiresScroll gesture remapping
This commit allows HiresScroll (when target is true) to map the up and down events to gestures that support it (i.e.AxisGesture/ IntervalGesture). This check is done by checking if wheelCompatibility() is true. This also allows hires scroll events to send low-res scroll events as well. TODO: Fix bug w/ Chromium (and some other programs?) where mapping scroll wheel to REL_WHEEL_HI_RES will cause the program to skip events occassionally. I have literally been stuck on this bug for a week and I still don't know what causes it. evtest shows proper scroll events, Firefox works fine, and libinput test-gui reports proper scrolling.
This commit is contained in:
@@ -27,10 +27,11 @@ AxisGesture::AxisGesture(Device *device, libconfig::Setting &root) :
|
||||
{
|
||||
}
|
||||
|
||||
void AxisGesture::press()
|
||||
void AxisGesture::press(bool init_threshold)
|
||||
{
|
||||
_axis = 0;
|
||||
_axis = init_threshold ? _config.threshold() : 0;
|
||||
_axis_remainder = 0;
|
||||
_hires_remainder = 0;
|
||||
}
|
||||
|
||||
void AxisGesture::release(bool primary)
|
||||
@@ -41,7 +42,10 @@ void AxisGesture::release(bool primary)
|
||||
|
||||
void AxisGesture::move(int16_t axis)
|
||||
{
|
||||
int16_t new_axis = _axis + axis;
|
||||
int16_t new_axis = _axis+axis;
|
||||
int low_res_axis = InputDevice::getLowResAxis(_config.axis());
|
||||
int hires_remainder = _hires_remainder;
|
||||
|
||||
if(new_axis > _config.threshold()) {
|
||||
double move = axis;
|
||||
if(_axis < _config.threshold())
|
||||
@@ -63,7 +67,22 @@ void AxisGesture::move(int16_t axis)
|
||||
if(negative_multiplier)
|
||||
move_floor = -move_floor;
|
||||
|
||||
virtual_input->moveAxis(_config.axis(), move_floor);
|
||||
if(low_res_axis != -1) {
|
||||
int lowres_movement = 0, hires_movement = move_floor;
|
||||
virtual_input->moveAxis(_config.axis(), hires_movement);
|
||||
hires_remainder += hires_movement;
|
||||
if(abs(hires_remainder) >= 60) {
|
||||
lowres_movement = hires_remainder/120;
|
||||
if(lowres_movement == 0)
|
||||
lowres_movement = hires_remainder > 0 ? 1 : -1;
|
||||
hires_remainder -= lowres_movement*120;
|
||||
virtual_input->moveAxis(low_res_axis, lowres_movement);
|
||||
}
|
||||
|
||||
_hires_remainder = hires_remainder;
|
||||
} else {
|
||||
virtual_input->moveAxis(_config.axis(), move_floor);
|
||||
}
|
||||
}
|
||||
_axis = new_axis;
|
||||
}
|
||||
@@ -73,6 +92,11 @@ bool AxisGesture::metThreshold() const
|
||||
return _axis >= _config.threshold();
|
||||
}
|
||||
|
||||
void AxisGesture::setHiresMultiplier(double multiplier)
|
||||
{
|
||||
_config.setHiresMultiplier(multiplier);
|
||||
}
|
||||
|
||||
AxisGesture::Config::Config(Device *device, libconfig::Setting &setting) :
|
||||
Gesture::Config(device, setting, false)
|
||||
{
|
||||
@@ -113,6 +137,9 @@ AxisGesture::Config::Config(Device *device, libconfig::Setting &setting) :
|
||||
} catch(libconfig::SettingNotFoundException& e) {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
if(InputDevice::getLowResAxis(_axis) != -1)
|
||||
_multiplier *= 120;
|
||||
}
|
||||
|
||||
unsigned int AxisGesture::Config::axis() const
|
||||
@@ -123,4 +150,22 @@ unsigned int AxisGesture::Config::axis() const
|
||||
double AxisGesture::Config::multiplier() const
|
||||
{
|
||||
return _multiplier;
|
||||
}
|
||||
|
||||
bool AxisGesture::wheelCompatibility() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void AxisGesture::Config::setHiresMultiplier(double multiplier)
|
||||
{
|
||||
if(_hires_multiplier == multiplier || multiplier == 0)
|
||||
return;
|
||||
|
||||
if(InputDevice::getLowResAxis(_axis) != -1) {
|
||||
_multiplier *= _hires_multiplier;
|
||||
_multiplier /= multiplier;
|
||||
}
|
||||
|
||||
_hires_multiplier = multiplier;
|
||||
}
|
@@ -28,26 +28,32 @@ namespace logid {
|
||||
public:
|
||||
AxisGesture(Device* device, libconfig::Setting& root);
|
||||
|
||||
virtual void press();
|
||||
virtual void press(bool init_threshold=false);
|
||||
virtual void release(bool primary=false);
|
||||
virtual void move(int16_t axis);
|
||||
|
||||
virtual bool wheelCompatibility() const;
|
||||
virtual bool metThreshold() const;
|
||||
|
||||
void setHiresMultiplier(double multiplier);
|
||||
|
||||
class Config : public Gesture::Config
|
||||
{
|
||||
public:
|
||||
Config(Device* device, libconfig::Setting& setting);
|
||||
unsigned int axis() const;
|
||||
double multiplier() const;
|
||||
void setHiresMultiplier(double multiplier);
|
||||
private:
|
||||
unsigned int _axis;
|
||||
double _multiplier = 1;
|
||||
double _hires_multiplier = 1;
|
||||
};
|
||||
|
||||
protected:
|
||||
int16_t _axis;
|
||||
double _axis_remainder;
|
||||
int _hires_remainder;
|
||||
Config _config;
|
||||
};
|
||||
}}
|
||||
|
@@ -42,10 +42,11 @@ namespace actions
|
||||
class Gesture
|
||||
{
|
||||
public:
|
||||
virtual void press() = 0;
|
||||
virtual void press(bool init_threshold=false) = 0;
|
||||
virtual void release(bool primary=false) = 0;
|
||||
virtual void move(int16_t axis) = 0;
|
||||
|
||||
virtual bool wheelCompatibility() const = 0;
|
||||
virtual bool metThreshold() const = 0;
|
||||
|
||||
class Config
|
||||
|
@@ -25,9 +25,9 @@ IntervalGesture::IntervalGesture(Device *device, libconfig::Setting &root) :
|
||||
{
|
||||
}
|
||||
|
||||
void IntervalGesture::press()
|
||||
void IntervalGesture::press(bool init_threshold)
|
||||
{
|
||||
_axis = 0;
|
||||
_axis = init_threshold ? _config.threshold() : 0;
|
||||
_interval_pass_count = 0;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,11 @@ void IntervalGesture::move(int16_t axis)
|
||||
_interval_pass_count = new_interval_count;
|
||||
}
|
||||
|
||||
bool IntervalGesture::wheelCompatibility() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IntervalGesture::metThreshold() const
|
||||
{
|
||||
return _axis >= _config.threshold();
|
||||
|
@@ -28,10 +28,11 @@ namespace actions
|
||||
public:
|
||||
IntervalGesture(Device* device, libconfig::Setting& root);
|
||||
|
||||
virtual void press();
|
||||
virtual void press(bool init_threshold=false);
|
||||
virtual void release(bool primary=false);
|
||||
virtual void move(int16_t axis);
|
||||
|
||||
virtual bool wheelCompatibility() const;
|
||||
virtual bool metThreshold() const;
|
||||
|
||||
class Config : public Gesture::Config
|
||||
|
@@ -24,9 +24,9 @@ NullGesture::NullGesture(Device *device, libconfig::Setting& setting) :
|
||||
{
|
||||
}
|
||||
|
||||
void NullGesture::press()
|
||||
void NullGesture::press(bool init_threshold)
|
||||
{
|
||||
_axis = 0;
|
||||
_axis = init_threshold ? _config.threshold() : 0;
|
||||
}
|
||||
|
||||
void NullGesture::release(bool primary)
|
||||
@@ -40,6 +40,11 @@ void NullGesture::move(int16_t axis)
|
||||
_axis += axis;
|
||||
}
|
||||
|
||||
bool NullGesture::wheelCompatibility() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NullGesture::metThreshold() const
|
||||
{
|
||||
return _axis > _config.threshold();
|
||||
|
@@ -28,10 +28,11 @@ namespace actions
|
||||
public:
|
||||
NullGesture(Device* device, libconfig::Setting& setting);
|
||||
|
||||
virtual void press();
|
||||
virtual void press(bool init_threshold=false);
|
||||
virtual void release(bool primary=false);
|
||||
virtual void move(int16_t axis);
|
||||
|
||||
virtual bool wheelCompatibility() const;
|
||||
virtual bool metThreshold() const;
|
||||
protected:
|
||||
int16_t _axis;
|
||||
|
@@ -24,9 +24,9 @@ ReleaseGesture::ReleaseGesture(Device *device, libconfig::Setting &root) :
|
||||
{
|
||||
}
|
||||
|
||||
void ReleaseGesture::press()
|
||||
void ReleaseGesture::press(bool init_threshold)
|
||||
{
|
||||
_axis = 0;
|
||||
_axis = init_threshold ? _config.threshold() : 0;
|
||||
}
|
||||
|
||||
void ReleaseGesture::release(bool primary)
|
||||
@@ -42,6 +42,11 @@ void ReleaseGesture::move(int16_t axis)
|
||||
_axis += axis;
|
||||
}
|
||||
|
||||
bool ReleaseGesture::wheelCompatibility() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ReleaseGesture::metThreshold() const
|
||||
{
|
||||
return _axis >= _config.threshold();
|
||||
|
@@ -28,10 +28,11 @@ namespace actions
|
||||
public:
|
||||
ReleaseGesture(Device* device, libconfig::Setting& root);
|
||||
|
||||
virtual void press();
|
||||
virtual void press(bool init_threshold=false);
|
||||
virtual void release(bool primary=false);
|
||||
virtual void move(int16_t axis);
|
||||
|
||||
virtual bool wheelCompatibility() const;
|
||||
virtual bool metThreshold() const;
|
||||
|
||||
protected:
|
||||
|
Reference in New Issue
Block a user