From patchwork Wed Apr 13 15:45:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 8823981 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1D317C0553 for ; Wed, 13 Apr 2016 15:50:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7755D2025B for ; Wed, 13 Apr 2016 15:50:02 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BFA62200E3 for ; Wed, 13 Apr 2016 15:50:01 +0000 (UTC) Received: from localhost ([::1]:46181 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aqN3J-0003gQ-2p for patchwork-qemu-devel@patchwork.kernel.org; Wed, 13 Apr 2016 11:50:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33404) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aqMyi-0001WA-IQ for qemu-devel@nongnu.org; Wed, 13 Apr 2016 11:45:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aqMya-0004nk-Ap for qemu-devel@nongnu.org; Wed, 13 Apr 2016 11:45:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39919) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aqMya-0004nB-6F for qemu-devel@nongnu.org; Wed, 13 Apr 2016 11:45:08 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CB2507AE9D for ; Wed, 13 Apr 2016 15:45:07 +0000 (UTC) Received: from nilsson.home.kraxel.org (ovpn-116-24.ams2.redhat.com [10.36.116.24]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3DFj6Ig025804; Wed, 13 Apr 2016 11:45:07 -0400 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 984658279D; Wed, 13 Apr 2016 17:45:05 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 13 Apr 2016 17:45:02 +0200 Message-Id: <1460562303-17079-9-git-send-email-kraxel@redhat.com> In-Reply-To: <1460562303-17079-1-git-send-email-kraxel@redhat.com> References: <1460562303-17079-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 8/9] input-linux: refine mouse detection X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 Read absolute and relative axis information, only classify devices as mouse/tablet in case the x axis is present. Signed-off-by: Gerd Hoffmann --- ui/input-linux.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/ui/input-linux.c b/ui/input-linux.c index 9c921cc..1d33b5c 100644 --- a/ui/input-linux.c +++ b/ui/input-linux.c @@ -337,7 +337,7 @@ static void input_linux_event_mouse(void *opaque) static void input_linux_complete(UserCreatable *uc, Error **errp) { InputLinux *il = INPUT_LINUX(uc); - uint32_t evtmap; + uint32_t evtmap, relmap, absmap; int rc, ver; if (!il->evdev) { @@ -359,16 +359,36 @@ static void input_linux_complete(UserCreatable *uc, Error **errp) } rc = ioctl(il->fd, EVIOCGBIT(0, sizeof(evtmap)), &evtmap); + if (rc < 0) { + error_setg(errp, "%s: failed to read event bits", il->evdev); + goto err_close; + } if (evtmap & (1 << EV_REL)) { - /* has relative axis -> assume mouse */ + rc = ioctl(il->fd, EVIOCGBIT(EV_REL, sizeof(relmap)), &relmap); + if (rc < 0) { + relmap = 0; + } + } + + if (evtmap & (1 << EV_ABS)) { + ioctl(il->fd, EVIOCGBIT(EV_ABS, sizeof(absmap)), &absmap); + if (rc < 0) { + absmap = 0; + } + } + + if ((evtmap & (1 << EV_REL)) && + (relmap & (1 << REL_X))) { + /* has relative x axis -> assume mouse */ qemu_set_fd_handler(il->fd, input_linux_event_mouse, NULL, il); - } else if (evtmap & (1 << EV_ABS)) { - /* has absolute axis -> not supported */ + } else if ((evtmap & (1 << EV_ABS)) && + (absmap & (1 << ABS_X))) { + /* has absolute x axis -> not supported */ error_setg(errp, "tablet/touchscreen not supported"); goto err_close; } else if (evtmap & (1 << EV_KEY)) { - /* has keys/buttons (and no axis) -> assume keyboard */ + /* has keys/buttons (and no x axis) -> assume keyboard */ qemu_set_fd_handler(il->fd, input_linux_event_keyboard, NULL, il); } else { /* Huh? What is this? */