qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC PATCH] Fix pasting into serial console in GTK ui


From: Michal Suchanek
Subject: [Qemu-devel] [RFC PATCH] Fix pasting into serial console in GTK ui
Date: Fri, 23 Dec 2016 16:12:53 +0100

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 <address@hidden>
---
 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 via email to

[Prev in Thread] Current Thread [Next in Thread]