This patch introduces the SIDE and EXTRA mouse buttons and implements
appropriate event generation for gtk and input-linux input methods.
The naming was borrowed from evdev since it is more descriptive than
BUTTON4/5.
Note that the guest has to switch the ps2 mouse into IMEX mode, otherwise
events of the extra buttons are ignored. For example on a Windows guest one
needs to manually select the "Microsoft PS/2 Mouse" driver.
Signed-off-by: Fabian Lesniak <fab...@lesniak-it.de>
---
hw/input/ps2.c | 6 ++++++
qapi-schema.json | 7 ++++++-
ui/gtk.c | 4 ++++
ui/input-linux.c | 6 ++++++
4 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/hw/input/ps2.c b/hw/input/ps2.c
index 0d14de0..7347da5 100644
--- a/hw/input/ps2.c
+++ b/hw/input/ps2.c
@@ -870,10 +870,16 @@ static void ps2_mouse_send_packet(PS2MouseState *s)
static void ps2_mouse_event(DeviceState *dev, QemuConsole *src,
InputEvent *evt)
{
+ /* the definition of MOUSE_EVENT_WHEELUP/MOUSE_EVENT_WHEELDN
+ * is ambiguous since ps2_mouse_send_packet expects the bits
+ * for buttons 4 and 5 at s->mouse_buttons & 0x18 which
+ * matches MOUSE_EVENT_WHEELUP/MOUSE_EVENT_WHEELDN */
static const int bmap[INPUT_BUTTON__MAX] = {
[INPUT_BUTTON_LEFT] = MOUSE_EVENT_LBUTTON,
[INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON,
[INPUT_BUTTON_RIGHT] = MOUSE_EVENT_RBUTTON,
+ [INPUT_BUTTON_SIDE] = MOUSE_EVENT_WHEELUP,
+ [INPUT_BUTTON_EXTRA] = MOUSE_EVENT_WHEELDN,
};
PS2MouseState *s = (PS2MouseState *)dev;
InputMoveEvent *move;
diff --git a/qapi-schema.json b/qapi-schema.json
index f3e9bfc..7f3272f 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4277,10 +4277,15 @@
#
# Button of a pointer input device (mouse, tablet).
#
+# @side: front side button of a 5-button mouse (since 2.9)
+#
+# @extra: rear side button of a 5-button mouse (since 2.9)
+#
# Since: 2.0
##
{ 'enum' : 'InputButton',
- 'data' : [ 'left', 'middle', 'right', 'wheel-up', 'wheel-down' ] }
+ 'data' : [ 'left', 'middle', 'right', 'wheel-up', 'wheel-down', 'side',
+ 'extra' ] }
##
# @InputAxis
diff --git a/ui/gtk.c b/ui/gtk.c
index e816428..9cdce83 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -995,6 +995,10 @@ static gboolean gd_button_event(GtkWidget *widget,
GdkEventButton *button,
btn = INPUT_BUTTON_MIDDLE;
} else if (button->button == 3) {
btn = INPUT_BUTTON_RIGHT;
+ } else if (button->button == 8) {
+ btn = INPUT_BUTTON_SIDE;
+ } else if (button->button == 9) {
+ btn = INPUT_BUTTON_EXTRA;
} else {
return TRUE;
}
diff --git a/ui/input-linux.c b/ui/input-linux.c
index f345317..ac31f47 100644
--- a/ui/input-linux.c
+++ b/ui/input-linux.c
@@ -291,6 +291,12 @@ static void input_linux_handle_mouse(InputLinux
*il, struct input_event *event)
qemu_input_queue_btn(NULL, INPUT_BUTTON_WHEEL_DOWN,
event->value);
break;
+ case BTN_SIDE:
+ qemu_input_queue_btn(NULL, INPUT_BUTTON_SIDE, event->value);
+ break;
+ case BTN_EXTRA:
+ qemu_input_queue_btn(NULL, INPUT_BUTTON_EXTRA, event->value);
+ break;
};
break;
case EV_REL:
--
2.10.2