Add "Resolution" option for mice to the evdev driver

It can be used to scale the resolution of a mouse to that of a 1000 DPI
mouse. This can be useful to make high resolution mice less sensitive
without turning off acceleration. The target of 1000 DPI is used as the
same default is used in libinput. If the option is not set no scaling
will be done.

https://bugs.freedesktop.org/show_bug.cgi?id=88134
Signed-off-by: Thomas Hindoe Paaboel Andersen <phomes@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
master
Thomas Hindoe Paaboel Andersen 11 years ago committed by Peter Hutterer
parent 66c9978864
commit 034be31159
  1. 6
      man/evdev.man
  2. 10
      src/emuThird.c
  3. 24
      src/evdev.c
  4. 7
      src/evdev.h

@ -238,6 +238,12 @@ Default: "1". Property: "Evdev Scrolling Distance".
.BI "Option \*qDialDelta\*q \*q" integer \*q .BI "Option \*qDialDelta\*q \*q" integer \*q
The amount of motion considered one unit of turning the dial. Default: "1". The amount of motion considered one unit of turning the dial. Default: "1".
Property: "Evdev Scrolling Distance". Property: "Evdev Scrolling Distance".
.TP 7
.BI "Option \*qResolution\*q \*q" integer \*q
Sets the resolution of the device in dots per inch. The resolution is used
to scale relative motion events from mouse devices to 1000 DPI resolution. This
can be used to make high resolution mice less sensitive without turning off
acceleration. If set to 0 no scaling will be performed. Default: "0".
.SH SUPPORTED PROPERTIES .SH SUPPORTED PROPERTIES
The following properties are provided by the The following properties are provided by the

@ -229,8 +229,8 @@ Evdev3BEmuProcessAbsMotion(InputInfoPtr pInfo, ValuatorMask *vals)
{ {
if (valuator_mask_isset(vals, axis)) if (valuator_mask_isset(vals, axis))
{ {
int delta = valuator_mask_get(vals, axis) - emu3B->startpos[axis]; double delta = valuator_mask_get_double(vals, axis) - emu3B->startpos[axis];
if (abs(delta) > emu3B->threshold) if (fabs(delta) > emu3B->threshold)
cancel = TRUE; cancel = TRUE;
} }
axis++; axis++;
@ -248,7 +248,7 @@ Evdev3BEmuProcessAbsMotion(InputInfoPtr pInfo, ValuatorMask *vals)
* emulation. * emulation.
*/ */
void void
Evdev3BEmuProcessRelMotion(InputInfoPtr pInfo, int dx, int dy) Evdev3BEmuProcessRelMotion(InputInfoPtr pInfo, double dx, double dy)
{ {
EvdevPtr pEvdev = pInfo->private; EvdevPtr pEvdev = pInfo->private;
struct emulate3B *emu3B = &pEvdev->emulate3B; struct emulate3B *emu3B = &pEvdev->emulate3B;
@ -260,8 +260,8 @@ Evdev3BEmuProcessRelMotion(InputInfoPtr pInfo, int dx, int dy)
emu3B->delta[1] += dy; emu3B->delta[1] += dy;
emu3B->flags |= EVDEV_RELATIVE_EVENTS; emu3B->flags |= EVDEV_RELATIVE_EVENTS;
if (abs(emu3B->delta[0]) > emu3B->threshold || if (fabs(emu3B->delta[0]) > emu3B->threshold ||
abs(emu3B->delta[1]) > emu3B->threshold) fabs(emu3B->delta[1]) > emu3B->threshold)
{ {
Evdev3BEmuPostButtonEvent(pInfo, 1, BUTTON_PRESS); Evdev3BEmuPostButtonEvent(pInfo, 1, BUTTON_PRESS);
Evdev3BCancel(pInfo); Evdev3BCancel(pInfo);

@ -25,6 +25,7 @@
* Adam Jackson (ajax@redhat.com) * Adam Jackson (ajax@redhat.com)
* Peter Hutterer (peter.hutterer@redhat.com) * Peter Hutterer (peter.hutterer@redhat.com)
* Oliver McFadden (oliver.mcfadden@nokia.com) * Oliver McFadden (oliver.mcfadden@nokia.com)
* Thomas H.P. Andersen (phomes@gmail.com)
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
@ -432,31 +433,36 @@ EvdevProcessValuators(InputInfoPtr pInfo)
/* Apply transformations on relative coordinates */ /* Apply transformations on relative coordinates */
if (pEvdev->rel_queued) { if (pEvdev->rel_queued) {
int deltaX = 0, deltaY = 0; double deltaX = 0, deltaY = 0;
if (valuator_mask_isset(pEvdev->rel_vals, REL_X)) if (valuator_mask_isset(pEvdev->rel_vals, REL_X))
deltaX = valuator_mask_get(pEvdev->rel_vals, REL_X); deltaX = valuator_mask_get_double(pEvdev->rel_vals, REL_X);
if (valuator_mask_isset(pEvdev->rel_vals, REL_Y)) if (valuator_mask_isset(pEvdev->rel_vals, REL_Y))
deltaY = valuator_mask_get(pEvdev->rel_vals, REL_Y); deltaY = valuator_mask_get_double(pEvdev->rel_vals, REL_Y);
if (pEvdev->swap_axes) { if (pEvdev->swap_axes) {
int tmp = deltaX; double tmp = deltaX;
deltaX = deltaY; deltaX = deltaY;
deltaY = tmp; deltaY = tmp;
} }
if (pEvdev->resolution > 0) {
deltaX *= DEFAULT_MOUSE_DPI / pEvdev->resolution;
deltaY *= DEFAULT_MOUSE_DPI / pEvdev->resolution;
}
if (pEvdev->invert_x) if (pEvdev->invert_x)
deltaX *= -1; deltaX *= -1;
if (pEvdev->invert_y) if (pEvdev->invert_y)
deltaY *= -1; deltaY *= -1;
if (deltaX) if (deltaX)
valuator_mask_set(pEvdev->rel_vals, REL_X, deltaX); valuator_mask_set_double(pEvdev->rel_vals, REL_X, deltaX);
else else
valuator_mask_unset(pEvdev->rel_vals, REL_X); valuator_mask_unset(pEvdev->rel_vals, REL_X);
if (deltaY) if (deltaY)
valuator_mask_set(pEvdev->rel_vals, REL_Y, deltaY); valuator_mask_set_double(pEvdev->rel_vals, REL_Y, deltaY);
else else
valuator_mask_unset(pEvdev->rel_vals, REL_Y); valuator_mask_unset(pEvdev->rel_vals, REL_Y);
@ -2293,6 +2299,12 @@ EvdevProbe(InputInfoPtr pInfo)
pEvdev->invert_y = xf86SetBoolOption(pInfo->options, "InvertY", FALSE); pEvdev->invert_y = xf86SetBoolOption(pInfo->options, "InvertY", FALSE);
pEvdev->swap_axes = xf86SetBoolOption(pInfo->options, "SwapAxes", FALSE); pEvdev->swap_axes = xf86SetBoolOption(pInfo->options, "SwapAxes", FALSE);
pEvdev->resolution = xf86SetIntOption(pInfo->options, "Resolution", 0);
if (pEvdev->resolution < 0) {
xf86IDrvMsg(pInfo, X_ERROR, "Resolution must be a positive number");
pEvdev->resolution = 0;
}
str = xf86CheckStrOption(pInfo->options, "Calibration", NULL); str = xf86CheckStrOption(pInfo->options, "Calibration", NULL);
if (str) { if (str) {
num_calibration = sscanf(str, "%d %d %d %d", num_calibration = sscanf(str, "%d %d %d %d",

@ -97,6 +97,8 @@
/* Number of longs needed to hold the given number of bits */ /* Number of longs needed to hold the given number of bits */
#define NLONGS(x) (((x) + LONG_BITS - 1) / LONG_BITS) #define NLONGS(x) (((x) + LONG_BITS - 1) / LONG_BITS)
#define DEFAULT_MOUSE_DPI 1000.0
/* Function key mode */ /* Function key mode */
enum fkeymode { enum fkeymode {
FKEYMODE_UNKNOWN = 0, FKEYMODE_UNKNOWN = 0,
@ -170,6 +172,7 @@ typedef struct {
BOOL swap_axes; BOOL swap_axes;
BOOL invert_x; BOOL invert_x;
BOOL invert_y; BOOL invert_y;
int resolution;
unsigned int abs_queued, rel_queued, prox_queued; unsigned int abs_queued, rel_queued, prox_queued;
@ -191,7 +194,7 @@ typedef struct {
int button; /* phys button to emit */ int button; /* phys button to emit */
int threshold; /* move threshold in dev coords */ int threshold; /* move threshold in dev coords */
OsTimerPtr timer; OsTimerPtr timer;
int delta[2]; /* delta x/y, accumulating */ double delta[2]; /* delta x/y, accumulating */
int startpos[2]; /* starting pos for abs devices */ int startpos[2]; /* starting pos for abs devices */
int flags; /* remember if we had rel or abs movement */ int flags; /* remember if we had rel or abs movement */
} emulate3B; } emulate3B;
@ -269,7 +272,7 @@ BOOL Evdev3BEmuFilterEvent(InputInfoPtr, int, BOOL);
void Evdev3BEmuPreInit(InputInfoPtr pInfo); void Evdev3BEmuPreInit(InputInfoPtr pInfo);
void Evdev3BEmuOn(InputInfoPtr); void Evdev3BEmuOn(InputInfoPtr);
void Evdev3BEmuFinalize(InputInfoPtr); void Evdev3BEmuFinalize(InputInfoPtr);
void Evdev3BEmuProcessRelMotion(InputInfoPtr pInfo, int dx, int dy); void Evdev3BEmuProcessRelMotion(InputInfoPtr pInfo, double dx, double dy);
void Evdev3BEmuProcessAbsMotion(InputInfoPtr pInfo, ValuatorMask *vals); void Evdev3BEmuProcessAbsMotion(InputInfoPtr pInfo, ValuatorMask *vals);
/* Mouse Wheel emulation */ /* Mouse Wheel emulation */

Loading…
Cancel
Save