* Fixed the mouse movement when speed or acceleration where below default
values. The implementation needs to sum up fractional movement, not truncate to zero. Before this change, the mouse would be pretty much unusable at lower speeds/acceleration. Now it is guaranteed to move. * No need to memset() before ioctl(), the driver does that anyways. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28669 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -86,8 +86,8 @@
|
|||||||
# define TRACE(x...) do {} while (0)
|
# define TRACE(x...) do {} while (0)
|
||||||
# define MD_CALLED(x...) TRACE(x)
|
# define MD_CALLED(x...) TRACE(x)
|
||||||
# define MID_CALLED(x...) TRACE(x)
|
# define MID_CALLED(x...) TRACE(x)
|
||||||
# define LOG_ERR(text...) debug_printf(text)
|
# define LOG_ERR(x...) debug_printf(x)
|
||||||
# define LOG_EVENT(text...) TRACE(x)
|
# define LOG_EVENT(x...) TRACE(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -128,7 +128,9 @@ private:
|
|||||||
int32 deltaX, int32 deltaY) const;
|
int32 deltaX, int32 deltaY) const;
|
||||||
void _ComputeAcceleration(
|
void _ComputeAcceleration(
|
||||||
const mouse_movement& movements,
|
const mouse_movement& movements,
|
||||||
int32& deltaX, int32& deltaY) const;
|
int32& deltaX, int32& deltaY,
|
||||||
|
float& historyDeltaX,
|
||||||
|
float& historyDeltaY) const;
|
||||||
uint32 _RemapButtons(uint32 buttons) const;
|
uint32 _RemapButtons(uint32 buttons) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -368,11 +370,11 @@ MouseDevice::_ControlThread()
|
|||||||
_UpdateSettings();
|
_UpdateSettings();
|
||||||
|
|
||||||
uint32 lastButtons = 0;
|
uint32 lastButtons = 0;
|
||||||
|
float historyDeltaX = 0.0;
|
||||||
|
float historyDeltaY = 0.0;
|
||||||
|
|
||||||
while (fActive) {
|
while (fActive) {
|
||||||
mouse_movement movements;
|
mouse_movement movements;
|
||||||
memset(&movements, 0, sizeof(movements));
|
|
||||||
|
|
||||||
if (ioctl(fDevice, MS_READ, &movements) != B_OK) {
|
if (ioctl(fDevice, MS_READ, &movements) != B_OK) {
|
||||||
_ControlThreadCleanup();
|
_ControlThreadCleanup();
|
||||||
// TOAST!
|
// TOAST!
|
||||||
@@ -399,12 +401,16 @@ MouseDevice::_ControlThread()
|
|||||||
|
|
||||||
uint32 remappedButtons = _RemapButtons(movements.buttons);
|
uint32 remappedButtons = _RemapButtons(movements.buttons);
|
||||||
int32 deltaX, deltaY;
|
int32 deltaX, deltaY;
|
||||||
_ComputeAcceleration(movements, deltaX, deltaY);
|
_ComputeAcceleration(movements, deltaX, deltaY, historyDeltaX,
|
||||||
|
historyDeltaY);
|
||||||
|
|
||||||
LOG_EVENT("%s: buttons: 0x%lx, x: %ld, y: %ld, clicks:%ld, wheel_x:%ld, wheel_y:%ld\n",
|
LOG_EVENT("%s: buttons: 0x%lx, x: %ld, y: %ld, clicks:%ld, "
|
||||||
fDeviceRef.name, movements.buttons, movements.xdelta, movements.ydelta,
|
"wheel_x:%ld, wheel_y:%ld\n",
|
||||||
movements.clicks, movements.wheel_xdelta, movements.wheel_ydelta);
|
fDeviceRef.name, movements.buttons,
|
||||||
LOG_EVENT("%s: x: %ld, y: %ld\n", fDeviceRef.name, deltaX, deltaY);
|
movements.xdelta, movements.ydelta, movements.clicks,
|
||||||
|
movements.wheel_xdelta, movements.wheel_ydelta);
|
||||||
|
LOG_EVENT("%s: x: %ld, y: %ld (%.4f, %.4f)\n", fDeviceRef.name,
|
||||||
|
deltaX, deltaY, historyDeltaX, historyDeltaY);
|
||||||
|
|
||||||
// Send single messages for each event
|
// Send single messages for each event
|
||||||
|
|
||||||
@@ -574,11 +580,14 @@ MouseDevice::_BuildMouseMessage(uint32 what, uint64 when, uint32 buttons,
|
|||||||
|
|
||||||
void
|
void
|
||||||
MouseDevice::_ComputeAcceleration(const mouse_movement& movements,
|
MouseDevice::_ComputeAcceleration(const mouse_movement& movements,
|
||||||
int32& deltaX, int32& deltaY) const
|
int32& _deltaX, int32& _deltaY, float& historyDeltaX,
|
||||||
|
float& historyDeltaY) const
|
||||||
{
|
{
|
||||||
// basic mouse speed
|
// basic mouse speed
|
||||||
deltaX = movements.xdelta * fSettings.accel.speed >> 16;
|
float deltaX = (float)movements.xdelta * fSettings.accel.speed / 65536.0
|
||||||
deltaY = movements.ydelta * fSettings.accel.speed >> 16;
|
+ historyDeltaX;
|
||||||
|
float deltaY = (float)movements.ydelta * fSettings.accel.speed / 65536.0
|
||||||
|
+ historyDeltaY;
|
||||||
|
|
||||||
// acceleration
|
// acceleration
|
||||||
double acceleration = 1;
|
double acceleration = 1;
|
||||||
@@ -587,16 +596,21 @@ MouseDevice::_ComputeAcceleration(const mouse_movement& movements,
|
|||||||
* fSettings.accel.accel_factor / 524288.0;
|
* fSettings.accel.accel_factor / 524288.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure that we move at least one pixel (if there was a movement)
|
deltaX *= acceleration;
|
||||||
if (deltaX > 0)
|
deltaY *= acceleration;
|
||||||
deltaX = (int32)floor(deltaX * acceleration);
|
|
||||||
else
|
|
||||||
deltaX = (int32)ceil(deltaX * acceleration);
|
|
||||||
|
|
||||||
if (deltaY > 0)
|
if (deltaX >= 0)
|
||||||
deltaY = (int32)floor(deltaY * acceleration);
|
_deltaX = (int32)floorf(deltaX);
|
||||||
else
|
else
|
||||||
deltaY = (int32)ceil(deltaY * acceleration);
|
_deltaX = (int32)ceilf(deltaX);
|
||||||
|
|
||||||
|
if (deltaY >= 0)
|
||||||
|
_deltaY = (int32)floorf(deltaY);
|
||||||
|
else
|
||||||
|
_deltaY = (int32)ceilf(deltaY);
|
||||||
|
|
||||||
|
historyDeltaX = deltaX - _deltaX;
|
||||||
|
historyDeltaY = deltaY - _deltaY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user