[RFC,spice-vdagent,6/8] clipboard: add vdagent_clipboards_set_protocol()

Submitted by =?UTF-8?q?Jakub=20Jank=C5=AF?= on May 31, 2018, 8:52 p.m.

Details

Message ID 20180531205225.4266-7-jjanku@redhat.com
State New
Headers show
Series "Clipboard - using MIME types" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

=?UTF-8?q?Jakub=20Jank=C5=AF?= May 31, 2018, 8:52 p.m.
---
 src/vdagent/clipboard.c | 11 +++++++++++
 src/vdagent/clipboard.h |  2 ++
 src/vdagent/vdagent.c   |  3 +++
 3 files changed, 16 insertions(+)

Patch hide | download patch | download mbox

diff --git a/src/vdagent/clipboard.c b/src/vdagent/clipboard.c
index 101e535..63f8527 100644
--- a/src/vdagent/clipboard.c
+++ b/src/vdagent/clipboard.c
@@ -24,6 +24,7 @@ 
 #include <syslog.h>
 
 #include "vdagentd-proto.h"
+#include "vdagentd-proto-strings.h"
 #include "spice/vd_agent.h"
 
 #include "clipboard.h"
@@ -60,6 +61,7 @@  typedef struct {
 struct VDAgentClipboards {
     struct udscs_connection *conn;
     Selection                selections[SELECTION_COUNT];
+    guint                    protocol;
 };
 
 static const struct {
@@ -401,6 +403,14 @@  err:
                 VD_AGENT_CLIPBOARD_NONE, NULL, 0);
 }
 
