From nobody Sat Nov 15 12:48:48 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752561914; cv=none; d=zohomail.com; s=zohoarc; b=MeC79ox4jObhy3t8e+k4jP3lgjYgpCSGb1q41bZa56mfZUXuPV5HCx61TsNQ2Q6pLbMZVmRyrzqwGPXRTNjsnm1Rk/6CCnTeKi5qiLchJPqohWGsSuPDyd0j2W4aLHFsiPiWjAJiiqaNGPzhuEAtN5FOJE5lRZiD2rMVZPRlt1Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752561914; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=aKPy83W1hiV5/W0xo6GAaKjDBMB+hmRcxLmXHAgpL6c=; b=FOva52WQnhRnERUysVDBTigrpQPwE0U1ixayhySm5YphSoJOcNJZbTqmwILrk/YELt4MofrzFqTKbrZ4lUOsx4H8gB9qw//zW9hek01xf+eNLM426C0GU3c5kn5FWqUkO5S172jvd1p7yxjONahD3khxIsgf1C0tw+Cu49Uk6LY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752561914153499.31458456549956; Mon, 14 Jul 2025 23:45:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubZMi-0003EE-Ha; Tue, 15 Jul 2025 02:42:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubZF9-0003R3-Qb for qemu-devel@nongnu.org; Tue, 15 Jul 2025 02:34:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubZF7-0003kf-WD for qemu-devel@nongnu.org; Tue, 15 Jul 2025 02:34:23 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-232-kCyp9wt-PrqGkG66rdGAXw-1; Tue, 15 Jul 2025 02:34:19 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B0EDA19560B1; Tue, 15 Jul 2025 06:34:18 +0000 (UTC) Received: from localhost (unknown [10.45.242.9]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 30902195609D; Tue, 15 Jul 2025 06:34:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752561261; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aKPy83W1hiV5/W0xo6GAaKjDBMB+hmRcxLmXHAgpL6c=; b=Ilj6UjT+5tEFxLNWMG+ix8f/iZ8WORMPX+HMeIGANaeVYD+l3t3s2nFWjcEA9DRLgXUm9/ 0wGv+H9YA3do9TDLzUoogF9pq8WT3m08TUuqklTM9smFwDIj2Cz3LGgQsjUYLzk/zKgVGo Tyrrs9vJOHq/I0WogPGbM96XUbkhHIo= X-MC-Unique: kCyp9wt-PrqGkG66rdGAXw-1 X-Mimecast-MFC-AGG-ID: kCyp9wt-PrqGkG66rdGAXw_1752561258 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, Weifeng Liu , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eric Blake , Markus Armbruster Subject: [PULL v2 11/13] ui/gtk: Add keep-aspect-ratio option Date: Tue, 15 Jul 2025 10:32:57 +0400 Message-ID: <20250715063301.145191-12-marcandre.lureau@redhat.com> In-Reply-To: <20250715063301.145191-1-marcandre.lureau@redhat.com> References: <20250715063301.145191-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752561915941116600 From: Weifeng Liu When aspect ratio of host window and that of guest display are not aligned, we can either zoom the guest content to fill the whole host window or add padding to respect aspect ratio of the guest. Add an option keep-aspect-ratio to allow users to select their preferred behavior in this case. Suggested-by: BALATON Zoltan Suggested-by: Kim, Dongwon Signed-off-by: Weifeng Liu Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Marc-Andr=C3=A9 Lureau Message-Id: <20250601045245.36778-2-weifeng.liu.z@gmail.com> --- qapi/ui.json | 12 ++++++++---- include/ui/gtk.h | 1 + ui/gtk.c | 12 ++++++++++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/qapi/ui.json b/qapi/ui.json index 514fa159b1..9e496b4835 100644 --- a/qapi/ui.json +++ b/qapi/ui.json @@ -1335,13 +1335,17 @@ # @show-menubar: Display the main window menubar. Defaults to "on". # (Since 8.0) # +# @keep-aspect-ratio: Keep width/height aspect ratio of guest content when +# resizing host window. Defaults to "on". (Since 10.1) +# # Since: 2.12 ## { 'struct' : 'DisplayGTK', - 'data' : { '*grab-on-hover' : 'bool', - '*zoom-to-fit' : 'bool', - '*show-tabs' : 'bool', - '*show-menubar' : 'bool' } } + 'data' : { '*grab-on-hover' : 'bool', + '*zoom-to-fit' : 'bool', + '*show-tabs' : 'bool', + '*show-menubar' : 'bool', + '*keep-aspect-ratio' : 'bool' } } =20 ## # @DisplayEGLHeadless: diff --git a/include/ui/gtk.h b/include/ui/gtk.h index d3944046db..b7cfbf218e 100644 --- a/include/ui/gtk.h +++ b/include/ui/gtk.h @@ -140,6 +140,7 @@ struct GtkDisplayState { GdkCursor *null_cursor; Notifier mouse_mode_notifier; gboolean free_scale; + gboolean keep_aspect_ratio; =20 bool external_pause_update; =20 diff --git a/ui/gtk.c b/ui/gtk.c index 8c4a94c8f6..9104509ee1 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -828,8 +828,12 @@ void gd_update_scale(VirtualConsole *vc, int ww, int w= h, int fbw, int fbh) =20 sx =3D (double)ww / fbw; sy =3D (double)wh / fbh; - - vc->gfx.scale_x =3D vc->gfx.scale_y =3D MIN(sx, sy); + if (vc->s->keep_aspect_ratio) { + vc->gfx.scale_x =3D vc->gfx.scale_y =3D MIN(sx, sy); + } else { + vc->gfx.scale_x =3D sx; + vc->gfx.scale_y =3D sy; + } } } /** @@ -2328,6 +2332,10 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, Vi= rtualConsole *vc, s->free_scale =3D true; } =20 + s->keep_aspect_ratio =3D true; + if (s->opts->u.gtk.has_keep_aspect_ratio) + s->keep_aspect_ratio =3D s->opts->u.gtk.keep_aspect_ratio; + for (i =3D 0; i < INPUT_EVENT_SLOTS_MAX; i++) { struct touch_slot *slot =3D &touch_slots[i]; slot->tracking_id =3D -1; --=20 2.50.0