summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Pouget <kpouget@redhat.com>2020-05-14 16:00:59 +0200
committerJoan Bruguera <joanbrugueram@gmail.com>2022-01-18 00:59:56 +0100
commitfe6469a27feada616f67f3eeb30a53514ed6fbd0 (patch)
tree98c4758a3709de4822efbd02d90f74f4647aff01
parent0031c57fccaa1514bea7dcef450207faba77af34 (diff)
Capture and forward side mouse buttons (BTN_SIDE and BTN_EXTRA)
Adds support for capturing and forwarding the side mouse buttons some mouses have, typically used in web browsers for previous/next website in history. (Those are presented by GDK as buttons 8 and 9.) spice-vdagent requires a corresponding patch to handle the buttons. At the spice and protocol level, the required changes were previously merged: * https://gitlab.freedesktop.org/spice/spice/-/issues/45 * https://gitlab.freedesktop.org/spice/spice/-/merge_requests/140 * https://gitlab.freedesktop.org/spice/spice-protocol/-/merge_requests/22 This commit is a rebased and revised version of the patch by Kevin Pouget: https://www.spinics.net/lists/spice-devel/msg42582.html (I have confirmed with him that it's OK that I submit the updated patches.) Co-Authored-By: Kevin Pouget <kpouget@redhat.com> Co-Authored-By: Joan Bruguera <joanbrugueram@gmail.com>
-rw-r--r--src/channel-inputs.c12
-rw-r--r--src/spice-widget.c12
2 files changed, 24 insertions, 0 deletions
diff --git a/src/channel-inputs.c b/src/channel-inputs.c
index 5e6c7b4..fcdf701 100644
--- a/src/channel-inputs.c
+++ b/src/channel-inputs.c
@@ -426,6 +426,12 @@ void spice_inputs_channel_button_press(SpiceInputsChannel *channel, gint button,
case SPICE_MOUSE_BUTTON_RIGHT:
button_state |= SPICE_MOUSE_BUTTON_MASK_RIGHT;
break;
+ case SPICE_MOUSE_BUTTON_SIDE:
+ button_state |= SPICE_MOUSE_BUTTON_MASK_SIDE;
+ break;
+ case SPICE_MOUSE_BUTTON_EXTRA:
+ button_state |= SPICE_MOUSE_BUTTON_MASK_EXTRA;
+ break;
}
c->bs = button_state;
@@ -491,6 +497,12 @@ void spice_inputs_channel_button_release(SpiceInputsChannel *channel, gint butto
case SPICE_MOUSE_BUTTON_RIGHT:
button_state &= ~SPICE_MOUSE_BUTTON_MASK_RIGHT;
break;
+ case SPICE_MOUSE_BUTTON_SIDE:
+ button_state &= ~SPICE_MOUSE_BUTTON_MASK_SIDE;
+ break;
+ case SPICE_MOUSE_BUTTON_EXTRA:
+ button_state &= ~SPICE_MOUSE_BUTTON_MASK_EXTRA;
+ break;
}
c->bs = button_state;
diff --git a/src/spice-widget.c b/src/spice-widget.c
index afcf45a..5f7c061 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -2037,6 +2037,8 @@ static int button_gdk_to_spice(guint gdk)
[ 3 ] = SPICE_MOUSE_BUTTON_RIGHT,
[ 4 ] = SPICE_MOUSE_BUTTON_UP,
[ 5 ] = SPICE_MOUSE_BUTTON_DOWN,
+ [ 8 ] = SPICE_MOUSE_BUTTON_SIDE,
+ [ 9 ] = SPICE_MOUSE_BUTTON_EXTRA,
};
if (gdk < SPICE_N_ELEMENTS(map)) {
@@ -2051,6 +2053,8 @@ static int button_gdk_to_spice_mask(guint gdk)
[1] = SPICE_MOUSE_BUTTON_MASK_LEFT,
[2] = SPICE_MOUSE_BUTTON_MASK_MIDDLE,
[3] = SPICE_MOUSE_BUTTON_MASK_RIGHT,
+ [8] = SPICE_MOUSE_BUTTON_MASK_SIDE,
+ [9] = SPICE_MOUSE_BUTTON_MASK_EXTRA,
};
if (gdk < SPICE_N_ELEMENTS(map)) {
@@ -2069,6 +2073,14 @@ static int button_mask_gdk_to_spice(int gdk)
spice |= SPICE_MOUSE_BUTTON_MASK_MIDDLE;
if (gdk & GDK_BUTTON3_MASK)
spice |= SPICE_MOUSE_BUTTON_MASK_RIGHT;
+ /* Currently, GDK does not define any mask for buttons 8 and 9
+ For X11, no mask is set at all for those buttons:
+ https://gitlab.gnome.org/GNOME/gtk/-/blob/4fff68355a22027791258b900f1f39ca1226b669/gdk/x11/gdkdevice-xi2.c#L639
+ For Wayland, masks of (1 << 15) and (1 << 16) respectively are set:
+ https://gitlab.gnome.org/GNOME/gtk/-/blob/4fff68355a22027791258b900f1f39ca1226b669/gdk/wayland/gdkdevice-wayland.c#L1703
+ While the situation is unclear, completely ignore the GTK mask for SIDE and EXTRA events.
+ Also, note that callers of this function already set/unset the mask based on the button
+ code, so not setting the mask here shouldn't have a noticeable impact anyway */
return spice;
}