+void vdagent_clipboards_set_protocol(VDAgentClipboards *c, guint protocol)
+{
+    g_return_if_fail(protocol <= CLIPBOARD_PROTOCOL_SELECTION);
+    c->protocol = protocol;
+    syslog(LOG_DEBUG, "Clipboard protocol set to %s",
+                      vdagentd_clipboard_protocols[protocol]);
+}
+
 VDAgentClipboards *vdagent_clipboards_init(struct udscs_connection *conn)
 {
     guint sel_id;
@@ -412,6 +422,7 @@  VDAgentClipboards *vdagent_clipboards_init(struct udscs_connection *conn)
     VDAgentClipboards *c;
     c = g_new0(VDAgentClipboards, 1);
     c->conn = conn;
+    c->protocol = CLIPBOARD_PROTOCOL_COMPATIBILITY;
 
     for (sel_id = 0; sel_id < SELECTION_COUNT; sel_id++) {
         GtkClipboard *clipboard = gtk_clipboard_get(sel_atom[sel_id]);
diff --git a/src/vdagent/clipboard.h b/src/vdagent/clipboard.h
index e007a37..d9cc22c 100644
--- a/src/vdagent/clipboard.h
+++ b/src/vdagent/clipboard.h
@@ -28,6 +28,8 @@  typedef struct VDAgentClipboards VDAgentClipboards;
 VDAgentClipboards *vdagent_clipboards_init(struct udscs_connection *conn);
 void vdagent_clipboards_finalize(VDAgentClipboards *c, gboolean conn_alive);
 
+void vdagent_clipboards_set_protocol(VDAgentClipboards *c, guint protocol);
+
 void vdagent_clipboard_request(VDAgentClipboards *c, guint sel_id, guint type);
 
 void vdagent_clipboard_release(VDAgentClipboards *c, guint sel_id);
diff --git a/src/vdagent/vdagent.c b/src/vdagent/vdagent.c
index 711e4f8..85aa6ae 100644
--- a/src/vdagent/vdagent.c
+++ b/src/vdagent/vdagent.c
@@ -192,6 +192,9 @@  static void daemon_read_complete(struct udscs_connection **connp,
     case VDAGENTD_CLIPBOARD_RELEASE:
         vdagent_clipboard_release(agent->clipboards, header->arg1);
         break;
+    case VDAGENTD_CLIPBOARD_PROTOCOL:
+        vdagent_clipboards_set_protocol(agent->clipboards, header->arg1);
+        break;
     case VDAGENTD_VERSION:
         if (strcmp((char *)data, VERSION) != 0) {
             syslog(LOG_INFO, "vdagentd version mismatch: got %s expected %s",

Comments

Hi,

On Thu, May 31, 2018 at 10:52:23PM +0200, Jakub Janků wrote:
> ---

Log is missing for the commit. The previous protocol would stay
as default to the selection protocol.

>  src/vdagent/clipboard.c | 11 +++++++++++
>  src/vdagent/clipboard.h |  2 ++
>  src/vdagent/vdagent.c   |  3 +++
>  3 files changed, 16 insertions(+)
> 
> diff --git a/src/vdagent/clipboard.c b/src/vdagent/clipboard.c
> index 101e535..63f8527 100644
> --- a/src/vdagent/clipboard.c
> +++ b/src/vdagent/clipboard.c
> @@ -24,6 +24,7 @@
>  #include <syslog.h>
>  
>  #include "vdagentd-proto.h"
> +#include "vdagentd-proto-strings.h"
>  #include "spice/vd_agent.h"
>  
>  #include "clipboard.h"
> @@ -60,6 +61,7 @@ typedef struct {
>  struct VDAgentClipboards {
>      struct udscs_connection *conn;
>      Selection                selections[SELECTION_COUNT];
> +    guint                    protocol;

if (c->protocol) { ...  does not tell much when we are reading
the code. Hopefully this is not something we plan to extend so

I'd use a bool with something like use_selection or
selection_enabled.

>  };
>  
>  static const struct {
> @@ -401,6 +403,14 @@ err:
>                  VD_AGENT_CLIPBOARD_NONE, NULL, 0);
>  }
>  
> +void vdagent_clipboards_set_protocol(VDAgentClipboards *c, guint protocol)
> +{
> +    g_return_if_fail(protocol <= CLIPBOARD_PROTOCOL_SELECTION);
> +    c->protocol = protocol;

c->use_selection = (protocol == CLIPBOARD_PROTOCOL_SELECTION);

> +    syslog(LOG_DEBUG, "Clipboard protocol set to %s",
> +                      vdagentd_clipboard_protocols[protocol]);
> +}
> +
>  VDAgentClipboards *vdagent_clipboards_init(struct udscs_connection *conn)
>  {
>      guint sel_id;
> @@ -412,6 +422,7 @@ VDAgentClipboards *vdagent_clipboards_init(struct udscs_connection *conn)
>      VDAgentClipboards *c;
>      c = g_new0(VDAgentClipboards, 1);
>      c->conn = conn;
> +    c->protocol = CLIPBOARD_PROTOCOL_COMPATIBILITY;

c->use_selection = false;

>  
>      for (sel_id = 0; sel_id < SELECTION_COUNT; sel_id++) {
>          GtkClipboard *clipboard = gtk_clipboard_get(sel_atom[sel_id]);
> diff --git a/src/vdagent/clipboard.h b/src/vdagent/clipboard.h
> index e007a37..d9cc22c 100644
> --- a/src/vdagent/clipboard.h
> +++ b/src/vdagent/clipboard.h
> @@ -28,6 +28,8 @@ typedef struct VDAgentClipboards VDAgentClipboards;
>  VDAgentClipboards *vdagent_clipboards_init(struct udscs_connection *conn);
>  void vdagent_clipboards_finalize(VDAgentClipboards *c, gboolean conn_alive);
>  
> +void vdagent_clipboards_set_protocol(VDAgentClipboards *c, guint protocol);
> +
>  void vdagent_clipboard_request(VDAgentClipboards *c, guint sel_id, guint type);
>  
>  void vdagent_clipboard_release(VDAgentClipboards *c, guint sel_id);
> diff --git a/src/vdagent/vdagent.c b/src/vdagent/vdagent.c
> index 711e4f8..85aa6ae 100644
> --- a/src/vdagent/vdagent.c
> +++ b/src/vdagent/vdagent.c
> @@ -192,6 +192,9 @@ static void daemon_read_complete(struct udscs_connection **connp,
>      case VDAGENTD_CLIPBOARD_RELEASE:
>          vdagent_clipboard_release(agent->clipboards, header->arg1);
>          break;
> +    case VDAGENTD_CLIPBOARD_PROTOCOL:
> +        vdagent_clipboards_set_protocol(agent->clipboards, header->arg1);
> +        break;

We could possibly change VDAGENTD_CLIPBOARD_PROTOCOL message too
with something lik VDAGENTD_CLIPBOARD_SET_SELECTION with
true/false values. Up to you.

Cheers,

>      case VDAGENTD_VERSION:
>          if (strcmp((char *)data, VERSION) != 0) {
>              syslog(LOG_INFO, "vdagentd version mismatch: got %s expected %s",
> -- 
> 2.17.0
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel