Signed-off-by: Hans de Goede <hdego...@redhat.com> --- gtk/spice-gtk-session.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++- gtk/spice-widget-priv.h | 1 - gtk/spice-widget.c | 40 +++++++++++++++------------------- 3 files changed, 71 insertions(+), 24 deletions(-)
diff --git a/gtk/spice-gtk-session.c b/gtk/spice-gtk-session.c index d3cdd7d..35c01c8 100644 --- a/gtk/spice-gtk-session.c +++ b/gtk/spice-gtk-session.c @@ -20,13 +20,15 @@ #include <spice/vd_agent.h> #include "spice-common.h" #include "spice-gtk-session.h" +#include "spice-gtk-session-priv.h" #define CLIPBOARD_LAST (VD_AGENT_CLIPBOARD_SELECTION_SECONDARY + 1) struct _SpiceGtkSessionPrivate { SpiceSession *session; - SpiceMainChannel *main; + /* Clipboard related */ gboolean auto_clipboard_enable; + SpiceMainChannel *main; GtkClipboard *clipboard; GtkClipboard *clipboard_primary; GtkTargetEntry *clip_targets[CLIPBOARD_LAST]; @@ -35,6 +37,9 @@ struct _SpiceGtkSessionPrivate { gboolean clip_grabbed[CLIPBOARD_LAST]; gboolean clipboard_by_guest[CLIPBOARD_LAST]; gboolean clipboard_selfgrab_pending[CLIPBOARD_LAST]; + /* auto-usbredir related */ + gboolean auto_usbredir_enable; + gboolean keyboard_focus; }; /** @@ -88,6 +93,7 @@ enum { PROP_0, PROP_SESSION, PROP_AUTO_CLIPBOARD, + PROP_AUTO_USBREDIR, }; static void spice_gtk_session_init(SpiceGtkSession *self) @@ -205,6 +211,9 @@ static void spice_gtk_session_get_property(GObject *gobject, case PROP_AUTO_CLIPBOARD: g_value_set_boolean(value, s->auto_clipboard_enable); break; + case PROP_AUTO_USBREDIR: + g_value_set_boolean(value, s->auto_usbredir_enable); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec); break; @@ -226,6 +235,10 @@ static void spice_gtk_session_set_property(GObject *gobject, case PROP_AUTO_CLIPBOARD: s->auto_clipboard_enable = g_value_get_boolean(value); break; + case PROP_AUTO_USBREDIR: + s->auto_usbredir_enable = g_value_get_boolean(value); + spice_gtk_session_update_keyboard_focus(self, s->keyboard_focus); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec); break; @@ -275,6 +288,25 @@ static void spice_gtk_session_class_init(SpiceGtkSessionClass *klass) G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); + /** + * SpiceGtkSession:auto-usbredir: + * + * Automatically redirect newly plugged in USB devices. Note the auto + * redirection only happens when a #SpiceDisplay associated with the + * session had keyboard focus. + * + **/ + g_object_class_install_property + (gobject_class, PROP_AUTO_USBREDIR, + g_param_spec_boolean("auto-usbredir", + "Auto USB Redirection", + "Automatically redirect newly plugged in USB" + "Devices to the guest.", + TRUE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + G_PARAM_STATIC_STRINGS)); + g_type_class_add_private(klass, sizeof(SpiceGtkSessionPrivate)); } @@ -727,6 +759,26 @@ static void channel_destroy(SpiceSession *session, SpiceChannel *channel, } } +/* ---------------------------------------------------------------- */ +/* private functions (usbredir related) */ +void spice_gtk_session_update_keyboard_focus(SpiceGtkSession *self, + gboolean state) +{ + SpiceGtkSessionPrivate *s = SPICE_GTK_SESSION_GET_PRIVATE(self); + SpiceUsbDeviceManager *manager; + gboolean auto_connect = FALSE; + + s->keyboard_focus = state; + + if (s->auto_usbredir_enable && s->keyboard_focus) + auto_connect = TRUE; + + manager = spice_usb_device_manager_get(s->session, NULL, NULL); + if (manager) { + g_object_set(manager, "auto-connect", auto_connect, NULL); + } +} + /* ------------------------------------------------------------------ */ /* public functions */ diff --git a/gtk/spice-widget-priv.h b/gtk/spice-widget-priv.h index f94c8c6..a5791a4 100644 --- a/gtk/spice-widget-priv.h +++ b/gtk/spice-widget-priv.h @@ -48,7 +48,6 @@ struct _SpiceDisplayPrivate { bool keyboard_grab_enable; bool mouse_grab_enable; bool resize_guest_enable; - bool auto_usbredir_enable; /* state */ enum SpiceSurfaceFmt format; diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c index 06e5113..e1483fd 100644 --- a/gtk/spice-widget.c +++ b/gtk/spice-widget.c @@ -32,6 +32,7 @@ #include "spice-widget.h" #include "spice-widget-priv.h" +#include "spice-gtk-session-priv.h" #include "vncdisplaykeymap.h" /* Some compatibility defines to let us build on both Gtk2 and Gtk3 */ @@ -118,7 +119,6 @@ static void disconnect_display(SpiceDisplay *display); static void channel_new(SpiceSession *s, SpiceChannel *channel, gpointer data); static void channel_destroy(SpiceSession *s, SpiceChannel *channel, gpointer data); static void sync_keyboard_lock_modifiers(SpiceDisplay *display); -static void update_auto_usbredir(SpiceDisplay *display); /* ---------------------------------------------------------------- */ @@ -152,7 +152,8 @@ static void spice_display_get_property(GObject *object, g_value_set_boolean(value, boolean); break; case PROP_AUTO_USBREDIR: - g_value_set_boolean(value, d->auto_usbredir_enable); + g_object_get(d->gtk_session, "auto-usbredir", &boolean, NULL); + g_value_set_boolean(value, boolean); break; case PROP_SCALING: g_value_set_boolean(value, d->allow_scaling); @@ -217,8 +218,8 @@ static void spice_display_set_property(GObject *object, g_value_get_boolean(value), NULL); break; case PROP_AUTO_USBREDIR: - d->auto_usbredir_enable = g_value_get_boolean(value); - update_auto_usbredir(display); + g_object_set(d->gtk_session, "auto-usbredir", + g_value_get_boolean(value), NULL); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); @@ -340,6 +341,8 @@ spice_display_constructor(GType gtype, g_signal_connect(d->gtk_session, "notify::auto-clipboard", G_CALLBACK(gtk_session_property_changed), display); + g_signal_connect(d->gtk_session, "notify::auto-usbredir", + G_CALLBACK(gtk_session_property_changed), display); return obj; } @@ -621,22 +624,6 @@ static void recalc_geometry(GtkWidget *widget, gboolean set_display) } } -static void update_auto_usbredir(SpiceDisplay *display) -{ - SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display); - SpiceUsbDeviceManager *manager; - gboolean auto_connect = FALSE; - - if (d->auto_usbredir_enable && d->keyboard_have_focus) - auto_connect = TRUE; - - /* FIXME: allow specifying a different GMainContext then the default */ - manager = spice_usb_device_manager_get(d->session, NULL /* FIXME */, NULL); - if (manager) { - g_object_set(manager, "auto-connect", auto_connect, NULL); - } -} - /* ---------------------------------------------------------------- */ #define CONVERT_0565_TO_0888(s) \ @@ -922,7 +909,8 @@ static gboolean focus_in_event(GtkWidget *widget, GdkEventFocus *focus G_GNUC_UN sync_keyboard_lock_modifiers(display); d->keyboard_have_focus = true; try_keyboard_grab(display); - update_auto_usbredir(display); + spice_gtk_session_update_keyboard_focus(d->gtk_session, + d->keyboard_have_focus); #ifdef WIN32 focus_window = GDK_WINDOW_HWND(gtk_widget_get_window(widget)); g_return_val_if_fail(focus_window != NULL, true); @@ -946,7 +934,8 @@ static gboolean focus_out_event(GtkWidget *widget, GdkEventFocus *focus G_GNUC_U release_keys(display); d->keyboard_have_focus = false; - update_auto_usbredir(display); + spice_gtk_session_update_keyboard_focus(d->gtk_session, + d->keyboard_have_focus); return true; } @@ -1234,6 +1223,13 @@ static void spice_display_class_init(SpiceDisplayClass *klass) G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); + /** + * SpiceDisplay:auto-usbredir: + * + * Automatically redirect newly plugged in USB devices. Note the auto + * redirection only happens when the widget has keyboard focus. + * + **/ g_object_class_install_property (gobject_class, PROP_AUTO_USBREDIR, g_param_spec_boolean("auto-usbredir", -- 1.7.6.4 _______________________________________________ Spice-devel mailing list Spice-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/spice-devel