From patchwork Sun Dec 18 20:20:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raphael Assenat X-Patchwork-Id: 9479395 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 79DD660237 for ; Sun, 18 Dec 2016 20:25:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 683CC28456 for ; Sun, 18 Dec 2016 20:25:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CA45284C8; Sun, 18 Dec 2016 20:25:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6F6328456 for ; Sun, 18 Dec 2016 20:25:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753395AbcLRUZ5 (ORCPT ); Sun, 18 Dec 2016 15:25:57 -0500 Received: from mout.perfora.net ([74.208.4.194]:60709 "EHLO mout.perfora.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753150AbcLRUZ5 (ORCPT ); Sun, 18 Dec 2016 15:25:57 -0500 Received: from yggdrasil2.lan.raphnet.net ([24.201.146.26]) by mrelay.perfora.net (mreueus002 [74.208.5.2]) with ESMTPSA (Nemesis) id 0MAOQ0-1cT70Q3VJi-00BcA8; Sun, 18 Dec 2016 21:20:52 +0100 Received: from raph by yggdrasil2.lan.raphnet.net with local (Exim 4.72) (envelope-from ) id 1cIhww-00009X-NO; Sun, 18 Dec 2016 15:20:50 -0500 Date: Sun, 18 Dec 2016 15:20:50 -0500 From: Raphael Assenat To: linux-input@vger.kernel.org Cc: Dmitry Torokhov Subject: [PATCH RESEND] Initialize axis values in joydev_open_device() Message-ID: <20161218202050.GX10002@yggdrasil2.lan.raphnet.net> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-Provags-ID: V03:K0:ERLZZe7qYBlp2ZYf20ShMHqPA4cL5Si4UutF086RA1qn/vr9Bse OIxaIfraKL+MxXDSrCeztDKdjbduILnAqnzvlgX30JREu9XgZSqgkSEzvvzWQXJHVln2f/U PCbvhO3KzViu4tWKMgC8i0TF/Xpl7N3ykGOhktv4TgiXnX2F6rrV6VhnYBV35LKC9B4ez0a o5CAIJEU/kmAtt3nAxLCA== X-UI-Out-Filterresults: notjunk:1; V01:K0:1ZKOrqga1oE=:bA5bJRA/hvH4OfcrKyUuOo urfJyHy5lDbNiQi/KcpEDtj3i7HLr482jbSPyhgi/tTmRm8o/BD0NWLsv8RvGUHlWD1IKlZL4 da+/JDn51QSAkpohZZxVtq+7G/Au5O+4aC8W7UTxRuPIQpDNcBwyWKhyjvJvbTyvRCGayuZEJ b7hGpFHKx+Ct4t/s8gcZpyL6+s/AzQjYLk4nJPVhucUVsH+knCBrbU3LIbCJ1U3VFV0hOt+15 +bW4ickrm2bl0nF8jT5X7EGMiYpLwgcCdOsYmLHZMYy1ECcwSttm75Hn1n7A1j9JU5ganHM9h dEuwiF/8b7Rotm3k0hypLwqnMzjgGpumDj6J1HlAZvqGvFvjV+DogV0mGuZ+kvMIk+zuFyMUS 3QrJBM4bNahKKjiugex/UwOqrEt7CkebmXFmwU+FAZBBlD/z+cpSrOtwfv9KTXrHIv8on5ST0 WWUGoV86yqnCClFF0WgCu+476ytPD7XG321azMw5GowQRZh02BVkWMUOaoYyjLG7ppp7GDLgF F/yFIopjIyURqnlU7FmFMDXL8gpQYhNl6ZT4IVCHzuYqQUePyFuYsxVUFSUpMoG6aXZHZL3Ur jF+bWMx3FWLYW1PocqIHn0IlqSchp9XFxjlsHumM7BunhNGUB8NzTHho7l2GkPHHaKxbuxUM6 /r9zC1PJJ6gN7DFvDnfNjED8ap1x/vEzDW4yjPgDsfBbJpcUd+x2HyP4yK9gpUAEsLUg= Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Postpone axis initialization to the first open instead of doing it once 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. 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... Unless I misunderstood the intent of JS_EVENT_INIT, I think the startup events should reflect the current state of the joystick. Please consider applying if it makes sense. Signed-off-by: Raphael Assenat --- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c index 5d11fea..5b42e5a 100644 --- a/drivers/input/joydev.c +++ b/drivers/input/joydev.c @@ -156,6 +156,38 @@ static void joydev_event(struct input_handle *handle, wake_up_interruptible(&joydev->wait); } +static void joydev_refresh_state(struct joydev *joydev) +{ + struct input_dev *dev = joydev->handle.dev; + int i, j, t; + + for (i = 0; i < joydev->nabs; i++) { + j = joydev->abspam[i]; + if (input_abs_get_max(dev, j) == input_abs_get_min(dev, j)) { + joydev->corr[i].type = JS_CORR_NONE; + joydev->abs[i] = input_abs_get_val(dev, j); + continue; + } + joydev->corr[i].type = JS_CORR_BROKEN; + joydev->corr[i].prec = input_abs_get_fuzz(dev, j); + + t = (input_abs_get_max(dev, j) + input_abs_get_min(dev, j)) / 2; + joydev->corr[i].coef[0] = t - input_abs_get_flat(dev, j); + joydev->corr[i].coef[1] = t + input_abs_get_flat(dev, j); + + t = (input_abs_get_max(dev, j) - input_abs_get_min(dev, j)) / 2 + - 2 * input_abs_get_flat(dev, j); + if (t) { + joydev->corr[i].coef[2] = (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); + } + } +} + static int joydev_fasync(int fd, struct file *file, int on) { struct joydev_client *client = file->private_data; @@ -202,6 +234,8 @@ static int joydev_open_device(struct joydev *joydev) retval = input_open_device(&joydev->handle); if (retval) joydev->open--; + else + joydev_refresh_state(joydev); } mutex_unlock(&joydev->mutex); @@ -816,7 +850,7 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id) { struct joydev *joydev; - int i, j, t, minor, dev_no; + int i, minor, dev_no; int error; minor = input_get_new_minor(JOYDEV_MINOR_BASE, JOYDEV_MINORS, true); @@ -869,31 +903,7 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev, joydev->nkey++; } - for (i = 0; i < joydev->nabs; i++) { - j = joydev->abspam[i]; - if (input_abs_get_max(dev, j) == input_abs_get_min(dev, j)) { - joydev->corr[i].type = JS_CORR_NONE; - joydev->abs[i] = input_abs_get_val(dev, j); - continue; - } - joydev->corr[i].type = JS_CORR_BROKEN; - joydev->corr[i].prec = input_abs_get_fuzz(dev, j); - - t = (input_abs_get_max(dev, j) + input_abs_get_min(dev, j)) / 2; - joydev->corr[i].coef[0] = t - input_abs_get_flat(dev, j); - joydev->corr[i].coef[1] = t + input_abs_get_flat(dev, j); - - t = (input_abs_get_max(dev, j) - input_abs_get_min(dev, j)) / 2 - - 2 * input_abs_get_flat(dev, j); - if (t) { - joydev->corr[i].coef[2] = (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); - } - } + joydev_refresh_state(joydev); joydev->dev.devt = MKDEV(INPUT_MAJOR, minor); joydev->dev.class = &input_class;