[Spice-devel] [PATCH spice-gtk 7/7] Make auto-usbredir a session setting rather then a per display setting

Marc-André Lureau marcandre.lureau at gmail.com
Mon Oct 10 06:00:53 PDT 2011


ack

On Mon, Oct 10, 2011 at 2:34 PM, Hans de Goede <hdegoede at redhat.com> wrote:
> Signed-off-by: Hans de Goede <hdegoede at redhat.com>
> ---
>  gtk/spice-gtk-session.c |   55 ++++++++++++++++++++++++++++++++++++++++++++++-
>  gtk/spice-widget-priv.h |    1 -
>  gtk/spice-widget.c      |   43 ++++--------------------------------
>  gtk/spicy.c             |    6 ++--
>  4 files changed, 62 insertions(+), 43 deletions(-)
>
> diff --git a/gtk/spice-gtk-session.c b/gtk/spice-gtk-session.c
> index acc69f1..0c95e4f 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;
>  };
>
>  /**
> @@ -85,6 +90,7 @@ enum {
>     PROP_0,
>     PROP_SESSION,
>     PROP_AUTO_CLIPBOARD,
> +    PROP_AUTO_USBREDIR,
>  };
>
>  static void spice_gtk_session_init(SpiceGtkSession *self)
> @@ -202,6 +208,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;
> @@ -223,6 +232,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,26 @@ 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.
> +     *
> +     * Since: 0.10
> +     **/
> +    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.",
> +                              FALSE,
> +                              G_PARAM_READWRITE |
> +                              G_PARAM_CONSTRUCT |
> +                              G_PARAM_STATIC_STRINGS));
> +
>     g_type_class_add_private(klass, sizeof(SpiceGtkSessionPrivate));
>  }
>
> @@ -727,6 +760,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 c38da84..da3f42c 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 */
> @@ -84,7 +85,6 @@ enum {
>     PROP_MOUSE_GRAB,
>     PROP_RESIZE_GUEST,
>     PROP_AUTO_CLIPBOARD,
> -    PROP_AUTO_USBREDIR,
>     PROP_SCALING,
>  };
>
> @@ -113,7 +113,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);
>
>  /* ---------------------------------------------------------------- */
>
> @@ -146,9 +145,6 @@ static void spice_display_get_property(GObject    *object,
>         g_object_get(d->gtk_session, "auto-clipboard", &boolean, NULL);
>         g_value_set_boolean(value, boolean);
>         break;
> -    case PROP_AUTO_USBREDIR:
> -        g_value_set_boolean(value, d->auto_usbredir_enable);
> -        break;
>     case PROP_SCALING:
>         g_value_set_boolean(value, d->allow_scaling);
>        break;
> @@ -211,10 +207,6 @@ static void spice_display_set_property(GObject      *object,
>         g_object_set(d->gtk_session, "auto-clipboard",
>                      g_value_get_boolean(value), NULL);
>         break;
> -    case PROP_AUTO_USBREDIR:
> -        d->auto_usbredir_enable = g_value_get_boolean(value);
> -        update_auto_usbredir(display);
> -        break;
>     default:
>         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
>         break;
> @@ -616,22 +608,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)                                         \
> @@ -917,7 +893,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);
> @@ -941,7 +918,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;
>  }
>
> @@ -1232,17 +1210,6 @@ static void spice_display_class_init(SpiceDisplayClass *klass)
>                               G_PARAM_STATIC_STRINGS));
>
>     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_object_class_install_property
>         (gobject_class, PROP_SCALING,
>          g_param_spec_boolean("scaling", "Scaling",
>                               "Whether we should use scaling",
> diff --git a/gtk/spicy.c b/gtk/spicy.c
> index 3034dbb..e837414 100644
> --- a/gtk/spicy.c
> +++ b/gtk/spicy.c
> @@ -721,13 +721,13 @@ static const char *spice_display_properties[] = {
>     "grab-mouse",
>     "resize-guest",
>     "scaling",
> -#ifdef USE_USBREDIR
> -    "auto-usbredir",
> -#endif
>  };
>
>  static const char *spice_gtk_session_properties[] = {
>     "auto-clipboard",
> +#ifdef USE_USBREDIR
> +    "auto-usbredir",
> +#endif
>  };
>
>  static const GtkToggleActionEntry tentries[] = {
> --
> 1.7.6.4
>
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
>



-- 
Marc-André Lureau


More information about the Spice-devel mailing list