From nobody Sat Nov 15 17:47:13 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1748753676; cv=none; d=zohomail.com; s=zohoarc; b=Ywjt6oJgADLivinBDoW9Ee5bRcjhXpZHzD8D3b2te5epl6K7uwr3AsWGO3BFR5YTsIi/+j0WPOKAME9TPEZ3xe7LhDNaAGSV7SH6iznInfq6d3X4QnzkgYfPab+IpnQuEmrnxxYJOJxdRYxhdXEQTDxKgo1lJvzDpSuboLb9h50= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748753676; h=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=Y7ZYhg5f98QXcBbYXh1bLssUQ7z4lxRxh40jHAXmpIk=; b=SKNiZi7Ju+TzU1ma8PxMNhoUdgUMQ8X4Gh//nCPKwO7pU8zkOlsgmf+ZB0jqQiSKH3O0K56dFpoIl2M0hX3Vlp0RKT0/MGVHriZOFGLc1wG4BIBYZPlfl2mMkQY4/0B2XZ0adEZPl0JSjKas4KoR9YrMhDJBt4v1ce57NQ04MQQ= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1748753676184502.3775794768934; Sat, 31 May 2025 21:54:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uLahd-0006xt-8S; Sun, 01 Jun 2025 00:53:45 -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 1uLahX-0006x8-6t for qemu-devel@nongnu.org; Sun, 01 Jun 2025 00:53:39 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uLahV-0002QG-Ao for qemu-devel@nongnu.org; Sun, 01 Jun 2025 00:53:38 -0400 Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-309fac646adso4044597a91.1 for ; Sat, 31 May 2025 21:53:36 -0700 (PDT) Received: from localhost ([103.192.227.65]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3124e39742fsm3826144a91.27.2025.05.31.21.53.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 May 2025 21:53:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748753615; x=1749358415; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y7ZYhg5f98QXcBbYXh1bLssUQ7z4lxRxh40jHAXmpIk=; b=jh64UG/cfuMmcZowWBSVewsNE0NWLuU6E0vSf2xMRLzWfiWVptut40sGUN+617Xe+d nwT/nwAEQUsDqLuXBeXPsk4cCW2Oyx93LUFg2PtopW+6iGIYApiyWKGrAOtnJyV6kWnQ TXyMmRfQo6Mvpj1mr8Z5ZTNopKq8os8iCb/d16osGb6EV/vL0IE7PFApjcDmzrgxr89I rTZc7o2zif9uuIsXBMPYUL5WgpiKrulk+ehlceNY8mre4+ILSJ2FJ5PPwrXeYaf1z6zN SgESsSWgb9DveRfJ+7RDCq6dWRXiDDpUN8auShWfk0qr5//uL2AoZDEbcpy2EEY36/Az B0OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748753615; x=1749358415; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y7ZYhg5f98QXcBbYXh1bLssUQ7z4lxRxh40jHAXmpIk=; b=QhF/+S7NrkrWUvYMbCu2eQINV2+UuZ+SqWBM0CFfXMNRWpcSjUaLGqDHVmgAFXxDYN P9Tz/GKTfU4LZaP4zw4gCmbMEFGSKSkyatKSD1xeFUGegyV6UvdT7nwEdSClKNBTq1Ew ++qlFWwRQkbevsVt1/GpuNYucs25XJn24PiIc0dMIKMTdoFdVgWh3mOfodfwkUGdclav JOHn5GEeQsZLWQP54Kvdk+aLPnTpafhDwWlYeUvXqPs4aOL2fakFnDl8UOculvnTc5BI qTyp/4OW86SZuUYo2ahhm5ceMKQfztps70Y1GJ7woohtCUn7EksKwrw9g4Wwv1yG+fjF sSLw== X-Gm-Message-State: AOJu0YyQOgjvVozgDk4isgj0ZiBx2wpBaS4kuvTxIyxVR8R5G93JRhHI mr3yaM4vywgMcYLHhqlrALmNUmqPKxq9F8luBGWlv/kCaOD+CF3dxDpYcIq27wGEs94= X-Gm-Gg: ASbGncsAkDx1SqYECEco+OAUrSAH5MqzWVkiOgvkyUc1TRblL+hJkIgp4TqnTbPw1rL tWcjcY2KIImHrhAQnmT5ydOZEEqym7InQcIXnD/kR0sxvS2wreBQWv845Lyj1xigOynuVrEDeum coYuJDdSnWlnxy9oCkMdzSYvyyJPQ3fWG5PIvojns8KXAAjZEELIq8KrFXk6oqyQDdkjgqA38tF EtYqmAi1sQHw3WtIzoc3j7FNLYzUmF24FeSbdRWieTm/oxFFd9m9f1AETntzjneN7WVbKCsdZvC cICzeoR2cYmkWk/BTiBf2/wVERMJkCx7Mfon4SOuN+0fM4bL5u/t0zg= X-Google-Smtp-Source: AGHT+IGGqwHw6ODHmRWSFNxp51iCyS4Jfaoy2DHYndnl8W/ZS5TJcss3iF99UrAPQBMq/xFNS3fIwg== X-Received: by 2002:a17:90b:4a0d:b0:310:b602:bc52 with SMTP id 98e67ed59e1d1-31214e11d96mr19215353a91.2.1748753614715; Sat, 31 May 2025 21:53:34 -0700 (PDT) From: Weifeng Liu To: qemu-devel@nongnu.org Cc: Weifeng Liu , BALATON Zoltan , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Kim, Dongwon" , Dmitry Osipenko , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH 1/2] ui/gtk: Add keep-aspect-ratio option Date: Sun, 1 Jun 2025 12:52:32 +0800 Message-ID: <20250601045245.36778-2-weifeng.liu.z@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250601045245.36778-1-weifeng.liu.z@gmail.com> References: <20250601045245.36778-1-weifeng.liu.z@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::1032; envelope-from=weifeng.liu.z@gmail.com; helo=mail-pj1-x1032.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: 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 @gmail.com) X-ZM-MESSAGEID: 1748753678860116600 Content-Type: text/plain; charset="utf-8" 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 --- include/ui/gtk.h | 1 + qapi/ui.json | 12 ++++++++---- ui/gtk.c | 12 ++++++++++-- 3 files changed, 19 insertions(+), 6 deletions(-) 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/qapi/ui.json b/qapi/ui.json index 3d0c853c9a..4f7d994e26 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/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.49.0 From nobody Sat Nov 15 17:47:13 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1748753676; cv=none; d=zohomail.com; s=zohoarc; b=gLSu/D/1aGki8RbvCvOnguJKDJHV7XrJ7SMzb1OVhjRqDlLdU9a0QDNb6ZhjyqAIMYosNV5zKyzLuvTplk3qL6w2VG1kHjHjRtAdnT7rLzeAHxH5Un6+7B1n2SbktEK0y3QubWvkskcBRHFjgyJGt9rCjQoH6hO3E+3ghnp7ULo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748753676; h=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=I8+mq13Ike4tII/xN10loMuJgw5sR3KYt5pU1khJptI=; b=PuNdYgGeR7TCwy1+k9u06cW47QQS16H/S7m/TUfCbLzLK5k4hdttPOEQXiHecplQAqYYYQp1LNJBdpK67JBIZOc/hYCtH4aZotI+OzksbB3N03p6rEM4WCTwv7JRJ+csE8XYA25lm7OPuUKxWKZFzDLJgNqvKIhA/y2ddiYIezY= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1748753676218865.4293163592166; Sat, 31 May 2025 21:54:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uLahi-0006yq-AL; Sun, 01 Jun 2025 00:53:50 -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 1uLahc-0006xs-Id for qemu-devel@nongnu.org; Sun, 01 Jun 2025 00:53:45 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uLahZ-0002Ro-Li for qemu-devel@nongnu.org; Sun, 01 Jun 2025 00:53:44 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-7376dd56f8fso3869782b3a.2 for ; Sat, 31 May 2025 21:53:41 -0700 (PDT) Received: from localhost ([103.192.227.65]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-747affaf9e5sm5411451b3a.86.2025.05.31.21.53.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 May 2025 21:53:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748753619; x=1749358419; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=I8+mq13Ike4tII/xN10loMuJgw5sR3KYt5pU1khJptI=; b=CZ3XpOmfrAGWknF4cG90azSZ93oUuwRuMT8BK5gVBSLwgFsBd+vdKRBjdlETH2B/kb fWpFOId3QPRMDI608FQsuhgU715zsFcSdmQgco4ZIPEYtwMg257BpSNXtO+IcMvWrHAx Qnw8e41D2yLEX7ZyxAW504DOpwKyK8603PuNn+IU0svxKQU3/qIvHa4CKP29E1BfN/Nx DZkF7VO+qcHoNSXLWvXPBSBGInW3jkc79/tV91Ccqd8KGwjpEk+UqhqxvPfqxwMwca9e Z6nkwOM5J6yLVJJwDvdk3xK35qsWfEukP5t63ECDz/LmO+0Bv3UBOkT8STZS9oRzXnm9 o3sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748753619; x=1749358419; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=I8+mq13Ike4tII/xN10loMuJgw5sR3KYt5pU1khJptI=; b=bAs8pfVgAksEEdgZSaPIpehlKGMWl1U5TkGFruorHETOCGlZAleJZ3KxZdycmh/Wpn HddHDpQnxer1vSu7yOkzclF2WYtebCnTVjiKJ+Dy85dd5OkPJdR/GZMHqKBRi3/5kEiE WJuAPY341vDC2Z4LNTTWhMG/HzutBqVjLzRSEfR8fgAKpfobMDDHE5lDvRGMYnTGUNJe Y7BSm27iKvEnEMPBx5mgC+uhDhrrRy5ZFL15Z2eLYd3TZj3rqA2kZajS06bspsVDah0i gvpohgevgy/OvsYFDmFtkONlPco+EUMZOxdxO7K+IhuZ0jGkidGfDY0gF1hF36r08K9Z dDEw== X-Gm-Message-State: AOJu0YxRClO73YCF7wyhqLlBBRb78gsczjLtmdTxOL1HXs8r4EF3aniq zsxS7zQ3HIYQvCncIO/67nf3Xm7aRoA+ncgy5UtGpNCkp69rHM4h+pDfXqGS4EKMhb0= X-Gm-Gg: ASbGncsWKXigKYdf+xyFlbaICcx6DH3cT/4FRFlM20CA0hH4dutIiTd1e+H3F9BAlXl a+NIlbZDEJzvclTCqDBl+bue3FP96ipbQqKC6w1wZzzesPZ2dHyas21eCiDfarNjJKOWxXAFGqT QnwuVQ7EjbEiNfaU3rzwL00vS5OJj6+IML0GJQS6sEl32MPF98Czn6UctIBTmrMKKPT2UI98Lu6 XxBY18NMTqPYBI+kXWN22s0d8IeuZAt2YhdFWb8PJrgs8sJhvw/j6U8XHcdzenXsQxPV9k+Iyb0 zEqBIQOz/jw86wnZNEg+GDtwYjeXqhpSc08FDc/yQQpAZg2f5Lo5muw= X-Google-Smtp-Source: AGHT+IE29cZRw/GowY6WCBbka3EeJTjCjmKIUtKXJq98fFLDgK7oq3z5eFXgTamfo0fgw5xsjaJCIg== X-Received: by 2002:a05:6a21:32a5:b0:21a:d7ad:e0c7 with SMTP id adf61e73a8af0-21ad979928cmr16035597637.34.1748753619474; Sat, 31 May 2025 21:53:39 -0700 (PDT) From: Weifeng Liu To: qemu-devel@nongnu.org Cc: Weifeng Liu , BALATON Zoltan , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Kim, Dongwon" , Dmitry Osipenko , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH 2/2] ui/gtk: Add scale option Date: Sun, 1 Jun 2025 12:52:33 +0800 Message-ID: <20250601045245.36778-3-weifeng.liu.z@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250601045245.36778-1-weifeng.liu.z@gmail.com> References: <20250601045245.36778-1-weifeng.liu.z@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::42d; envelope-from=weifeng.liu.z@gmail.com; helo=mail-pf1-x42d.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: 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 @gmail.com) X-ZM-MESSAGEID: 1748753679033116600 Content-Type: text/plain; charset="utf-8" Allow user to set a preferred scale (defaulting to 1) of the virtual display. Along with zoom-to-fix=3Dfalse, this would be helpful for users running QEMU on hi-dpi host desktop to achieve pixel to pixel display -- e.g., if the scale factor of a user's host desktop is set to 200%, then they can set a 0.5 scale for the virtual display to avoid magnification that might cause blurriness. Signed-off-by: Weifeng Liu Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Marc-Andr=C3=A9 Lureau --- include/ui/gtk.h | 1 + qapi/ui.json | 5 ++++- ui/gtk.c | 46 +++++++++++++++++++++++++++++----------------- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/include/ui/gtk.h b/include/ui/gtk.h index b7cfbf218e..3e6ce3cb48 100644 --- a/include/ui/gtk.h +++ b/include/ui/gtk.h @@ -41,6 +41,7 @@ typedef struct VirtualGfxConsole { DisplaySurface *ds; pixman_image_t *convert; cairo_surface_t *surface; + double preferred_scale; double scale_x; double scale_y; #if defined(CONFIG_OPENGL) diff --git a/qapi/ui.json b/qapi/ui.json index 4f7d994e26..023d055ef1 100644 --- a/qapi/ui.json +++ b/qapi/ui.json @@ -1338,6 +1338,8 @@ # @keep-aspect-ratio: Keep width/height aspect ratio of guest content when # resizing host window. Defaults to "on". (Since 10.1) # +# @scale: Set preferred scale of the display. Defaults to 1.0. (Since 10= .1) +# # Since: 2.12 ## { 'struct' : 'DisplayGTK', @@ -1345,7 +1347,8 @@ '*zoom-to-fit' : 'bool', '*show-tabs' : 'bool', '*show-menubar' : 'bool', - '*keep-aspect-ratio' : 'bool' } } + '*keep-aspect-ratio' : 'bool', + '*scale' : 'number' } } =20 ## # @DisplayEGLHeadless: diff --git a/ui/gtk.c b/ui/gtk.c index 9104509ee1..e91d093a49 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -67,6 +67,7 @@ #define VC_TERM_X_MIN 80 #define VC_TERM_Y_MIN 25 #define VC_SCALE_MIN 0.25 +#define VC_SCALE_MAX 4 #define VC_SCALE_STEP 0.25 =20 #ifdef GDK_WINDOWING_X11 @@ -272,15 +273,11 @@ static void gd_update_geometry_hints(VirtualConsole *= vc) if (!vc->gfx.ds) { return; } - if (s->free_scale) { - geo.min_width =3D surface_width(vc->gfx.ds) * VC_SCALE_MIN; - geo.min_height =3D surface_height(vc->gfx.ds) * VC_SCALE_MIN; - mask |=3D GDK_HINT_MIN_SIZE; - } else { - geo.min_width =3D surface_width(vc->gfx.ds) * vc->gfx.scale_x; - geo.min_height =3D surface_height(vc->gfx.ds) * vc->gfx.scale_= y; - mask |=3D GDK_HINT_MIN_SIZE; - } + double scale_x =3D s->free_scale ? VC_SCALE_MIN : vc->gfx.scale_x; + double scale_y =3D s->free_scale ? VC_SCALE_MIN : vc->gfx.scale_y; + geo.min_width =3D surface_width(vc->gfx.ds) * scale_x; + geo.min_height =3D surface_height(vc->gfx.ds) * scale_y; + mask |=3D GDK_HINT_MIN_SIZE; geo_widget =3D vc->gfx.drawing_area; gtk_widget_set_size_request(geo_widget, geo.min_width, geo.min_hei= ght); =20 @@ -1579,8 +1576,8 @@ static void gd_menu_full_screen(GtkMenuItem *item, vo= id *opaque) } s->full_screen =3D FALSE; if (vc->type =3D=3D GD_VC_GFX) { - vc->gfx.scale_x =3D 1.0; - vc->gfx.scale_y =3D 1.0; + vc->gfx.scale_x =3D vc->gfx.preferred_scale; + vc->gfx.scale_y =3D vc->gfx.preferred_scale; gd_update_windowsize(vc); } } @@ -1636,8 +1633,8 @@ static void gd_menu_zoom_fixed(GtkMenuItem *item, voi= d *opaque) GtkDisplayState *s =3D opaque; VirtualConsole *vc =3D gd_vc_find_current(s); =20 - vc->gfx.scale_x =3D 1.0; - vc->gfx.scale_y =3D 1.0; + vc->gfx.scale_x =3D vc->gfx.preferred_scale; + vc->gfx.scale_y =3D vc->gfx.preferred_scale; =20 gd_update_windowsize(vc); } @@ -1651,8 +1648,8 @@ static void gd_menu_zoom_fit(GtkMenuItem *item, void = *opaque) s->free_scale =3D TRUE; } else { s->free_scale =3D FALSE; - vc->gfx.scale_x =3D 1.0; - vc->gfx.scale_y =3D 1.0; + vc->gfx.scale_x =3D vc->gfx.preferred_scale; + vc->gfx.scale_y =3D vc->gfx.preferred_scale; } =20 gd_update_windowsize(vc); @@ -2243,6 +2240,11 @@ static void gl_area_realize(GtkGLArea *area, Virtual= Console *vc) } #endif =20 +static bool gd_scale_valid(double scale) +{ + return scale >=3D VC_SCALE_MIN && scale <=3D VC_SCALE_MAX; +} + static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc, QemuConsole *con, int idx, GSList *group, GtkWidget *view_menu) @@ -2252,8 +2254,18 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, Vi= rtualConsole *vc, =20 vc->label =3D qemu_console_get_label(con); vc->s =3D s; - vc->gfx.scale_x =3D 1.0; - vc->gfx.scale_y =3D 1.0; + vc->gfx.preferred_scale =3D 1.0; + if (s->opts->u.gtk.has_scale) { + if (gd_scale_valid(s->opts->u.gtk.scale)) { + vc->gfx.preferred_scale =3D s->opts->u.gtk.scale; + } else { + error_report("Invalid scale value %lf given, being ignored", + s->opts->u.gtk.scale); + s->opts->u.gtk.has_scale =3D false; + } + } + vc->gfx.scale_x =3D vc->gfx.preferred_scale; + vc->gfx.scale_y =3D vc->gfx.preferred_scale; =20 #if defined(CONFIG_OPENGL) if (display_opengl) { --=20 2.49.0