From: Szymon Lukasz <noh4hss@gmail.com>
To: qemu-devel@nongnu.org
Cc: lvivier@redhat.com, amit@kernel.org, mst@redhat.com,
Szymon Lukasz <noh4hss@gmail.com>,
marcandre.lureau@redhat.com, pbonzini@redhat.com
Subject: [PATCH 4/6] char-stdio: add support for the terminal size
Date: Sun, 21 Jun 2020 18:21:30 +0200 [thread overview]
Message-ID: <20200621162132.62797-5-noh4hss@gmail.com> (raw)
In-Reply-To: <20200621162132.62797-1-noh4hss@gmail.com>
Implement chr_get_winsize for the stdio backend
and trigger CHR_EVENT_RESIZE upon SIGWINCH delivery.
Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
---
chardev/char-stdio.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/chardev/char-stdio.c b/chardev/char-stdio.c
index 82eaebc1db..ab14edffc1 100644
--- a/chardev/char-stdio.c
+++ b/chardev/char-stdio.c
@@ -34,7 +34,9 @@
#include "chardev/char-win-stdio.h"
#else
#include <termios.h>
+#include <sys/ioctl.h>
#include "chardev/char-fd.h"
+#include "qemu/main-loop.h"
#endif
#ifndef _WIN32
@@ -45,6 +47,13 @@ static bool stdio_in_use;
static bool stdio_allow_signal;
static bool stdio_echo_state;
+typedef struct {
+ FDChardev parent;
+ Notifier resize_notifier;
+} StdioChardev;
+
+#define STDIO_CHARDEV(obj) OBJECT_CHECK(StdioChardev, (obj), TYPE_CHARDEV_STDIO)
+
static void term_exit(void)
{
if (stdio_in_use) {
@@ -82,11 +91,31 @@ static void term_stdio_handler(int sig)
qemu_chr_set_echo_stdio(NULL, stdio_echo_state);
}
+static int qemu_chr_get_winsize_stdio(Chardev *chr, uint16_t *cols, uint16_t *rows)
+{
+ struct winsize ws;
+
+ if (ioctl(1, TIOCGWINSZ, &ws) < 0) {
+ return -1;
+ }
+
+ *cols = ws.ws_col;
+ *rows = ws.ws_row;
+ return 0;
+}
+
+static void term_resize_notify(Notifier *n, void *data)
+{
+ StdioChardev *s = container_of(n, StdioChardev, resize_notifier);
+ qemu_chr_be_event(CHARDEV(s), CHR_EVENT_RESIZE);
+}
+
static void qemu_chr_open_stdio(Chardev *chr,
ChardevBackend *backend,
bool *be_opened,
Error **errp)
{
+ StdioChardev *s = STDIO_CHARDEV(chr);
ChardevStdio *opts = backend->u.stdio.data;
struct sigaction act;
@@ -116,6 +145,9 @@ static void qemu_chr_open_stdio(Chardev *chr,
stdio_allow_signal = opts->signal;
}
qemu_chr_set_echo_stdio(chr, false);
+
+ s->resize_notifier.notify = term_resize_notify;
+ sigwinch_add_notifier(&s->resize_notifier);
}
#endif
@@ -139,6 +171,7 @@ static void char_stdio_class_init(ObjectClass *oc, void *data)
#ifndef _WIN32
cc->open = qemu_chr_open_stdio;
cc->chr_set_echo = qemu_chr_set_echo_stdio;
+ cc->chr_get_winsize = qemu_chr_get_winsize_stdio;
#endif
}
@@ -155,6 +188,7 @@ static const TypeInfo char_stdio_type_info = {
.parent = TYPE_CHARDEV_WIN_STDIO,
#else
.parent = TYPE_CHARDEV_FD,
+ .instance_size = sizeof(StdioChardev),
#endif
.instance_finalize = char_stdio_finalize,
.class_init = char_stdio_class_init,
--
2.27.0
next prev parent reply other threads:[~2020-06-21 16:35 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-21 16:21 [PATCH 0/6] virtio-console: notify about the terminal size Szymon Lukasz
2020-06-21 16:21 ` [PATCH 1/6] main-loop: change the handling of SIGWINCH Szymon Lukasz
2020-06-21 16:21 ` [PATCH 2/6] chardev: add support for retrieving the terminal size Szymon Lukasz
2020-06-21 16:21 ` [PATCH 3/6] chardev: add support for notifying about terminal resizes Szymon Lukasz
2020-06-21 16:21 ` Szymon Lukasz [this message]
2020-06-21 16:21 ` [PATCH 5/6] virtio-serial-bus: add terminal resize messages Szymon Lukasz
2020-06-22 4:14 ` Michael S. Tsirkin
2020-06-21 16:21 ` [PATCH 6/6] virtio-console: notify the guest about terminal resizes Szymon Lukasz
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=20200621162132.62797-5-noh4hss@gmail.com \
--to=noh4hss@gmail.com \
--cc=amit@kernel.org \
--cc=lvivier@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--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).