qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Michal Suchanek <msuchanek@suse.de>
To: qemu-devel@nongnu.org
Cc: Michal Suchanek <msuchanek@suse.de>
Subject: [Qemu-devel] [RFC PATCH] Fix pasting into serial console in GTK ui
Date: Fri, 23 Dec 2016 16:12:53 +0100	[thread overview]
Message-ID: <20161223151253.21338-1-msuchanek@suse.de> (raw)

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 <msuchanek@suse.de>
---
 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)
-- 
2.10.2

             reply	other threads:[~2016-12-23 15:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-23 15:12 Michal Suchanek [this message]
2016-12-23 15:16 ` [Qemu-devel] [RFC PATCH] Fix pasting into serial console in GTK ui no-reply
2016-12-23 15:48 ` Michal Suchanek
2016-12-23 16:29 ` Paolo Bonzini
2017-01-02 15:17   ` Michal Suchánek
2017-01-03 13:32     ` Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161223151253.21338-1-msuchanek@suse.de \
    --to=msuchanek@suse.de \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).