qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Amit Shah <amit.shah@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: Amit Shah <amit.shah@redhat.com>,
	Kusanagi Kouichi <slash@ac.auone-net.jp>,
	qemu list <qemu-devel@nongnu.org>
Subject: [Qemu-devel] [PATCH 1/2] char: Handle resize.
Date: Mon,  3 May 2010 12:06:32 +0530	[thread overview]
Message-ID: <1272868593-3795-1-git-send-email-amit.shah@redhat.com> (raw)

From: Kusanagi Kouichi <slash@ac.auone-net.jp>

Signed-off-by: Kusanagi Kouichi <slash@ac.auone-net.jp>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
 qemu-char.c |   34 ++++++++++++++++++++++++++++++++++
 qemu-char.h |    3 +++
 2 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index ac65a1c..ce24483 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -437,6 +437,11 @@ static void mux_chr_event(void *opaque, int event)
     MuxDriver *d = chr->opaque;
     int i;
 
+    if (event == CHR_EVENT_RESIZE) {
+        chr->rows = d->drv->rows;
+        chr->cols = d->drv->cols;
+    }
+
     /* Send the event to all registered listeners */
     for (i = 0; i < d->mux_cnt; i++)
         mux_chr_send_event(d, i, event);
@@ -465,6 +470,10 @@ static void mux_chr_update_read_handler(CharDriverState *chr)
     d->focus = d->mux_cnt;
     d->mux_cnt++;
     mux_chr_send_event(d, d->focus, CHR_EVENT_MUX_IN);
+
+    if (chr->rows > 0 && chr->cols > 0) {
+        mux_chr_send_event(d, d->focus, CHR_EVENT_RESIZE);
+    }
 }
 
 static CharDriverState *qemu_chr_open_mux(CharDriverState *drv)
@@ -545,6 +554,7 @@ int send_all(int fd, const void *buf, int len1)
 typedef struct {
     int fd_in, fd_out;
     int max_size;
+    QEMUTimer *timer;
 } FDCharDriver;
 
 #define STDIO_MAX_CLIENTS 1
@@ -600,6 +610,8 @@ static void fd_chr_update_read_handler(CharDriverState *chr)
                                  fd_chr_read, NULL, chr);
         }
     }
+
+    qemu_mod_timer(s->timer, qemu_get_clock(vm_clock));
 }
 
 static void fd_chr_close(struct CharDriverState *chr)
@@ -613,10 +625,31 @@ static void fd_chr_close(struct CharDriverState *chr)
         }
     }
 
+    qemu_del_timer(s->timer);
+    qemu_free_timer(s->timer);
     qemu_free(s);
     qemu_chr_event(chr, CHR_EVENT_CLOSED);
 }
 
+static void fd_chr_timer(void *opaque)
+{
+    struct CharDriverState *chr = opaque;
+    FDCharDriver *s = chr->opaque;
+    struct winsize size;
+
+    if (ioctl(s->fd_out, TIOCGWINSZ, &size) == -1) {
+        return;
+    }
+
+    if (size.ws_row != chr->rows || size.ws_col != chr->cols) {
+        chr->rows = size.ws_row;
+        chr->cols = size.ws_col;
+        qemu_chr_event(chr, CHR_EVENT_RESIZE);
+    }
+
+    qemu_mod_timer(s->timer, qemu_get_clock(vm_clock) + get_ticks_per_sec());
+}
+
 /* open a character device to a unix fd */
 static CharDriverState *qemu_chr_open_fd(int fd_in, int fd_out)
 {
@@ -627,6 +660,7 @@ static CharDriverState *qemu_chr_open_fd(int fd_in, int fd_out)
     s = qemu_mallocz(sizeof(FDCharDriver));
     s->fd_in = fd_in;
     s->fd_out = fd_out;
+    s->timer = qemu_new_timer(vm_clock, fd_chr_timer, chr);
     chr->opaque = s;
     chr->chr_write = fd_chr_write;
     chr->chr_update_read_handler = fd_chr_update_read_handler;
diff --git a/qemu-char.h b/qemu-char.h
index e3a0783..4fa2812 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -15,6 +15,7 @@
 #define CHR_EVENT_MUX_IN  3 /* mux-focus was set to this terminal */
 #define CHR_EVENT_MUX_OUT 4 /* mux-focus will move on */
 #define CHR_EVENT_CLOSED  5 /* connection closed */
+#define CHR_EVENT_RESIZE  6 /* terminal resize */
 
 
 #define CHR_IOCTL_SERIAL_SET_PARAMS   1
@@ -68,6 +69,8 @@ struct CharDriverState {
     char *label;
     char *filename;
     int opened;
+    int rows;
+    int cols;
     QTAILQ_ENTRY(CharDriverState) next;
 };
 
-- 
1.6.2.5

             reply	other threads:[~2010-05-03  6:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-03  6:36 Amit Shah [this message]
2010-05-03  6:36 ` [Qemu-devel] [PATCH 2/2] virtio-console: Notify resize to the guest Amit Shah
2010-05-03  8:03   ` [Qemu-devel] " Amit Shah
  -- strict thread matches above, loose matches on Subject: below --
2010-05-05 20:50 [Qemu-devel] [PATCH 1/2] char: Handle resize Amit Shah
2010-04-16 11:42 Kusanagi Kouichi

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=1272868593-3795-1-git-send-email-amit.shah@redhat.com \
    --to=amit.shah@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=qemu-devel@nongnu.org \
    --cc=slash@ac.auone-net.jp \
    /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).