All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: qemu-devel <qemu-devel@nongnu.org>
Subject: [Qemu-devel] [PATCH] add command to position mouse pointer in absolute mode
Date: Thu, 5 Jun 2014 20:25:29 -0300	[thread overview]
Message-ID: <20140605232528.GA2566@amt.cnet> (raw)


Add monitor command to change mouse cursor position when input 
device is in absolute mode.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

---
 hmp-commands.hx |   22 +++++++++++++++++++---
 monitor.c       |   35 ++++++++++++++++++++++++++++++++++-
 2 files changed, 53 insertions(+), 4 deletions(-)

Index: qemu/hmp-commands.hx
===================================================================
--- qemu.orig/hmp-commands.hx	2014-06-05 20:21:32.310919549 -0300
+++ qemu/hmp-commands.hx	2014-06-05 20:21:44.582879764 -0300
@@ -703,18 +703,34 @@
         .name       = "mouse_move",
         .args_type  = "dx_str:s,dy_str:s,dz_str:s?",
         .params     = "dx dy [dz]",
-        .help       = "send mouse move events",
-        .mhandler.cmd = do_mouse_move,
+        .help       = "send mouse move events (relative coordinates)",
+        .mhandler.cmd = do_mouse_move_rel,
     },
 
 STEXI
 @item mouse_move @var{dx} @var{dy} [@var{dz}]
 @findex mouse_move
-Move the active mouse to the specified coordinates @var{dx} @var{dy}
+Move the active mouse to the specified relative coordinates @var{dx} @var{dy}
 with optional scroll axis @var{dz}.
 ETEXI
 
     {
+        .name       = "mouse_move_abs",
+        .args_type  = "dx_str:s,dy_str:s,dz_str:s?",
+        .params     = "dx dy [dz]",
+        .help       = "send mouse move events (absolute coordinates)",
+        .mhandler.cmd = do_mouse_move_abs,
+    },
+
+STEXI
+@item mouse_move_abs @var{dx} @var{dy} [@var{dz}]
+@findex mouse_move_abs
+Move the active mouse to the specified absolute coordinates @var{dx} @var{dy}
+with optional scroll axis @var{dz}.
+ETEXI
+
+
+    {
         .name       = "mouse_button",
         .args_type  = "button_state:i",
         .params     = "state",
Index: qemu/monitor.c
===================================================================
--- qemu.orig/monitor.c	2014-06-05 20:21:32.313919539 -0300
+++ qemu/monitor.c	2014-06-05 20:21:44.583879761 -0300
@@ -1436,7 +1436,7 @@
 
 static int mouse_button_state;
 
-static void do_mouse_move(Monitor *mon, const QDict *qdict)
+static void do_mouse_move_rel(Monitor *mon, const QDict *qdict)
 {
     int dx, dy, dz, button;
     const char *dx_str = qdict_get_str(qdict, "dx_str");
@@ -1450,6 +1450,39 @@
 
     if (dz_str) {
         dz = strtol(dz_str, NULL, 0);
+        if (dz != 0) {
+            button = (dz > 0) ? INPUT_BUTTON_WHEEL_UP : INPUT_BUTTON_WHEEL_DOWN;
+            qemu_input_queue_btn(NULL, button, true);
+            qemu_input_event_sync();
+            qemu_input_queue_btn(NULL, button, false);
+        }
+    }
+    qemu_input_event_sync();
+}
+
+static void do_mouse_move_abs(Monitor *mon, const QDict *qdict)
+{
+    int dx, dy, dz, button;
+    const char *dx_str = qdict_get_str(qdict, "dx_str");
+    const char *dy_str = qdict_get_str(qdict, "dy_str");
+    const char *dz_str = qdict_get_try_str(qdict, "dz_str");
+    int weight, height;
+
+    weight = qemu_console_get_width(NULL, 0);
+    height = qemu_console_get_height(NULL, 0);
+
+    if (!height || !weight) {
+        monitor_printf(mon, "failed to retrieve active console size\n");
+        return;
+    }
+
+    dx = strtol(dx_str, NULL, 0);
+    dy = strtol(dy_str, NULL, 0);
+    qemu_input_queue_abs(NULL, INPUT_AXIS_X, dx, weight);
+    qemu_input_queue_abs(NULL, INPUT_AXIS_Y, dy, height);
+
+    if (dz_str) {
+        dz = strtol(dz_str, NULL, 0);
         if (dz != 0) {
             button = (dz > 0) ? INPUT_BUTTON_WHEEL_UP : INPUT_BUTTON_WHEEL_DOWN;
             qemu_input_queue_btn(NULL, button, true);

             reply	other threads:[~2014-06-05 23:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-05 23:25 Marcelo Tosatti [this message]
2014-06-10  8:25 ` [Qemu-devel] [PATCH] add command to position mouse pointer in absolute mode Gerd Hoffmann
2014-06-10 11:48   ` Marcelo Tosatti
2014-06-10 11:53     ` Marcelo Tosatti
2014-06-10 12:19       ` Gerd Hoffmann
2014-06-10 12:38   ` Eric Blake
2014-06-12  7:12   ` Markus Armbruster

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=20140605232528.GA2566@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.