From patchwork Wed May 5 20:50:05 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 51768 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CEC0CB7D4A for ; Thu, 6 May 2010 09:55:28 +1000 (EST) Received: from localhost ([127.0.0.1]:56560 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9oR4-0001SW-1G for incoming@patchwork.ozlabs.org; Wed, 05 May 2010 19:55:26 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O9lZk-00085x-Ba for qemu-devel@nongnu.org; Wed, 05 May 2010 16:52:12 -0400 Received: from [140.186.70.92] (port=50944 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9lZh-00083h-Mr for qemu-devel@nongnu.org; Wed, 05 May 2010 16:52:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O9lZb-0001zk-KQ for qemu-devel@nongnu.org; Wed, 05 May 2010 16:52:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4886) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O9lZb-0001zf-9M for qemu-devel@nongnu.org; Wed, 05 May 2010 16:52:03 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o45KpmrI022911 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 5 May 2010 16:51:48 -0400 Received: from localhost (vpn-240-233.phx2.redhat.com [10.3.240.233]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o45Kpkop016707; Wed, 5 May 2010 16:51:47 -0400 From: Amit Shah To: Anthony Liguori Date: Thu, 6 May 2010 02:20:05 +0530 Message-Id: <1273092606-23099-1-git-send-email-amit.shah@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Amit Shah , Kusanagi Kouichi , qemu list Subject: [Qemu-devel] [PATCH 1/2] char: Handle resize. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Kusanagi Kouichi Signed-off-by: Kusanagi Kouichi Signed-off-by: Amit Shah --- 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; };