Add monitor command to change mouse cursor position when input device is in absolute mode.
Signed-off-by: Marcelo Tosatti <mtosa...@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);