qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 2/3] input-linux: add option to toggle grab on all devices
Date: Fri,  4 Mar 2016 11:25:15 +0100	[thread overview]
Message-ID: <1457087116-4379-3-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1457087116-4379-1-git-send-email-kraxel@redhat.com>

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 <kraxel@redhat.com>
---
 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 */ }
     },
-- 
1.8.3.1

  parent reply	other threads:[~2016-03-04 10:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-04 10:25 [Qemu-devel] [PATCH 0/3] input: linux evdev support Gerd Hoffmann
2016-03-04 10:25 ` [Qemu-devel] [PATCH 1/3] " Gerd Hoffmann
2016-03-04 10:25 ` Gerd Hoffmann [this message]
2016-03-04 10:25 ` [Qemu-devel] [PATCH 3/3] input-linux: add switch to enable auto-repeat events Gerd Hoffmann
2016-03-09 21:23 ` [Qemu-devel] [PATCH 0/3] input: linux evdev support Paolo Bonzini
2016-03-10  7:31   ` Gerd Hoffmann
2016-03-10  9:50     ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1457087116-4379-3-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).