[Spice-devel] [PATCH vdagent v3 1/2] vdagent: add new vdagent_clipboard_*() interface
Jakub Janků
janku.jakub.jj at gmail.com
Thu Mar 1 10:13:59 UTC 2018
From: Jakub Janků <jjanku at redhat.com>
Introduce new functions to handle clipboard,
add new files clipboard.[ch]
This is only a preparatory patch for
following GTK+ clipboard implementation.
---
Makefile.am | 2 ++
src/vdagent/clipboard.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++
src/vdagent/clipboard.h | 43 +++++++++++++++++++++++++++++++
src/vdagent/vdagent.c | 19 +++++++++-----
4 files changed, 125 insertions(+), 7 deletions(-)
create mode 100644 src/vdagent/clipboard.c
create mode 100644 src/vdagent/clipboard.h
diff --git a/Makefile.am b/Makefile.am
index c4bd3dd..3e405bc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -33,6 +33,8 @@ src_spice_vdagent_SOURCES = \
$(common_sources) \
src/vdagent/audio.c \
src/vdagent/audio.h \
+ src/vdagent/clipboard.c \
+ src/vdagent/clipboard.h \
src/vdagent/file-xfers.c \
src/vdagent/file-xfers.h \
src/vdagent/x11-priv.h \
diff --git a/src/vdagent/clipboard.c b/src/vdagent/clipboard.c
new file mode 100644
index 0000000..ab1e875
--- /dev/null
+++ b/src/vdagent/clipboard.c
@@ -0,0 +1,68 @@
+/* clipboard.c - vdagent clipboard handling code
+
+ Copyright 2017 Red Hat, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "clipboard.h"
+
+struct VDAgentClipboards {
+ struct vdagent_x11 *x11;
+};
+
+void vdagent_clipboard_grab(VDAgentClipboards *c, guint sel_id,
+ guint32 *types, guint n_types)
+{
+ vdagent_x11_clipboard_grab(c->x11, sel_id, types, n_types);
+}
+
+void vdagent_clipboard_data(VDAgentClipboards *c, guint sel_id,
+ guint type, guchar *data, guint size)
+{
+ vdagent_x11_clipboard_data(c->x11, sel_id, type, data, size);
+}
+
+void vdagent_clipboard_release(VDAgentClipboards *c, guint sel_id)
+{
+ vdagent_x11_clipboard_release(c->x11, sel_id);
+}
+
+void vdagent_clipboards_release_all(VDAgentClipboards *c)
+{
+ vdagent_x11_client_disconnected(c->x11);
+}
+
+void vdagent_clipboard_request(VDAgentClipboards *c, guint sel_id, guint type)
+{
+ vdagent_x11_clipboard_request(c->x11, sel_id, type);
+}
+
+VDAgentClipboards *vdagent_clipboards_init(struct vdagent_x11 *x11)
+{
+ VDAgentClipboards *c;
+ c = g_new0(VDAgentClipboards, 1);
+ c->x11 = x11;
+
+ return c;
+}
+
+void vdagent_clipboards_finalize(VDAgentClipboards *c)
+{
+ g_free(c);
+}
diff --git a/src/vdagent/clipboard.h b/src/vdagent/clipboard.h
new file mode 100644
index 0000000..aac3143
--- /dev/null
+++ b/src/vdagent/clipboard.h
@@ -0,0 +1,43 @@
+/* clipboard.h - vdagent clipboard handling header
+
+ Copyright 2017 Red Hat, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __VDAGENT_CLIPBOARD_H
+#define __VDAGENT_CLIPBOARD_H
+
+#include <glib.h>
+
+#include "x11.h"
+
+typedef struct VDAgentClipboards VDAgentClipboards;
+
+VDAgentClipboards *vdagent_clipboards_init(struct vdagent_x11 *x11);
+void vdagent_clipboards_finalize(VDAgentClipboards *c);
+
+void vdagent_clipboard_request(VDAgentClipboards *c, guint sel_id, guint type);
+
+void vdagent_clipboard_release(VDAgentClipboards *c, guint sel_id);
+
+void vdagent_clipboards_release_all(VDAgentClipboards *c);
+
+void vdagent_clipboard_data(VDAgentClipboards *c, guint sel_id,
+ guint type, guchar *data, guint size);
+
+void vdagent_clipboard_grab(VDAgentClipboards *c, guint sel_id,
+ guint32 *types, guint n_types);
+
+#endif
diff --git a/src/vdagent/vdagent.c b/src/vdagent/vdagent.c
index 6a20429..83180ac 100644
--- a/src/vdagent/vdagent.c
+++ b/src/vdagent/vdagent.c
@@ -46,8 +46,10 @@
#include "audio.h"
#include "x11.h"
#include "file-xfers.h"
+#include "clipboard.h"
typedef struct VDAgent {
+ VDAgentClipboards *clipboards;
struct vdagent_x11 *x11;
struct vdagent_file_xfers *xfers;
struct udscs_connection *conn;
@@ -168,18 +170,18 @@ static void daemon_read_complete(struct udscs_connection **connp,
vdagent_x11_set_monitor_config(agent->x11, (VDAgentMonitorsConfig *)data, 0);
break;
case VDAGENTD_CLIPBOARD_REQUEST:
- vdagent_x11_clipboard_request(agent->x11, header->arg1, header->arg2);
+ vdagent_clipboard_request(agent->clipboards, header->arg1, header->arg2);
break;
case VDAGENTD_CLIPBOARD_GRAB:
- vdagent_x11_clipboard_grab(agent->x11, header->arg1, (uint32_t *)data,
- header->size / sizeof(uint32_t));
+ vdagent_clipboard_grab(agent->clipboards, header->arg1,
+ (guint32 *)data, header->size / sizeof(guint32));
break;
case VDAGENTD_CLIPBOARD_DATA:
- vdagent_x11_clipboard_data(agent->x11, header->arg1, header->arg2,
- data, header->size);
+ vdagent_clipboard_data(agent->clipboards, header->arg1, header->arg2,
+ data, header->size);
break;
case VDAGENTD_CLIPBOARD_RELEASE:
- vdagent_x11_clipboard_release(agent->x11, header->arg1);
+ vdagent_clipboard_release(agent->clipboards, header->arg1);
break;
case VDAGENTD_VERSION:
if (strcmp((char *)data, VERSION) != 0) {
@@ -232,7 +234,7 @@ static void daemon_read_complete(struct udscs_connection **connp,
}
break;
case VDAGENTD_CLIENT_DISCONNECTED:
- vdagent_x11_client_disconnected(agent->x11);
+ vdagent_clipboards_release_all(agent->clipboards);
if (vdagent_finalize_file_xfer(agent)) {
vdagent_init_file_xfer(agent);
}
@@ -340,6 +342,7 @@ static VDAgent *vdagent_new(void)
static void vdagent_destroy(VDAgent *agent)
{
vdagent_finalize_file_xfer(agent);
+ vdagent_clipboards_finalize(agent->clipboards);
vdagent_x11_destroy(agent->x11, agent->conn == NULL);
udscs_destroy_connection(&agent->conn);
@@ -379,6 +382,8 @@ static gboolean vdagent_init_async_cb(gpointer user_data)
if (!vdagent_init_file_xfer(agent))
syslog(LOG_WARNING, "File transfer is disabled");
+ agent->clipboards = vdagent_clipboards_init(agent->x11);
+
if (parent_socket != -1) {
if (write(parent_socket, "OK", 2) != 2)
syslog(LOG_WARNING, "Parent already gone.");
--
2.14.3
More information about the Spice-devel
mailing list