Commit 45536d37 authored by Raphael Assenat's avatar Raphael Assenat Committed by Dmitry Torokhov

Input: joydev - do not report stale values on first open

Postpone axis initialization to the first open instead of doing it
in joydev_connect. This is to make sure the generated startup events
are representative of the current joystick state rather than what
it was when joydev_connect() was called, potentially much earlier.
Once the first user is connected to joydev node we'll be updating
joydev->abs[] values and subsequent clients will be getting correct
initial states as well.

This solves issues with joystick driven menus that start scrolling
up each time they are started, until the user moves the joystick to
generate events. In emulator menu setups where the menu program is
restarted every time the game exits, the repeated need to move the
joystick to stop the unintended scrolling gets old rather quickly...
Signed-off-by: default avatarRaphael Assenat <raph@raphnet.net>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 81dec809
...@@ -187,6 +187,17 @@ static void joydev_detach_client(struct joydev *joydev, ...@@ -187,6 +187,17 @@ static void joydev_detach_client(struct joydev *joydev,
synchronize_rcu(); synchronize_rcu();
} }
static void joydev_refresh_state(struct joydev *joydev)
{
struct input_dev *dev = joydev->handle.dev;
int i, val;
for (i = 0; i < joydev->nabs; i++) {
val = input_abs_get_val(dev, joydev->abspam[i]);
joydev->abs[i] = joydev_correct(val, &joydev->corr[i]);
}
}
static int joydev_open_device(struct joydev *joydev) static int joydev_open_device(struct joydev *joydev)
{ {
int retval; int retval;
...@@ -201,6 +212,8 @@ static int joydev_open_device(struct joydev *joydev) ...@@ -201,6 +212,8 @@ static int joydev_open_device(struct joydev *joydev)
retval = input_open_device(&joydev->handle); retval = input_open_device(&joydev->handle);
if (retval) if (retval)
joydev->open--; joydev->open--;
else
joydev_refresh_state(joydev);
} }
mutex_unlock(&joydev->mutex); mutex_unlock(&joydev->mutex);
...@@ -872,7 +885,6 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev, ...@@ -872,7 +885,6 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev,
j = joydev->abspam[i]; j = joydev->abspam[i];
if (input_abs_get_max(dev, j) == input_abs_get_min(dev, j)) { if (input_abs_get_max(dev, j) == input_abs_get_min(dev, j)) {
joydev->corr[i].type = JS_CORR_NONE; joydev->corr[i].type = JS_CORR_NONE;
joydev->abs[i] = input_abs_get_val(dev, j);
continue; continue;
} }
joydev->corr[i].type = JS_CORR_BROKEN; joydev->corr[i].type = JS_CORR_BROKEN;
...@@ -887,10 +899,6 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev, ...@@ -887,10 +899,6 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev,
if (t) { if (t) {
joydev->corr[i].coef[2] = (1 << 29) / t; joydev->corr[i].coef[2] = (1 << 29) / t;
joydev->corr[i].coef[3] = (1 << 29) / t; joydev->corr[i].coef[3] = (1 << 29) / t;
joydev->abs[i] =
joydev_correct(input_abs_get_val(dev, j),
joydev->corr + i);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment