From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35428) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a8TxF-0004yo-BC for qemu-devel@nongnu.org; Mon, 14 Dec 2015 09:18:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a8TxA-0001xn-Bf for qemu-devel@nongnu.org; Mon, 14 Dec 2015 09:18:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43387) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a8TxA-0001xi-6N for qemu-devel@nongnu.org; Mon, 14 Dec 2015 09:18:16 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id E154332D3AD for ; Mon, 14 Dec 2015 14:18:15 +0000 (UTC) From: Gerd Hoffmann Date: Mon, 14 Dec 2015 15:18:06 +0100 Message-Id: <1450102686-23855-3-git-send-email-kraxel@redhat.com> In-Reply-To: <1450102686-23855-1-git-send-email-kraxel@redhat.com> References: <1450102686-23855-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH v2 3/3] input-linux: add option to toggle grab on all devices List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: vfio-users@redhat.com, Gerd Hoffmann 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 fdedf0b..1b43eef 100644 --- a/ui/input-linux.c +++ b/ui/input-linux.c @@ -20,14 +20,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); @@ -35,6 +40,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) @@ -114,6 +132,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) { @@ -168,6 +191,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; @@ -204,6 +229,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: @@ -221,6 +247,9 @@ static QemuOptsList qemu_input_linux_opts = { { .name = "evdev", .type = QEMU_OPT_STRING, + },{ + .name = "grab-all", + .type = QEMU_OPT_BOOL, }, { /* end of list */ } }, -- 1.8.3.1