<div dir="auto"><div>Hi,<br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Mar 25, 2019, 11:34 AM Marc-André Lureau <<a href="mailto:marcandre.lureau@gmail.com">marcandre.lureau@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi<br>
<br>
On Mon, Mar 25, 2019 at 10:26 AM Frediano Ziglio <<a href="mailto:fziglio@redhat.com" target="_blank" rel="noreferrer">fziglio@redhat.com</a>> wrote:<br>
><br>
> ><br>
> > From: Marc-André Lureau <<a href="mailto:marcandre.lureau@redhat.com" target="_blank" rel="noreferrer">marcandre.lureau@redhat.com</a>><br>
> ><br>
> > This will allow easier lifecycle management,<br>
> > and usage of gtk_clipboard_set_with_owner()<br>
> ><br>
> > Signed-off-by: Marc-André Lureau <<a href="mailto:marcandre.lureau@redhat.com" target="_blank" rel="noreferrer">marcandre.lureau@redhat.com</a>><br>
> > ---<br>
> >  src/vdagent/clipboard.c | 67 +++++++++++++++++++++++++++--------------<br>
> >  src/vdagent/clipboard.h | 12 +++++---<br>
> >  src/vdagent/vdagent.c   |  7 +++--<br>
> >  3 files changed, 56 insertions(+), 30 deletions(-)<br>
> ><br>
> > diff --git a/src/vdagent/clipboard.c b/src/vdagent/clipboard.c<br>
> > index 1e49248..cf6e344 100644<br>
> > --- a/src/vdagent/clipboard.c<br>
> > +++ b/src/vdagent/clipboard.c<br>
> > @@ -76,15 +76,25 @@ typedef struct {<br>
> >  } Selection;<br>
> >  #endif<br>
> ><br>
> > -struct VDAgentClipboards {<br>
> > -#ifdef WITH_GTK<br>
> > +struct _VDAgentClipboards {<br>
><br>
> Can we use C99 complaints identifiers?<br>
<br>
I didn't think much about the struct identifiers.<br>
<br>
fwiw, glib/gobject/gtk uses "struct _Foo" everywhere.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">I think it's necessary as long as you want to use the new GObject macro.</div><div dir="auto"><br></div><div dir="auto"><span style="font-family:sans-serif">G_DECLARE_FINAL_TYPE typedefs VdagentClipboards as struct </span><span style="font-family:sans-serif">_VDAgentClipboards afaik.</span><br></div><div dir="auto"><span style="font-family:sans-serif"><br></span></div><div dir="auto"><span style="font-family:sans-serif">Cheers,</span></div><div dir="auto"><span style="font-family:sans-serif">Jakub</span></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
><br>
> > +    GObject parent;<br>
> > +<br>
> >      struct udscs_connection *conn;<br>
> > -    Selection                selections[SELECTION_COUNT];<br>
> > +<br>
> > +#ifdef WITH_GTK<br>
> > +    Selection selections[SELECTION_COUNT];<br>
> >  #else<br>
> >      struct vdagent_x11 *x11;<br>
> >  #endif<br>
> >  };<br>
> ><br>
> > +struct _VDAgentClipboardsClass<br>
> > +{<br>
><br>
> 2 structure style declaration in one patch<br>
<br>
Hmm? are you talking about braces indentation here?<br>
<br>
><br>
> > +    GObjectClass parent;<br>
> > +};<br>
> > +<br>
> > +G_DEFINE_TYPE(VDAgentClipboards, vdagent_clipboards, G_TYPE_OBJECT)<br>
> > +<br>
> >  #ifdef WITH_GTK<br>
> >  static const struct {<br>
> >      guint         type;<br>
> > @@ -453,43 +463,56 @@ err:<br>
> >  #endif<br>
> >  }<br>
> ><br>
> > -VDAgentClipboards *vdagent_clipboards_init(struct vdagent_x11      *x11,<br>
> > -                                           struct udscs_connection *conn)<br>
> > +static void<br>
> > +vdagent_clipboards_init(VDAgentClipboards *self)<br>
> >  {<br>
> > -#ifdef WITH_GTK<br>
> > -    guint sel_id;<br>
> > -#endif<br>
> > +}<br>
> > +<br>
> > +VDAgentClipboards *vdagent_clipboards_new(struct vdagent_x11 *x11)<br>
> > +{<br>
> > +    VDAgentClipboards *self = g_object_new(VDAGENT_TYPE_CLIPBOARDS, NULL);<br>
> ><br>
> > -    VDAgentClipboards *c;<br>
> > -    c = g_new0(VDAgentClipboards, 1);<br>
> >  #ifndef WITH_GTK<br>
> > -    c->x11 = x11;<br>
> > +    self->x11 = x11;<br>
> >  #else<br>
> > -    c->conn = conn;<br>
> > +    guint sel_id;<br>
> ><br>
> >      for (sel_id = 0; sel_id < SELECTION_COUNT; sel_id++) {<br>
> >          GtkClipboard *clipboard = gtk_clipboard_get(sel_atom[sel_id]);<br>
> > -        c->selections[sel_id].clipboard = clipboard;<br>
> > +        self->selections[sel_id].clipboard = clipboard;<br>
> >          g_signal_connect(G_OBJECT(clipboard), "owner-change",<br>
> > -                         G_CALLBACK(clipboard_owner_change_cb), c);<br>
> > +                         G_CALLBACK(clipboard_owner_change_cb), self);<br>
> >      }<br>
> >  #endif<br>
> ><br>
> > -    return c;<br>
> > +    return self;<br>
> >  }<br>
> ><br>
> > -void vdagent_clipboards_finalize(VDAgentClipboards *c, gboolean conn_alive)<br>
> > +void<br>
> > +vdagent_clipboards_set_conn(VDAgentClipboards *self, struct udscs_connection<br>
> > *conn)<br>
> > +{<br>
> > +    self->conn = conn;<br>
> > +}<br>
> > +<br>
> > +static void vdagent_clipboards_dispose(GObject *obj)<br>
> >  {<br>
> >  #ifdef WITH_GTK<br>
> > +    VDAgentClipboards *self = VDAGENT_CLIPBOARDS(obj);<br>
> >      guint sel_id;<br>
> > +<br>
> >      for (sel_id = 0; sel_id < SELECTION_COUNT; sel_id++)<br>
> > -<br>
> > g_signal_handlers_disconnect_by_func(c->selections[sel_id].clipboard,<br>
> > -            G_CALLBACK(clipboard_owner_change_cb), c);<br>
> > +<br>
> > g_signal_handlers_disconnect_by_func(self->selections[sel_id].clipboard,<br>
> > +            G_CALLBACK(clipboard_owner_change_cb), self);<br>
> ><br>
> > -    if (conn_alive == FALSE)<br>
> > -        c->conn = NULL;<br>
> > -    vdagent_clipboards_release_all(c);<br>
> > +    if (self->conn)<br>
> > +        vdagent_clipboards_release_all(self);<br>
> >  #endif<br>
> > +}<br>
> > +<br>
> > +static void<br>
> > +vdagent_clipboards_class_init(VDAgentClipboardsClass *klass)<br>
> > +{<br>
> > +    GObjectClass *oclass = G_OBJECT_CLASS(klass);<br>
> ><br>
> > -    g_free(c);<br>
> > +    oclass->dispose = vdagent_clipboards_dispose;<br>
> >  }<br>
> > diff --git a/src/vdagent/clipboard.h b/src/vdagent/clipboard.h<br>
> > index f819b49..cd8eacb 100644<br>
> > --- a/src/vdagent/clipboard.h<br>
> > +++ b/src/vdagent/clipboard.h<br>
> > @@ -19,16 +19,18 @@<br>
> >  #ifndef __VDAGENT_CLIPBOARD_H<br>
> >  #define __VDAGENT_CLIPBOARD_H<br>
> ><br>
> > -#include <glib.h><br>
> > +#include <glib-object.h><br>
> ><br>
> >  #include "x11.h"<br>
> >  #include "udscs.h"<br>
> ><br>
> > -typedef struct VDAgentClipboards VDAgentClipboards;<br>
> > +#define VDAGENT_TYPE_CLIPBOARDS vdagent_clipboards_get_type()<br>
> > +G_DECLARE_FINAL_TYPE(VDAgentClipboards, vdagent_clipboards, VDAGENT,<br>
> > CLIPBOARDS, GObject)<br>
> ><br>
> > -VDAgentClipboards *vdagent_clipboards_init(struct vdagent_x11      *x11,<br>
> > -                                           struct udscs_connection *conn);<br>
> > -void vdagent_clipboards_finalize(VDAgentClipboards *c, gboolean conn_alive);<br>
> > +VDAgentClipboards *vdagent_clipboards_new(struct vdagent_x11 *x11);<br>
> > +<br>
> > +void vdagent_clipboards_set_conn(VDAgentClipboards *self,<br>
> > +                                 struct udscs_connection *conn);<br>
> ><br>
> >  void vdagent_clipboard_request(VDAgentClipboards *c, guint sel_id, guint<br>
> >  type);<br>
> ><br>
> > diff --git a/src/vdagent/vdagent.c b/src/vdagent/vdagent.c<br>
> > index 61aeac7..bfc0d5f 100644<br>
> > --- a/src/vdagent/vdagent.c<br>
> > +++ b/src/vdagent/vdagent.c<br>
> > @@ -165,8 +165,8 @@ static void vdagent_quit_loop(VDAgent *agent)<br>
> >  {<br>
> >      /* other GMainLoop(s) might be running, quit them before agent->loop */<br>
> >      if (agent->clipboards) {<br>
> > -        vdagent_clipboards_finalize(agent->clipboards, agent->conn != NULL);<br>
> > -        agent->clipboards = NULL;<br>
> > +        vdagent_clipboards_set_conn(agent->clipboards, agent->conn);<br>
> > +        g_clear_object(&agent->clipboards);<br>
> >      }<br>
> >      if (agent->loop)<br>
> >          g_main_loop_quit(agent->loop);<br>
> > @@ -400,7 +400,8 @@ static gboolean vdagent_init_async_cb(gpointer user_data)<br>
> >      if (!vdagent_init_file_xfer(agent))<br>
> >          syslog(LOG_WARNING, "File transfer is disabled");<br>
> ><br>
> > -    agent->clipboards = vdagent_clipboards_init(agent->x11, agent->conn);<br>
> > +    agent->clipboards = vdagent_clipboards_new(agent->x11);<br>
> > +    vdagent_clipboards_set_conn(agent->clipboards, agent->conn);<br>
><br>
> Why not using a constructor property to pass agent->conn?<br>
<br>
Because it's not needed at construct time, however we need to change<br>
the value when the conn goes away.<br>
<br>
><br>
> ><br>
> >      if (parent_socket != -1) {<br>
> >          if (write(parent_socket, "OK", 2) != 2)<br>
><br>
> Beside style I didn't have a look at other stuff<br>
<br>
thanks<br>
<br>
<br>
<br>
-- <br>
Marc-André Lureau<br>
_______________________________________________<br>
Spice-devel mailing list<br>
<a href="mailto:Spice-devel@lists.freedesktop.org" target="_blank" rel="noreferrer">Spice-devel@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/spice-devel" rel="noreferrer noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/spice-devel</a></blockquote></div></div></div>