[Spice-devel] [PATCH spice-gtk 1/2] cursor: Add cursor shape property

Christophe Fergeau cfergeau at redhat.com
Tue May 23 09:08:54 UTC 2017


On Fri, May 12, 2017 at 01:00:00PM +0200, Pavel Grunt wrote:
> It provides information about the remote cursor similar to the signal
> "cursor-set". The benefit over the signal is that the property can be
> queried at any time.
> 
> Users of the "cursor-set" signal should migrate to "notify::cursor".

> 
> Related:
> https://bugzilla.redhat.com/show_bug.cgi?id=1411380
> ---
>  doc/reference/spice-gtk-sections.txt |  3 ++
>  src/channel-cursor.c                 | 99 +++++++++++++++++++++++++++++++++++-
>  src/channel-cursor.h                 | 25 +++++++++
>  src/map-file                         |  1 +
>  src/spice-glib-sym-file              |  1 +
>  src/spice-widget.c                   | 31 ++++++-----
>  6 files changed, 144 insertions(+), 16 deletions(-)
> 
> diff --git a/doc/reference/spice-gtk-sections.txt b/doc/reference/spice-gtk-sections.txt
> index 6f49df3..82c930e 100644
> --- a/doc/reference/spice-gtk-sections.txt
> +++ b/doc/reference/spice-gtk-sections.txt
> @@ -180,6 +180,8 @@ SPICE_IS_DISPLAY_CHANNEL_CLASS
>  SPICE_DISPLAY_CHANNEL_GET_CLASS
>  SPICE_TYPE_GL_SCANOUT
>  spice_gl_scanout_get_type
> +SPICE_TYPE_CURSOR_SHAPE
> +spice_cursor_shape_get_type
>  <SUBSECTION Private>
>  SpiceDisplayChannelPrivate
>  </SECTION>
> @@ -189,6 +191,7 @@ SpiceDisplayChannelPrivate
>  <TITLE>SpiceCursorChannel</TITLE>
>  SpiceCursorChannel
>  SpiceCursorChannelClass
> +SpiceCursorShape
>  <SUBSECTION Standard>
>  SPICE_CURSOR_CHANNEL
>  SPICE_IS_CURSOR_CHANNEL
> diff --git a/src/channel-cursor.c b/src/channel-cursor.c
> index 609243b..25ba366 100644
> --- a/src/channel-cursor.c
> +++ b/src/channel-cursor.c
> @@ -36,8 +36,9 @@
>   * The Spice protocol defines a set of messages for controlling cursor
>   * shape and position on the remote display area. The cursor changes
>   * that should be reflected on the display are notified by
> - * signals. See for example #SpiceCursorChannel::cursor-set
> - * #SpiceCursorChannel::cursor-move signals.
> + * signals. See for example #SpiceCursorChannel::cursor-set and
> + * #SpiceCursorChannel::cursor-move signals and the #SpiceCursorChannel:cursor
> + * property.
>   */
>  
>  #define SPICE_CURSOR_CHANNEL_GET_PRIVATE(obj)                                  \
> @@ -55,6 +56,13 @@ struct display_cursor {
>  struct _SpiceCursorChannelPrivate {
>      display_cache               *cursors;
>      gboolean                    init_done;
> +    SpiceCursorShape            last_cursor;
> +};
> +
> +/* Properties */
> +enum {
> +    PROP_0,
> +    PROP_CURSOR,
>  };
>  
>  enum {
> @@ -74,7 +82,30 @@ static void channel_set_handlers(SpiceChannelClass *klass);
>  
>  G_DEFINE_TYPE(SpiceCursorChannel, spice_cursor_channel, SPICE_TYPE_CHANNEL)
>  
> +static SpiceCursorShape *spice_cursor_shape_copy(const SpiceCursorShape *cursor);
> +static void spice_cursor_shape_free(SpiceCursorShape *cursor);
> +
> +G_DEFINE_BOXED_TYPE(SpiceCursorShape, spice_cursor_shape,
> +                    (GBoxedCopyFunc)spice_cursor_shape_copy,
> +                    (GBoxedFreeFunc)spice_cursor_shape_free)
> +
>  /* ------------------------------------------------------------------ */
> +static SpiceCursorShape *spice_cursor_shape_copy(const SpiceCursorShape *cursor)
> +{
> +    SpiceCursorShape *new_cursor = g_new(SpiceCursorShape, 1);
> +    *new_cursor = *cursor;
> +    new_cursor->data = g_memdup(cursor->data, cursor->width * cursor->height * 4);
> +
> +    return new_cursor;
> +}
> +
> +static void spice_cursor_shape_free(SpiceCursorShape *cursor)
> +{
> +    g_return_if_fail(cursor != NULL);
> +
> +    g_free(cursor->data);
> +    g_free(cursor);
> +}
>  
>  static void spice_cursor_channel_init(SpiceCursorChannel *channel)
>  {
> @@ -107,15 +138,60 @@ static void spice_cursor_channel_reset(SpiceChannel *channel, gboolean migrating
>      SPICE_CHANNEL_CLASS(spice_cursor_channel_parent_class)->channel_reset(channel, migrating);
>  }
>  
> +static void spice_cursor_channel_dispose(GObject *object)
> +{
> +    SpiceCursorChannelPrivate *c = SPICE_CURSOR_CHANNEL(object)->priv;
> +
> +    g_clear_pointer(&c->last_cursor.data, g_free);
> +
> +    if (G_OBJECT_CLASS(spice_cursor_channel_parent_class)->dispose)
> +        G_OBJECT_CLASS(spice_cursor_channel_parent_class)->dispose(object);
> +}
> +
> +static void spice_cursor_channel_get_property(GObject    *object,
> +                                              guint       prop_id,
> +                                              GValue     *value,
> +                                              GParamSpec *pspec)
> +{
> +    SpiceCursorChannel *channel = SPICE_CURSOR_CHANNEL(object);
> +    SpiceCursorChannelPrivate *c = channel->priv;
> +
> +    switch (prop_id) {
> +    case PROP_CURSOR:
> +        g_value_set_static_boxed(value, c->last_cursor.data ? &c->last_cursor : NULL);
> +        break;
> +    default:
> +        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
> +        break;
> +    }
> +}
> +
>  static void spice_cursor_channel_class_init(SpiceCursorChannelClass *klass)
>  {
>      GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
>      SpiceChannelClass *channel_class = SPICE_CHANNEL_CLASS(klass);
>  
> +    gobject_class->dispose      = spice_cursor_channel_dispose;
>      gobject_class->finalize     = spice_cursor_channel_finalize;
> +    gobject_class->get_property = spice_cursor_channel_get_property;
>      channel_class->channel_reset = spice_cursor_channel_reset;
>  
>      /**
> +     * SpiceCursorChannel:cursor:
> +     *
> +     * The last #SpiceCursorShape received.
> +     *
> +     * Since: 0.34
> +     */
> +    g_object_class_install_property
> +        (gobject_class, PROP_CURSOR,
> +         g_param_spec_boxed("cursor",
> +                            "Last cursor shape",
> +                            "Last cursor shape received from the server",
> +                            SPICE_TYPE_CURSOR_SHAPE,
> +                            G_PARAM_READABLE |
> +                            G_PARAM_STATIC_STRINGS));
> +    /**
>       * SpiceCursorChannel::cursor-set:
>       * @cursor: the #SpiceCursorChannel that emitted the signal
>       * @width: width of the shape
> @@ -128,6 +204,8 @@ static void spice_cursor_channel_class_init(SpiceCursorChannelClass *klass)
>       *
>       * The #SpiceCursorChannel::cursor-set signal is emitted to modify
>       * cursor aspect and position on the display area.
> +     *
> +     * Deprecated: 0.34: Use #SpiceCursorChannel:cursor notify instead.
>       **/
>      signals[SPICE_CURSOR_SET] =
>          g_signal_new("cursor-set",

You could mark this signal with G_SIGNAL_DEPRECATED

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20170523/b609e38a/attachment-0001.sig>


More information about the Spice-devel mailing list