[Spice-devel] [PATCH spice-gtk 1/6] spice-gtk-session: Only update usb "auto-connect" when doing "auto-usb-redir"

Hans de Goede hdegoede at redhat.com
Tue Jun 26 04:48:59 PDT 2012


Only update the UsbDeviceManager's "auto-connect" property when
"auto-usb-redir" is set, otherwise leave it as is. This allows apps to
control UsbDeviceManager's "auto-connect" directly, without it getting reset
on every keyboard focus change.

Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 gtk/spice-gtk-session.c  |   23 ++++++++++++++++-------
 gtk/usb-device-manager.c |    5 +++++
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/gtk/spice-gtk-session.c b/gtk/spice-gtk-session.c
index 3d2483d..130cbc9 100644
--- a/gtk/spice-gtk-session.c
+++ b/gtk/spice-gtk-session.c
@@ -235,7 +235,16 @@ static void spice_gtk_session_set_property(GObject      *gobject,
         break;
     case PROP_AUTO_USBREDIR:
         s->auto_usbredir_enable = g_value_get_boolean(value);
-        spice_gtk_session_update_keyboard_focus(self, s->keyboard_focus);
+        if (s->keyboard_focus) {
+            SpiceUsbDeviceManager *manager =
+                spice_usb_device_manager_get(s->session, NULL);
+
+            if (!manager)
+                break;
+
+            g_object_set(manager, "auto-connect", s->auto_usbredir_enable,
+                         NULL);
+        }
         break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
@@ -835,17 +844,17 @@ void spice_gtk_session_update_keyboard_focus(SpiceGtkSession *self,
 
     SpiceGtkSessionPrivate *s = self->priv;
     SpiceUsbDeviceManager *manager;
-    gboolean auto_connect = FALSE;
 
     s->keyboard_focus = state;
 
-    if (s->auto_usbredir_enable && s->keyboard_focus)
-        auto_connect = TRUE;
+    if (!s->auto_usbredir_enable)
+        return;
 
     manager = spice_usb_device_manager_get(s->session, NULL);
-    if (manager) {
-        g_object_set(manager, "auto-connect", auto_connect, NULL);
-    }
+    if (!manager)
+        return;
+
+    g_object_set(manager, "auto-connect", state, NULL);
 }
 
 /* ------------------------------------------------------------------ */
diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index 25cb14a..b39c2d4 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -341,6 +341,11 @@ static void spice_usb_device_manager_class_init(SpiceUsbDeviceManagerClass *klas
 
     /**
      * SpiceUsbDeviceManager:auto-connect:
+     *
+     * Set this to TRUE to automatically redirect newly plugged in device.
+     *
+     * Note when #SpiceGtkSession's auto-usbredir property is TRUE, this
+     * property is controlled by #SpiceGtkSession.
      */
     pspec = g_param_spec_boolean("auto-connect", "Auto Connect",
                                  "Auto connect plugged in USB devices",
-- 
1.7.10.4



More information about the Spice-devel mailing list