From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9E072CA5FA5 for ; Tue, 29 Sep 2026 16:42:16 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBasl-00058j-5h; Tue, 29 Sep 2026 12:40:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBasj-00057m-7T for qemu-devel@nongnu.org; Tue, 29 Sep 2026 12:40:41 -0400 Received: from mail-wr2-x0f.google.com ([2a00:1450:4864:30::f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBasg-0006Mg-2v for qemu-devel@nongnu.org; Tue, 29 Sep 2026 12:40:39 -0400 Received: by mail-wr2-x0f.google.com with SMTP id ffacd0b85a97d-4888129c46eso2525847f8f.1 for ; Tue, 29 Sep 2026 09:40:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790700036; x=1791304836; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=GUvdc5pSabY72yhnIxUmFj2RHWlQFpUyB4LPoq4EGO4=; b=hU3PQhH5g9p5vUkJtZJdTejdYTaxbUe+lyfWe2V+JzjiPijGyR+3MVdkM26X39KKxZ AzHo4ugfUYRtVrA0f9tl6iPwYC/Pu3moEjkVCRYqq+wa2si1l3fe6GCKp70n28B4oxfP 9mIPwwHU9Cax2iU51NtG/bpgfTgFvzEPkLrAyXEUGtScc5qDjAzeGOTJAXz37J1Wn4M9 kAjO7vmzSL4k/dUVQthLUB3BFHo/xR2CrkPqWCkhUJKDBHr8MR53hw9xhqkrohbddfkB E4KSeCnKUOqCbcKKapVv+/YORzcf8wzR3QN+sLaQUT5cipkkiiNkWcopzSTbhZjNtR3N nmyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790700036; x=1791304836; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=GUvdc5pSabY72yhnIxUmFj2RHWlQFpUyB4LPoq4EGO4=; b=21YadMGhm01ZpU80nDw3vhX0b0wfe+V3QLPt+S+2wALXSPPAZOTNR7nsbKdCbAx34W pm3M5Q5qzpyCwp39BcSqNSLHNg0AmOPNNj4FGXsiKzbj0lke30B6mecesXbWzM+rS234 3j/tdMa+lHYcvvOQD6gctRfFwSpsdakPspQC8PEDVWoMI2VK6z92BMLAUjSoGvY4t7Fd 7gUSm6nrRl/V2wf3uWWQQLEvAV9GlYZeCNefBqE74UCO7wny6TjYE8t/dkPbDi5/zfSY 1y0hVd3cn6gquxcpR0tJ+ScFKMpQbpMh53AiQI/D5hFdsCwsuMzKxgmIdYQ9aZkrXEfA 5dKw== X-Gm-Message-State: AFq9FYIStcSwwiFX2AHsFETyeTkGVO2u96nrjm4hB7cEHYFYxHfV3bOc xTbWb6T77T+55XuGTEI4ctwvdFseGkxj6AX+rGS2VCKx5SEzhuRmLRmc X-Gm-Gg: AYBFou3/y18OhPXweNvNmiJUOLbZkJXdnaZGveOf12n3pVyseAsXjyIZhe9BPaapbka /PfZPosUIOJL6Oj6T4+eWmbOFhER6unS3On0DlKBXqsSDOwBqE1YHMmwSah/wTk/8m5gWEll7hz cZ3457TUJOr4fvVEejRq2XlvHceQAOZrbS1e3NbfW5F/bM2h+5Bv6X3WWDpp35fduTp/xVgNROx CCftxEmq1Y8YmAcFzVARR4T4LkLrl9J3+yfS0p/sQ0eCiZ5CYNLGSsLJr5ywLC/ykTJG3k0l6UW K5yrAGGgGI96Yins3PWST4GPg3+qCLHgUmy5krJCpRsT/EV0DMBetslnO9J/hJFN2JrXIfjuE9f 978w+qB0JvWmpJm4H7c29rVm9X6RLchIKJoVCN24LZugovyU1Qi7RTIQHuILrPSYQldArsk/gw1 5AzLCV+xIw1boK1M4DfNR7cSfGrn4sJ9gjcjPXjZHEUpDE3ycJol9PtZAyOrFed54+ifDGjRURg qAf9F8kOXJavsLu6ohgDU2AmP/4yBMgQ6gKmw== X-Received: by 2002:a05:6000:29d8:b0:488:764a:c09c with SMTP id ffacd0b85a97d-488764ac355mr17912758f8f.27.1790700036592; Tue, 29 Sep 2026 09:40:36 -0700 (PDT) Received: from localhost (mem-185.47.220.165.jmnet.cz. [185.47.220.165]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48af502cd22sm5337497f8f.13.2026.09.29.09.40.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 09:40:36 -0700 (PDT) From: Filip Hejsek Date: Tue, 29 Sep 2026 18:38:34 +0200 Subject: [PATCH v8 06/12] char-stdio: add support for the terminal size MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20260929-console-resize-v8-6-2ff9183f8750@gmail.com> References: <20260929-console-resize-v8-0-2ff9183f8750@gmail.com> In-Reply-To: <20260929-console-resize-v8-0-2ff9183f8750@gmail.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , "Michael S. Tsirkin" , Laurent Vivier , Amit Shah , Markus Armbruster , Eric Blake , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Zhao Liu , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Maximilian Immanuel Brandtner , Dominique Martinet , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Szymon Lukasz X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1790700030; l=2540; i=filip.hejsek@gmail.com; s=20250912; h=from:subject:message-id; bh=/0oOnfdCRy+yf2x3epn+eJzVEaL2oF++Lo4YaOLKmXg=; b=98PG3WiMRN08z3hSZGw+uZVpqyFsXy8/h394+i6NsjiVFpu6+ZMgqaEXqgMnLUItqdlGxmYB7 Wvy95StcB1PAy8YnTDtqPqOk+578F83lQFDhcJFc3+4Ml7YBtNzo27h X-Developer-Key: i=filip.hejsek@gmail.com; a=ed25519; pk=nakB8gEK3oi+Q/5dBTMCy/LgZL47NP60z1jeDR6O/WU= Received-SPF: pass client-ip=2a00:1450:4864:30::f; envelope-from=filip.hejsek@gmail.com; helo=mail-wr2-x0f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Szymon Lukasz Update the terminal size upon SIGWINCH delivery. Signed-off-by: Szymon Lukasz [Filip: use DECLARE_INSTANCE_CHECKER, qemu_chr_resize_stdio -> stdio_chr_resize] Reviewed-by: Daniel P. Berrangé Signed-off-by: Filip Hejsek --- chardev/char-stdio.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/chardev/char-stdio.c b/chardev/char-stdio.c index fe1cbb2d88..4fc8db212c 100644 --- a/chardev/char-stdio.c +++ b/chardev/char-stdio.c @@ -34,7 +34,9 @@ #include "chardev/char-win-stdio.h" #else #include +#include #include "chardev/char-fd.h" +#include "qemu/main-loop.h" #endif #ifndef _WIN32 @@ -46,6 +48,14 @@ static bool stdio_in_use; static bool stdio_allow_signal; static bool stdio_echo_state; +typedef struct { + FDChardev parent; + Notifier resize_notifier; +} StdioChardev; + +DECLARE_INSTANCE_CHECKER(StdioChardev, STDIO_CHARDEV, + TYPE_CHARDEV_STDIO) + static void term_exit(void) { if (stdio_in_use) { @@ -85,8 +95,23 @@ static void term_stdio_handler(int sig) stdio_chr_set_echo(NULL, stdio_echo_state); } +static void stdio_chr_resize(Chardev *chr) +{ + struct winsize ws; + if (ioctl(1, TIOCGWINSZ, &ws) != -1) { + qemu_chr_resize(chr, ws.ws_col, ws.ws_row); + } +} + +static void term_resize_notify(Notifier *n, void *data) +{ + StdioChardev *s = container_of(n, StdioChardev, resize_notifier); + stdio_chr_resize(CHARDEV(s)); +} + static bool stdio_chr_open(Chardev *chr, ChardevBackend *backend, Error **errp) { + StdioChardev *s = STDIO_CHARDEV(chr); ChardevStdio *opts = backend->u.stdio.data; struct sigaction act; @@ -121,6 +146,10 @@ static bool stdio_chr_open(Chardev *chr, ChardevBackend *backend, Error **errp) stdio_allow_signal = !opts->has_signal || opts->signal; stdio_chr_set_echo(chr, false); + s->resize_notifier.notify = term_resize_notify; + sigwinch_add_notifier(&s->resize_notifier); + stdio_chr_resize(chr); + qemu_chr_be_event(chr, CHR_EVENT_OPENED); return true; } @@ -162,6 +191,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.55.0