From patchwork Tue May 19 11:37:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Hellstrom X-Patchwork-Id: 6436281 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7A7B19F399 for ; Tue, 19 May 2015 11:37:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 90B8920439 for ; Tue, 19 May 2015 11:37:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8C93F204B0 for ; Tue, 19 May 2015 11:37:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754400AbbESLhU (ORCPT ); Tue, 19 May 2015 07:37:20 -0400 Received: from smtp-outbound-2.vmware.com ([208.91.2.13]:38330 "EHLO smtp-outbound-2.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754572AbbESLhT (ORCPT ); Tue, 19 May 2015 07:37:19 -0400 Received: from sc9-mailhost1.vmware.com (sc9-mailhost1.vmware.com [10.113.161.71]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id D7B802862A; Tue, 19 May 2015 04:37:18 -0700 (PDT) Received: from EX13-CAS-005.vmware.com (EX13-CAS-005.vmware.com [10.113.191.55]) by sc9-mailhost1.vmware.com (Postfix) with ESMTP id D3960182EF; Tue, 19 May 2015 04:37:18 -0700 (PDT) Received: from ubuntu.localdomain (10.113.160.246) by EX13-MBX-024.vmware.com (10.113.191.44) with Microsoft SMTP Server (TLS) id 15.0.913.22; Tue, 19 May 2015 04:37:18 -0700 From: Thomas Hellstrom To: , CC: , , "Thomas Hellstrom" Subject: [PATCH 1/2] input/joydev: Don't classify the vmmouse as a joystick Date: Tue, 19 May 2015 04:37:04 -0700 Message-ID: <1432035425-45514-2-git-send-email-thellstrom@vmware.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1432035425-45514-1-git-send-email-thellstrom@vmware.com> References: <1432035425-45514-1-git-send-email-thellstrom@vmware.com> MIME-Version: 1.0 X-Originating-IP: [10.113.160.246] X-ClientProxiedBy: EX13-CAS-013.vmware.com (10.113.191.65) To EX13-MBX-024.vmware.com (10.113.191.44) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Joydev is currently thinking some absolute mice are joystick, and that messes up games in VMware guests, as the cursor typically gets stuck in the top left corner. Try to detect the event signature of a VMmouse input device and back off for such devices. We're still incorrectly detecting, for example, the VMware absolute USB mouse as a joystick, but adding an event signature matching also that device would be considerably more risky, so defer that to a later merge window. Signed-off-by: Thomas Hellstrom --- drivers/input/joydev.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c index f362883..1ad2fb1 100644 --- a/drivers/input/joydev.c +++ b/drivers/input/joydev.c @@ -747,6 +747,42 @@ static void joydev_cleanup(struct joydev *joydev) input_close_device(handle); } +static bool joydev_dev_is_mouse(struct input_dev *dev) +{ + DECLARE_BITMAP(jd_scratch, KEY_CNT); + + BUILD_BUG_ON(ABS_CNT > KEY_CNT || EV_CNT > KEY_CNT); + + /* + * A device is, for joystick detection purposes, considered to be + * a mouse if the following is true. (This is currently tailored to + * the VMware PS/2 VMMouse device but might be extended). + * + * 1) Absolute events are exactly ABS_X and ABS_Y. + * 2) Keys are exactly BTN_LEFT, BTN_RIGHT and BTN_MIDDLE. + * 3) Event types include EV_ABS, EV_KEY and possibly EV_SYN. + */ + + bitmap_zero(jd_scratch, EV_CNT); + jd_scratch[BIT_WORD(EV_ABS)] = BIT_MASK(EV_ABS) | BIT_MASK(EV_KEY); + if (!bitmap_subset(jd_scratch, dev->evbit, EV_CNT)) + return false; + + __set_bit(EV_SYN, jd_scratch); + if (!bitmap_subset(dev->evbit, jd_scratch, EV_CNT)) + return false; + + bitmap_zero(jd_scratch, ABS_CNT); + jd_scratch[BIT_WORD(ABS_X)] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y); + if (!bitmap_equal(dev->absbit, jd_scratch, ABS_CNT)) + return false; + + bitmap_zero(jd_scratch, KEY_CNT); + jd_scratch[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) | + BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE); + + return bitmap_equal(dev->keybit, jd_scratch, KEY_CNT); +} static bool joydev_match(struct input_handler *handler, struct input_dev *dev) { @@ -758,6 +794,10 @@ static bool joydev_match(struct input_handler *handler, struct input_dev *dev) if (test_bit(EV_KEY, dev->evbit) && test_bit(BTN_DIGI, dev->keybit)) return false; + /* Avoid absolute mice */ + if (joydev_dev_is_mouse(dev)) + return false; + return true; }