From patchwork Fri Mar 4 10:25:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 8501991 Return-Path: X-Original-To: patchwork-qemu-devel@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 330539F38C for ; Fri, 4 Mar 2016 10:28:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8DAD9201CE for ; Fri, 4 Mar 2016 10:28:41 +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 D309B201C8 for ; Fri, 4 Mar 2016 10:28:40 +0000 (UTC) Received: from localhost ([::1]:40117 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abmyO-000514-7i for patchwork-qemu-devel@patchwork.kernel.org; Fri, 04 Mar 2016 05:28:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50848) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abmvI-0008Li-Fa for qemu-devel@nongnu.org; Fri, 04 Mar 2016 05:25:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1abmvH-0007BO-It for qemu-devel@nongnu.org; Fri, 04 Mar 2016 05:25:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41440) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abmvH-0007BB-Ds for qemu-devel@nongnu.org; Fri, 04 Mar 2016 05:25:27 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 21CB6C00F212 for ; Fri, 4 Mar 2016 10:25:27 +0000 (UTC) Received: from nilsson.home.kraxel.org (ovpn-116-34.ams2.redhat.com [10.36.116.34]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u24APQ4K024227; Fri, 4 Mar 2016 05:25:26 -0500 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 30CE9816A2; Fri, 4 Mar 2016 11:25:25 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 4 Mar 2016 11:25:15 +0100 Message-Id: <1457087116-4379-3-git-send-email-kraxel@redhat.com> In-Reply-To: <1457087116-4379-1-git-send-email-kraxel@redhat.com> References: <1457087116-4379-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 2/3] input-linux: add option to toggle grab on all devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org 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 Maintain a list of all input devices. Add an option to make grab work across all devices (so toggling grab on the keybard can switch over the mouse too). Signed-off-by: Gerd Hoffmann --- ui/input-linux.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/ui/input-linux.c b/ui/input-linux.c index 5374a2e..ad43963 100644 --- a/ui/input-linux.c +++ b/ui/input-linux.c @@ -134,14 +134,19 @@ struct InputLinux { int fd; bool grab_request; bool grab_active; + bool grab_all; bool keydown[KEY_CNT]; int keycount; int wheel; + QTAILQ_ENTRY(InputLinux) next; }; +static QTAILQ_HEAD(, InputLinux) inputs = QTAILQ_HEAD_INITIALIZER(inputs); + static void input_linux_toggle_grab(InputLinux *il) { intptr_t request = !il->grab_active; + InputLinux *item; int rc; rc = ioctl(il->fd, EVIOCGRAB, request); @@ -149,6 +154,19 @@ static void input_linux_toggle_grab(InputLinux *il) return; } il->grab_active = !il->grab_active; + + if (!il->grab_all) { + return; + } + QTAILQ_FOREACH(item, &inputs, next) { + if (item == il || item->grab_all) { + /* avoid endless loops */ + continue; + } + if (item->grab_active != il->grab_active) { + input_linux_toggle_grab(item); + } + } } static void input_linux_event_keyboard(void *opaque) @@ -238,6 +256,11 @@ static void input_linux_event_mouse(void *opaque) break; } + /* only send event to guest when grab is active */ + if (!il->grab_active) { + continue; + } + switch (event.type) { case EV_KEY: switch (event.code) { @@ -292,6 +315,8 @@ int input_linux_init(void *opaque, QemuOpts *opts, Error **errp) int rc, ver; il->evdev = qemu_opt_get(opts, "evdev"); + il->grab_all = qemu_opt_get_bool(opts, "grab-all", false); + if (!il->evdev) { error_setg(errp, "no input device specified"); goto err_free; @@ -328,6 +353,7 @@ int input_linux_init(void *opaque, QemuOpts *opts, Error **errp) goto err_close; } input_linux_toggle_grab(il); + QTAILQ_INSERT_TAIL(&inputs, il, next); return 0; err_close: @@ -345,6 +371,9 @@ static QemuOptsList qemu_input_linux_opts = { { .name = "evdev", .type = QEMU_OPT_STRING, + },{ + .name = "grab-all", + .type = QEMU_OPT_BOOL, }, { /* end of list */ } },