From patchwork Fri Dec 23 15:12:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Suchanek X-Patchwork-Id: 9487517 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E56F2600CB for ; Fri, 23 Dec 2016 15:13:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D734225D9E for ; Fri, 23 Dec 2016 15:13:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA3B926212; Fri, 23 Dec 2016 15:13:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 384D025D9E for ; Fri, 23 Dec 2016 15:13:34 +0000 (UTC) Received: from localhost ([::1]:39576 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cKRXJ-0001e6-Qu for patchwork-qemu-devel@patchwork.kernel.org; Fri, 23 Dec 2016 10:13:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34397) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cKRWy-0001do-FJ for qemu-devel@nongnu.org; Fri, 23 Dec 2016 10:13:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cKRWv-0004Bp-M2 for qemu-devel@nongnu.org; Fri, 23 Dec 2016 10:13:12 -0500 Received: from mx2.suse.de ([195.135.220.15]:43237) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cKRWv-00048U-A9 for qemu-devel@nongnu.org; Fri, 23 Dec 2016 10:13:09 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id EB08BACA3 for ; Fri, 23 Dec 2016 15:13:03 +0000 (UTC) From: Michal Suchanek To: qemu-devel@nongnu.org Date: Fri, 23 Dec 2016 16:12:53 +0100 Message-Id: <20161223151253.21338-1-msuchanek@suse.de> X-Mailer: git-send-email 2.10.2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 195.135.220.15 Subject: [Qemu-devel] [RFC PATCH] Fix pasting into serial console in GTK ui X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michal Suchanek Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This copies the timer hack from ui/console.c kbd_send_chars to ui/gtk.c gd_vc_in. There is no fd-like object to peek repatedly so the paste data is saved in a free-floating buffer only submitted to gtk_timeout_add. Multiple pastes can potentially interleave if qemu blocks for long or the user pastes fast. Signed-off-by: Michal Suchanek --- ui/gtk.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/ui/gtk.c b/ui/gtk.c index a216216..b3810c7 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -1715,11 +1715,15 @@ static CharDriverState *gd_vc_handler(ChardevVC *vc, Error **errp) return chr; } -static gboolean gd_vc_in(VteTerminal *terminal, gchar *text, guint size, - gpointer user_data) -{ - VirtualConsole *vc = user_data; +struct vc_in_buffer { + VirtualConsole *vc; + gchar *text; + guint size; + guint sent; +}; +static gboolean do_gd_vc_in(VirtualConsole *vc, gchar *text, guint size) +{ if (vc->vte.echo) { VteTerminal *term = VTE_TERMINAL(vc->vte.terminal); int i; @@ -1742,6 +1746,51 @@ static gboolean gd_vc_in(VteTerminal *terminal, gchar *text, guint size, return TRUE; } +static gint gd_vc_in_timer(gpointer data) +{ + struct vc_in_buffer *inbuf = data; + VirtualConsole *vc = inbuf->vc; + int len = qemu_chr_be_can_write(vc->vte.chr); + int size = inbuf->size - inbuf->sent; + if ( size > len) { + size = len; + } + do_gd_vc_in(vc, inbuf->text + inbuf->sent, size); + + inbuf->sent += size; + if (inbuf->sent < inbuf->size) + return TRUE; + else { + g_clear_pointer(&inbuf->text, g_free); + g_free(inbuf); + return FALSE; + } +} + +static gboolean gd_vc_in(VteTerminal *terminal, gchar *text, guint size, + gpointer user_data) +{ + VirtualConsole *vc = user_data; + int len = qemu_chr_be_can_write(vc->vte.chr); + + if (size > len) { + struct vc_in_buffer *inbuf = g_try_new0(struct vc_in_buffer, 1); + if (!inbuf) + return FALSE; + inbuf->text = g_strndup(text, size); + if (!inbuf->text) { + g_free(inbuf); + return FALSE; + } + inbuf->vc = vc; + inbuf->size = size; + inbuf->sent = len; + size = len; + g_timeout_add(1, gd_vc_in_timer, inbuf); + } + return do_gd_vc_in(vc, text, size); +} + static GSList *gd_vc_vte_init(GtkDisplayState *s, VirtualConsole *vc, CharDriverState *chr, int idx, GSList *group, GtkWidget *view_menu)