[RFC/POC PATCH spice-gtk 12/16] Use the new output_id as display ID for the mouse motion event

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If the output_id is set, it is the true xrandr guest ID to use for the
mouse motion event. If it's not present, keep relying on the wacky
sequence of IDs of channel_id + monitor_id.
---
 src/spice-widget.c | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/src/spice-widget.c b/src/spice-widget.c
index 72f5334..cdda8db 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -220,6 +220,12 @@ static void update_keyboard_focus(SpiceDisplay *display, gboolean state)
     spice_gtk_session_request_auto_usbredir(d->gtk_session, state);
 }
 
+/*
+ * This function assumes either channel_id or monitor_id is always 0. Under
+ * this assumption, the code is equal to channel_id + monitor_id. Therefore the
+ * result can be used with spice_main_channel_update_display{,_enabled}()
+ * functions.
+ */
 static gint get_display_id(SpiceDisplay *display)
 {
     SpiceDisplayPrivate *d = display->priv;
@@ -233,6 +239,28 @@ static gint get_display_id(SpiceDisplay *display)
     return d->channel_id;
 }
 
+/*
+ * Use output ID for mouse input if it is present in the monitor config. It is
+ * the correct ID from the guest, set by the streaming agent for streaming
+ * channels. If we don't find it, fall back to the old way of channel_id +
+ * monitor_id, which, under the assumptions we make, should be a sequence
+ * starting from 0 and with no collisions.
+ */
+static gint get_mouse_input_display_id(SpiceDisplay *display)
+{
+    SpiceDisplayPrivate *d = display->priv;
+
+    SpiceMonitorConfig *mc = spice_session_find_monitor_config(d->session, d->channel_id, d->monitor_id);
+
+    if (mc && mc->output_id) {
+        // output IDs are a sequence starting from 1 (0 meaning it is unset),
+        // but the mouse motion event expects zero-based IDs
+        return mc->output_id - 1;
+    }
+
+    return get_display_id(display);
+}
+
 static bool egl_enabled(SpiceDisplayPrivate *d)
 {
 #if HAVE_EGL
@@ -1980,7 +2008,7 @@ static gboolean motion_event(GtkWidget *widget, GdkEventMotion *motion)
     case SPICE_MOUSE_MODE_CLIENT:
         if (x >= 0 && x < d->area.width &&
             y >= 0 && y < d->area.height) {
-            spice_inputs_channel_position(d->inputs, x, y, get_display_id(display),
+            spice_inputs_channel_position(d->inputs, x, y, get_mouse_input_display_id(display),
                                           button_mask_gdk_to_spice(motion->state));
         }
         break;
-- 
2.17.1

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]