* [Qemu-devel] [RFC PATCH] Fix pasting into serial console in GTK ui
@ 2016-12-23 15:12 Michal Suchanek
2016-12-23 15:16 ` no-reply
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Michal Suchanek @ 2016-12-23 15:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Michal Suchanek
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [RFC PATCH] Fix pasting into serial console in GTK ui
2016-12-23 15:12 [Qemu-devel] [RFC PATCH] Fix pasting into serial console in GTK ui Michal Suchanek
@ 2016-12-23 15:16 ` no-reply
2016-12-23 15:48 ` Michal Suchanek
2016-12-23 16:29 ` Paolo Bonzini
2 siblings, 0 replies; 6+ messages in thread
From: no-reply @ 2016-12-23 15:16 UTC (permalink / raw)
To: msuchanek; +Cc: famz, qemu-devel
Hi,
Your series seems to have some coding style problems. See output below for
more information:
Type: series
Message-id: 20161223151253.21338-1-msuchanek@suse.de
Subject: [Qemu-devel] [RFC PATCH] Fix pasting into serial console in GTK ui
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
# Useful git options
git config --local diff.renamelimit 0
git config --local diff.renames True
commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))
done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
* [new tag] patchew/20161223151253.21338-1-msuchanek@suse.de -> patchew/20161223151253.21338-1-msuchanek@suse.de
Switched to a new branch 'test'
74e9646 Fix pasting into serial console in GTK ui
=== OUTPUT BEGIN ===
Checking PATCH 1/1: Fix pasting into serial console in GTK ui...
ERROR: space prohibited after that open parenthesis '('
#51: FILE: ui/gtk.c:1755:
+ if ( size > len) {
ERROR: braces {} are necessary for all arms of this statement
#57: FILE: ui/gtk.c:1761:
+ if (inbuf->sent < inbuf->size)
[...]
+ else {
[...]
ERROR: braces {} are necessary for all arms of this statement
#74: FILE: ui/gtk.c:1778:
+ if (!inbuf)
[...]
total: 3 errors, 0 warnings, 70 lines checked
Your patch has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@freelists.org
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Qemu-devel] [RFC PATCH] Fix pasting into serial console in GTK ui
2016-12-23 15:12 [Qemu-devel] [RFC PATCH] Fix pasting into serial console in GTK ui Michal Suchanek
2016-12-23 15:16 ` no-reply
@ 2016-12-23 15:48 ` Michal Suchanek
2016-12-23 16:29 ` Paolo Bonzini
2 siblings, 0 replies; 6+ messages in thread
From: Michal Suchanek @ 2016-12-23 15:48 UTC (permalink / raw)
To: qemu-devel; +Cc: Michal Suchanek
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 | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 54 insertions(+), 4 deletions(-)
diff --git a/ui/gtk.c b/ui/gtk.c
index a216216..58e97ab 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,52 @@ 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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [RFC PATCH] Fix pasting into serial console in GTK ui
2016-12-23 15:12 [Qemu-devel] [RFC PATCH] Fix pasting into serial console in GTK ui Michal Suchanek
2016-12-23 15:16 ` no-reply
2016-12-23 15:48 ` Michal Suchanek
@ 2016-12-23 16:29 ` Paolo Bonzini
2017-01-02 15:17 ` Michal Suchánek
2 siblings, 1 reply; 6+ messages in thread
From: Paolo Bonzini @ 2016-12-23 16:29 UTC (permalink / raw)
To: Michal Suchanek, qemu-devel
On 23/12/2016 16:12, Michal Suchanek wrote:
> 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.
Do not use a timer, instead set chr->chr_accept_input in gd_vc_handler.
The callback can do basically what you are doing in gd_vc_in_timer. The
buffer can be just a GString plus a "head" pointer, in VirtualConsole.
Once the head catches up with the tail, you can free the GString.
Paolo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [RFC PATCH] Fix pasting into serial console in GTK ui
2016-12-23 16:29 ` Paolo Bonzini
@ 2017-01-02 15:17 ` Michal Suchánek
2017-01-03 13:32 ` Gerd Hoffmann
0 siblings, 1 reply; 6+ messages in thread
From: Michal Suchánek @ 2017-01-02 15:17 UTC (permalink / raw)
To: qemu-devel
Hello,
On Fri, 23 Dec 2016 17:29:28 +0100
Paolo Bonzini <pbonzini@redhat.com> wrote:
> On 23/12/2016 16:12, Michal Suchanek wrote:
> > 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.
>
> Do not use a timer, instead set chr->chr_accept_input in
> gd_vc_handler. The callback can do basically what you are doing in
> gd_vc_in_timer. The buffer can be just a GString plus a "head"
> pointer, in VirtualConsole. Once the head catches up with the tail,
> you can free the GString.
How do you propose to use that callback? I did not find a
documentation for it. It takes no argument (except the chr object self)
so there is no way to pass in the buffer. It cannot be replaced -
it is set in non-ui code in multiple places and never in ui code.
Thanks
Michal
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [RFC PATCH] Fix pasting into serial console in GTK ui
2017-01-02 15:17 ` Michal Suchánek
@ 2017-01-03 13:32 ` Gerd Hoffmann
0 siblings, 0 replies; 6+ messages in thread
From: Gerd Hoffmann @ 2017-01-03 13:32 UTC (permalink / raw)
To: Michal Suchánek; +Cc: qemu-devel
Hi,
> How do you propose to use that callback? I did not find a
> documentation for it. It takes no argument (except the chr object self)
> so there is no way to pass in the buffer. It cannot be replaced -
> it is set in non-ui code in multiple places and never in ui code.
No docs, but see backend/msmouse.c where I've added chr_accept_input
support recently.
cheers,
Gerd
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-01-03 13:32 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-23 15:12 [Qemu-devel] [RFC PATCH] Fix pasting into serial console in GTK ui Michal Suchanek
2016-12-23 15:16 ` 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
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.