From nobody Sat May 4 07:20:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1493989146269151.4495096167309; Fri, 5 May 2017 05:59:06 -0700 (PDT) Received: from localhost ([::1]:46891 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6cp6-0002dK-0n for importer@patchew.org; Fri, 05 May 2017 08:59:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48668) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6YB5-0007oa-RU for qemu-devel@nongnu.org; Fri, 05 May 2017 04:01:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6YB1-0007JW-16 for qemu-devel@nongnu.org; Fri, 05 May 2017 04:01:27 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:34199) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d6YB0-0007JI-Q8 for qemu-devel@nongnu.org; Fri, 05 May 2017 04:01:22 -0400 Received: by mail-wm0-x241.google.com with SMTP id z129so8115668wmb.1 for ; Fri, 05 May 2017 01:01:21 -0700 (PDT) Received: from tupw.localdomain (pub082136102096.dh-hfc.datazug.ch. [82.136.102.96]) by smtp.gmail.com with ESMTPSA id x26sm1342917edx.60.2017.05.05.01.01.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 May 2017 01:01:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=V7NLlv3fptmL5tWlv6bGAiapMYhNLvf4jVc87VwoL3s=; b=kJZLWg8n28lAch31LdaoI4M4UiWCw2hxXU/4gTvitNj3/9OHJ5kIoM3IRcxwRmakLC r0IGyc4UdrZ4XWuC9iR/Pq2+bhrIIuw/A/TNr2Y8sVP1SWGVul7fWdCEkBvaywhJy0OZ 37C3DrpWYwwXv5JPXIKQMsNu1sAJPhz9R4V04Q1P+7IsmudboePSpZD3ZDtUJHC8x0HL RdBbmztiebcPYcBs+0PHp2Mo5VKitNzohI5EAMwIrfEhAcXfwU0aRP+0bLFI3mvfgWOx zEMAm0m7smZLNkcw6zl1RY+lBXngVkD4Br0QjHmdGefKzJXWnk/GG40csQ2DEOL1jqn/ lcpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=V7NLlv3fptmL5tWlv6bGAiapMYhNLvf4jVc87VwoL3s=; b=bgO3v53pJBsKwoVQqa1bzz4Lp2kwlSHvFcApxqdp0uUtOqBoD4G1IpD4Xii6PIm2Sd gegSuUzfJHJ5QsIe5MyUyEA1M86/K/lK3q5Iyz/PjBRrg3xaY6j/N59zEkuUAy+5/ing MfKCCDG4FhoaXR1jjdU9DMU78PhppVybYz8P0dxVl3fhDF3dKjIL0k2EM8/W0IaV9Z9M eVI8PP8vzqXbO1yjf87mB5yINooT31EZ8Ammw+0vij8GUG16hZfG9BrvRGzIX4NSlYjS +tkyKPbQcjR+uUHwNnYt78Fjsy97NbvERNjeNtKcMTXGy3+Ba1831NdH+F3ok9kDhuMj iI7Q== X-Gm-Message-State: AN3rC/6FCELUbqB7I5K1mNY3ZGbBzDUo2rSvUqIDUP3APncGyFiD/fGp 94WVI30U+41Vog== X-Received: by 10.80.174.99 with SMTP id c90mr32675796edd.136.1493971279919; Fri, 05 May 2017 01:01:19 -0700 (PDT) From: Philippe Voinov To: qemu-devel@nongnu.org Date: Fri, 5 May 2017 09:59:18 +0200 Message-Id: <20170505075918.4033-1-philippevoinov@gmail.com> X-Mailer: git-send-email 2.12.2 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::241 X-Mailman-Approved-At: Fri, 05 May 2017 08:56:46 -0400 Subject: [Qemu-devel] [PATCH] ui: input-linux: Add absolute event support 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 , Philippe Voinov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch adds support for absolute pointer events to the input-linux subsystem. This support was omitted from the original input-linux patch, however almost all the code required for it is already in place. Support for absolute events is especially useful for guests with vga passthrough. Since they have a physical monitor, none of normal channels for sending video output (vnc, etc) are used, meaning they also can't be used to send absolute input events. This leaves QMP as the only option to send absolute input into vga passthrough guests, which is not its intended use and is not efficient. This patch allows, for example, uinput to be used to create virtual absolute input devices. This lets you build external systems which share physical input devices between guests. Without absolute input capability, such external systems can't seamlessly share pointer devices between guests. Signed-off-by: Philippe Voinov --- ui/input-linux.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/ui/input-linux.c b/ui/input-linux.c index dc0613c..7946b87 100644 --- a/ui/input-linux.c +++ b/ui/input-linux.c @@ -169,6 +169,10 @@ struct InputLinux { bool has_abs_x; int num_keys; int num_btns; + int abs_x_min; + int abs_x_max; + int abs_y_min; + int abs_y_max; struct input_event event; int read_offset; =20 @@ -268,6 +272,11 @@ static void input_linux_event_mouse_button(int button) qemu_input_event_sync(); } =20 +static void input_linux_event_abs(InputAxis axis, int value, int min, int = max) +{ + qemu_input_queue_abs(NULL, axis, value - min, max - min); +} + static void input_linux_handle_mouse(InputLinux *il, struct input_event *e= vent) { if (!il->grab_active) { @@ -314,6 +323,18 @@ static void input_linux_handle_mouse(InputLinux *il, s= truct input_event *event) break; } break; + case EV_ABS: + switch (event->code) { + case ABS_X: + input_linux_event_abs(INPUT_AXIS_X, event->value, + il->abs_x_min, il->abs_x_max); + break; + case ABS_Y: + input_linux_event_abs(INPUT_AXIS_Y, event->value, + il->abs_y_min, il->abs_y_max); + break; + } + break; case EV_SYN: qemu_input_event_sync(); if (il->wheel !=3D 0) { @@ -351,12 +372,18 @@ static void input_linux_event(void *opaque) if (il->num_keys) { input_linux_handle_keyboard(il, &il->event); } - if (il->has_rel_x && il->num_btns) { + if ((il->has_rel_x || il->has_abs_x) && il->num_btns) { input_linux_handle_mouse(il, &il->event); } } } =20 +static bool input_linux_abs_range_is_valid(int min, int max) +{ + int64_t difference =3D ((int64_t) max) - ((int64_t) min); + return difference > 0 && difference <=3D INT_MAX; +} + static void input_linux_complete(UserCreatable *uc, Error **errp) { InputLinux *il =3D INPUT_LINUX(uc); @@ -364,6 +391,7 @@ static void input_linux_complete(UserCreatable *uc, Err= or **errp) uint8_t keymap[KEY_CNT / 8], keystate[KEY_CNT / 8]; unsigned int i; int rc, ver; + struct input_absinfo absinfo; =20 if (!il->evdev) { error_setg(errp, "no input device specified"); @@ -402,6 +430,17 @@ static void input_linux_complete(UserCreatable *uc, Er= ror **errp) rc =3D ioctl(il->fd, EVIOCGBIT(EV_ABS, sizeof(absmap)), &absmap); if (absmap & (1 << ABS_X)) { il->has_abs_x =3D true; + rc =3D ioctl(il->fd, EVIOCGABS(ABS_X), &absinfo); + il->abs_x_min =3D absinfo.minimum; + il->abs_x_max =3D absinfo.maximum; + rc =3D ioctl(il->fd, EVIOCGABS(ABS_Y), &absinfo); + il->abs_y_min =3D absinfo.minimum; + il->abs_y_max =3D absinfo.maximum; + if (!input_linux_abs_range_is_valid(il->abs_x_min, il->abs_x_m= ax) || + !input_linux_abs_range_is_valid(il->abs_y_min, il->abs_y_m= ax)) { + error_setg(errp, "incompatible evdev absolute axis range"); + goto err_close; + } } } =20 --=20 2.12.2