From nobody Mon Feb 9 23:59:43 2026 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1711468130; cv=none; d=zohomail.com; s=zohoarc; b=Q15eAAUU0xh1KtZdXeuIDdWCP2ZRVevjSm8brEOi3S3OlRAIfqyt1hKotnaQTCyqWK/sXBFsfi8vm9adboAUQ0OEArS4OauPGYqvCsDyet3ss+bSXLWBn3qA3RdyJ/Uzeu56i2i5cwXzR+0M7Qls+AvCii07/A6R5etoMa7VLBU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1711468130; 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=pTnsklKw4fWTCEXstwwApylL5b79xPCluS5bdtq/AP4=; b=hEXxRv27le/tt4yypMHQ+GouoHtfjI4UhHhkFrGqwFzMaAhdSEuxqWhWbHau5Z0LaRUwf8SOeiplLz8pABy4so5F314r3k7SAFAB08c28RJa44J11UzzaZv5AaK1c/XkK9x07d+n/uBuyEtmhcbL0rIhEc6WcjV0gNqOvSSQ4g0= 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 1711468130706780.6427590443609; Tue, 26 Mar 2024 08:48:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rp90E-0004YF-Hm; Tue, 26 Mar 2024 11:46:18 -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 1rp90A-0004Du-Sd for qemu-devel@nongnu.org; Tue, 26 Mar 2024 11:46:14 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rp909-0001JS-1c for qemu-devel@nongnu.org; Tue, 26 Mar 2024 11:46:14 -0400 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-341c7c8adf3so2025402f8f.0 for ; Tue, 26 Mar 2024 08:46:12 -0700 (PDT) Received: from m1x-phil.lan ([176.176.155.229]) by smtp.gmail.com with ESMTPSA id dv13-20020a0560000d8d00b0033e25c39ac3sm12463085wrb.80.2024.03.26.08.46.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 26 Mar 2024 08:46:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1711467971; x=1712072771; 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=pTnsklKw4fWTCEXstwwApylL5b79xPCluS5bdtq/AP4=; b=K9kypSWjrfL9N49/W0NFOIIlz2Dnk9rtYgHDD6A1UPo93CPorPUdqVmjm6kgb6pr2O ZuDtGSzklFVjwXlOvepNxv0tv7EHRW9ndWLYhbvZBKNEJKw3G3sqh/NjSeLkNEqY3810 lC/FZkOjdhaCgmmaGXaR0yLvPtpXg37ndUompjvycbESn9AEB3SfLm3FEeUVU8i9a1UC FL/if81txP+DD12rEucTkPTogqMX0JCVVr4lUnZc4f+qhgv9kWP0UtxgbS7YcTUioGqI 8aHdJtGGmg9YCTjK7Udiyf5IkzFCclroIJUHFaunEgDmUZuQS2O0Gx9apk5FQYDC5pU6 tDkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711467971; x=1712072771; 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=pTnsklKw4fWTCEXstwwApylL5b79xPCluS5bdtq/AP4=; b=QOn0wjYMRy8wymQWLFp1CHha2K0NGFyxXjt7Q16nOtY3Zj3+2wkyZZJ9a4kvKPfrNr I8FVqn9c5vtj50Sm68z+j8kGg6+IUXsLl0W/+Ur5Y2V6g3RSIqA7B8u7VTtgpgAtN7F3 WsjxbF7VzhAq+sc8u1WDQgD4/au34yYl0B97GyBmO1O+0NS/RqseJoV9uiF6+mXKrAp6 vxQBBXbhervPKgzMTJGBMeA2e4KpKzKISAoHC5XR7mpB/DoP1v28dfCDrLe8TtWpZ3RP pOPMuEss3gp8UAsxuFW91sI39TEpDW6Yys7qpg3+GvkHn4vTJ27qPZbRMLtLxiFLQYtQ ONww== X-Gm-Message-State: AOJu0YyIENf6BsRhQfUCrMm+0cxYWKCFMcUJI8r6+Vv7Ky04AxX+G6y2 m5PtbZNtLlIrEiclrTP2T7FHRQKziMC/Y6blWj85QY7RFcotFEuaSKj0g6cTMlehkXBGUtdNDGp r X-Google-Smtp-Source: AGHT+IFRg138015mLkS4XG4Sdyh7YagfM5S5mQJ97xUcjF73GKx/sVaycVtwbwmi4p09E0ToYZh4Dg== X-Received: by 2002:a5d:5b88:0:b0:33e:c0a9:79c with SMTP id df8-20020a5d5b88000000b0033ec0a9079cmr24223wrb.23.1711467971342; Tue, 26 Mar 2024 08:46:11 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Akihiko Odaki , Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PULL 11/13] ui/cocoa: Fix aspect ratio Date: Tue, 26 Mar 2024 16:45:02 +0100 Message-ID: <20240326154505.8300-12-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240326154505.8300-1-philmd@linaro.org> References: <20240326154505.8300-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::430; envelope-from=philmd@linaro.org; helo=mail-wr1-x430.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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 @linaro.org) X-ZM-MESSAGEID: 1711468131729100001 From: Akihiko Odaki [NSWindow setContentAspectRatio:] does not trigger window resize itself, so the wrong aspect ratio will persist if nothing resizes the window. Call [NSWindow setContentSize:] in such a case. Fixes: 91aa508d0274 ("ui/cocoa: Let the platform toggle fullscreen") Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell Message-ID: <20240323-fixes-v2-1-18651a2b0394@daynix.com> Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- ui/cocoa.m | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 810751cf26..17e125d66d 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -519,6 +519,43 @@ - (void) drawRect:(NSRect) rect } } =20 +- (NSSize)fixAspectRatio:(NSSize)max +{ + NSSize scaled; + NSSize fixed; + + scaled.width =3D screen.width * max.height; + scaled.height =3D screen.height * max.width; + + /* + * Here screen is our guest's output size, and max is the size of the + * largest possible area of the screen we can display on. + * We want to scale up (screen.width x screen.height) by either: + * 1) max.height / screen.height + * 2) max.width / screen.width + * With the first scale factor the scale will result in an output heig= ht of + * max.height (i.e. we will fill the whole height of the available scr= een + * space and have black bars left and right) and with the second scale + * factor the scaling will result in an output width of max.width (i.e= . we + * fill the whole width of the available screen space and have black b= ars + * top and bottom). We need to pick whichever keeps the whole of the g= uest + * output on the screen, which is to say the smaller of the two scale + * factors. + * To avoid doing more division than strictly necessary, instead of di= rectly + * comparing scale factors 1 and 2 we instead calculate and compare th= ose + * two scale factors multiplied by (screen.height * screen.width). + */ + if (scaled.width < scaled.height) { + fixed.width =3D scaled.width / screen.height; + fixed.height =3D max.height; + } else { + fixed.width =3D max.width; + fixed.height =3D scaled.height / screen.width; + } + + return fixed; +} + - (NSSize) screenSafeAreaSize { NSSize size =3D [[[self window] screen] frame].size; @@ -536,8 +573,10 @@ - (void) resizeWindow [[self window] setContentSize:NSMakeSize(screen.width, screen.heig= ht)]; [[self window] center]; } else if ([[self window] styleMask] & NSWindowStyleMaskFullScreen) { - [[self window] setContentSize:[self screenSafeAreaSize]]; + [[self window] setContentSize:[self fixAspectRatio:[self screenSaf= eAreaSize]]]; [[self window] center]; + } else { + [[self window] setContentSize:[self fixAspectRatio:[self frame].si= ze]]; } } =20 --=20 2.41.0