From patchwork Fri Sep 11 15:52:33 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 33475 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id 105A9B6F56 for ; Sat, 12 Sep 2009 02:06:32 +1000 (EST) Received: from localhost ([127.0.0.1]:60319 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mm8dn-00050x-V5 for incoming@patchwork.ozlabs.org; Fri, 11 Sep 2009 12:06:28 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mm8RD-0002H2-IC for qemu-devel@nongnu.org; Fri, 11 Sep 2009 11:53:27 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mm8R9-0002Ag-SH for qemu-devel@nongnu.org; Fri, 11 Sep 2009 11:53:27 -0400 Received: from [199.232.76.173] (port=54650 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mm8R9-0002AM-Mn for qemu-devel@nongnu.org; Fri, 11 Sep 2009 11:53:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46850) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mm8R9-00054v-0h for qemu-devel@nongnu.org; Fri, 11 Sep 2009 11:53:23 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8BFrKDS028349; Fri, 11 Sep 2009 11:53:20 -0400 Received: from localhost (vpn-12-154.rdu.redhat.com [10.11.12.154]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8BFrI6i016882; Fri, 11 Sep 2009 11:53:19 -0400 From: Amit Shah To: qemu-devel@nongnu.org Date: Fri, 11 Sep 2009 21:22:33 +0530 Message-Id: <1252684353-25067-6-git-send-email-amit.shah@redhat.com> In-Reply-To: <1252684353-25067-5-git-send-email-amit.shah@redhat.com> References: <1252684353-25067-1-git-send-email-amit.shah@redhat.com> <1252684353-25067-2-git-send-email-amit.shah@redhat.com> <1252684353-25067-3-git-send-email-amit.shah@redhat.com> <1252684353-25067-4-git-send-email-amit.shah@redhat.com> <1252684353-25067-5-git-send-email-amit.shah@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Amit Shah Subject: [Qemu-devel] [PATCH 5/5] vnc: Send / receive guest clipboard if virtio-console connected to clipboard port X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org If a connection to the guest clipboard is open, send the host clipboard to the guest and guest clipboard to the host on any change Signed-off-by: Amit Shah --- hw/virtio-console.h | 1 + vnc.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 0 deletions(-) diff --git a/hw/virtio-console.h b/hw/virtio-console.h index b06297e..caefb2c 100644 --- a/hw/virtio-console.h +++ b/hw/virtio-console.h @@ -28,6 +28,7 @@ /* Port number to function mapping */ #define VIRTIO_CONSOLE_CONSOLE_PORT 0 #define VIRTIO_CONSOLE_CONSOLE2_PORT 1 +#define VIRTIO_CONSOLE_CLIPBOARD_PORT 3 /* Features supported */ #define VIRTIO_CONSOLE_F_MULTIPORT 1 diff --git a/vnc.c b/vnc.c index ff2d4a8..74602dd 100644 --- a/vnc.c +++ b/vnc.c @@ -29,6 +29,7 @@ #include "qemu_socket.h" #include "qemu-timer.h" #include "acl.h" +#include "hw/virtio-console.h" #define VNC_REFRESH_INTERVAL_BASE 30 #define VNC_REFRESH_INTERVAL_INC 50 @@ -47,6 +48,7 @@ static VncDisplay *vnc_display; /* needed for info vnc */ static DisplayChangeListener *dcl; +static VirtIOConsolePort *virtcon_port; static char *addr_to_string(const char *format, struct sockaddr_storage *sa, @@ -671,6 +673,37 @@ static void vnc_copy(VncState *vs, int src_x, int src_y, int dst_x, int dst_y, i vnc_flush(vs); } +static size_t vnc_clipboard_data_from_guest(const uint8_t *buf, size_t len) +{ + VncState *vs; + VncDisplay *vd; + DisplayState *ds; + size_t orig_len; + + orig_len = len; + if (!is_vnc_active()) { + /* If there's no display we don't want the caller to buffer any data */ + return orig_len; + } + + ds = vnc_display->ds; + vd = ds->opaque; + + for (vs = vd->clients; vs; vs = vs->next) { + len = orig_len; + vnc_write_u8(vs, 3); /* ServerCutText */ + vnc_write_u8(vs, 0); /* Padding */ + vnc_write_u8(vs, 0); /* Padding */ + vnc_write_u8(vs, 0); /* Padding */ + vnc_write_u32(vs, len); + while (len--) { + vnc_write_u8(vs, *(buf++)); + } + vnc_flush(vs); + } + return orig_len; +} + static void vnc_dpy_copy(DisplayState *ds, int src_x, int src_y, int dst_x, int dst_y, int w, int h) { VncDisplay *vd = ds->opaque; @@ -1240,6 +1273,7 @@ uint32_t read_u32(uint8_t *data, size_t offset) static void client_cut_text(VncState *vs, size_t len, uint8_t *text) { + virtio_console_write(virtcon_port, text, len); } static void check_pointer_type_change(VncState *vs, int absolute) @@ -2265,6 +2299,7 @@ void vnc_display_close(DisplayState *ds) vs->subauth = VNC_AUTH_INVALID; vs->tls.x509verify = 0; #endif + virtio_console_close(virtcon_port); } int vnc_display_password(DisplayState *ds, const char *password) @@ -2514,5 +2549,8 @@ int vnc_display_open(DisplayState *ds, const char *display) vs->display = dpy; } } + + virtcon_port = virtio_console_open(VIRTIO_CONSOLE_CLIPBOARD_PORT, + vnc_clipboard_data_from_guest); return qemu_set_fd_handler2(vs->lsock, NULL, vnc_listen_read, NULL, vs); }