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 2/6] chardev: add support for retrieving the terminal size
Date: Sun, 21 Jun 2020 18:21:28 +0200 [thread overview]
Message-ID: <20200621162132.62797-3-noh4hss@gmail.com> (raw)
In-Reply-To: <20200621162132.62797-1-noh4hss@gmail.com>
Extend the class of chardevs with a new function - chr_get_winsize.
A chardev backend should implement if it is able to get the size of
the connected terminal and can detect changes in the terminal size,
i.e. if the backend cannot detect resizes it must not implement this
(e.g. if we have a tty backend connected to some (pseudo)terminal
there is no clean way to detect resizes since SIGWINCH is sent only
for the controlling terminal).
Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
---
chardev/char-fe.c | 11 +++++++++++
chardev/char-mux.c | 7 +++++++
include/chardev/char-fe.h | 11 +++++++++++
include/chardev/char.h | 1 +
4 files changed, 30 insertions(+)
diff --git a/chardev/char-fe.c b/chardev/char-fe.c
index f3530a90e6..802d3096cd 100644
--- a/chardev/char-fe.c
+++ b/chardev/char-fe.c
@@ -336,6 +336,17 @@ void qemu_chr_fe_set_echo(CharBackend *be, bool echo)
}
}
+int qemu_chr_fe_get_winsize(CharBackend *be, uint16_t *cols, uint16_t *rows)
+{
+ Chardev *chr = be->chr;
+
+ if (chr && CHARDEV_GET_CLASS(chr)->chr_get_winsize) {
+ return CHARDEV_GET_CLASS(chr)->chr_get_winsize(chr, cols, rows);
+ }
+
+ return -1;
+}
+
void qemu_chr_fe_set_open(CharBackend *be, int fe_open)
{
Chardev *chr = be->chr;
diff --git a/chardev/char-mux.c b/chardev/char-mux.c
index 46c44af67c..368ce2334e 100644
--- a/chardev/char-mux.c
+++ b/chardev/char-mux.c
@@ -293,6 +293,12 @@ static void mux_chr_update_read_handlers(Chardev *chr)
chr->gcontext, true, false);
}
+static int mux_chr_get_winsize(Chardev *chr, uint16_t *cols, uint16_t *rows)
+{
+ MuxChardev *d = MUX_CHARDEV(chr);
+ return qemu_chr_fe_get_winsize(&d->chr, cols, rows);
+}
+
void mux_set_focus(Chardev *chr, int focus)
{
MuxChardev *d = MUX_CHARDEV(chr);
@@ -385,6 +391,7 @@ static void char_mux_class_init(ObjectClass *oc, void *data)
cc->chr_be_event = mux_chr_be_event;
cc->chr_machine_done = open_muxes;
cc->chr_update_read_handler = mux_chr_update_read_handlers;
+ cc->chr_get_winsize = mux_chr_get_winsize;
}
static const TypeInfo char_mux_type_info = {
diff --git a/include/chardev/char-fe.h b/include/chardev/char-fe.h
index a553843364..b7943df93a 100644
--- a/include/chardev/char-fe.h
+++ b/include/chardev/char-fe.h
@@ -154,6 +154,17 @@ int qemu_chr_fe_wait_connected(CharBackend *be, Error **errp);
*/
void qemu_chr_fe_set_echo(CharBackend *be, bool echo);
+/**
+ * qemu_chr_fe_get_winsize:
+ * @cols: the address for storing columns
+ * @rows: the address for storing rows
+ *
+ * Get the terminal size of the backend.
+ *
+ * Returns: 0 on success and < 0 on error
+ */
+int qemu_chr_fe_get_winsize(CharBackend *be, uint16_t *cols, uint16_t *rows);
+
/**
* qemu_chr_fe_set_open:
*
diff --git a/include/chardev/char.h b/include/chardev/char.h
index 00589a6025..fb20707917 100644
--- a/include/chardev/char.h
+++ b/include/chardev/char.h
@@ -276,6 +276,7 @@ typedef struct ChardevClass {
void (*chr_be_event)(Chardev *s, QEMUChrEvent event);
/* Return 0 if succeeded, 1 if failed */
int (*chr_machine_done)(Chardev *chr);
+ int (*chr_get_winsize)(Chardev *chr, uint16_t *cols, uint16_t *rows);
} ChardevClass;
Chardev *qemu_chardev_new(const char *id, const char *typename,
--
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 ` Szymon Lukasz [this message]
2020-06-21 16:21 ` [PATCH 3/6] chardev: add support for notifying about terminal resizes Szymon Lukasz
2020-06-21 16:21 ` [PATCH 4/6] char-stdio: add support for the terminal size Szymon Lukasz
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-3-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).