From nobody Sun May 12 18:37:03 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1711174896; cv=none; d=zohomail.com; s=zohoarc; b=G6EDafuSTqOrQZxj6KZeAUgwaAplsxMdl5FxR2GEljc3+DlN2XkHEvEaU3nCNJsbDCvN56zqdj1khAaHgQHMAer+QvMuTfcLoitvZ0Jw5vUshXnTR3kUXxdkn5/PwrDejiqx2D3wL75a0x+n3QQ+tHAavapoZW9NZzivqdu0P7Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1711174896; 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=EbyKf2p5kvOfhKqh3XRD8emzriRkVdu9uRtFgfGqp4o=; b=Jc0DxkRBzUkqpdrfeo4fGbdTiqOscq9ep+G+XGEuyUV9ZAABb2OjslGaRXdjtNyarn2ZpY/K/tfrJWXGiBDAdpJeL1p8roQw2EzrqslbcdqqKUFQ5V23iuksSk2kO9vx+kllszw9p/rRvGO6Q6YJHlzK/+U91VqfK4bR89x3T4U= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1711174896350179.4193508476393; Fri, 22 Mar 2024 23:21:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rnuk3-0005w6-9y; Sat, 23 Mar 2024 02:20:31 -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 1rnuju-0005tW-D7 for qemu-devel@nongnu.org; Sat, 23 Mar 2024 02:20:24 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rnujr-0007dA-2k for qemu-devel@nongnu.org; Sat, 23 Mar 2024 02:20:22 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6e6f4ad4c57so2040470b3a.2 for ; Fri, 22 Mar 2024 23:20:16 -0700 (PDT) Received: from localhost ([157.82.200.213]) by smtp.gmail.com with UTF8SMTPSA id u4-20020a170902e5c400b001def0324a64sm803039plf.135.2024.03.22.23.20.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 22 Mar 2024 23:20:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1711174815; x=1711779615; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=EbyKf2p5kvOfhKqh3XRD8emzriRkVdu9uRtFgfGqp4o=; b=2MUcVtY4kyCbOdKUl+G8bdARjBMBRa1++0cXaZ2fwu8REtp4RHdi7WvDXmzcxRWoxz lNGsBGCJ2ZgHAE1PA5OmDevZGePYK3/wYXz4a7Su8HHEtfTmyDVKVzd5wiyn3O79ICdv BHxAVQlsnL3gesl1MQll4bUlDUvcrw+jyqxkDTR3wiEyqSJ3gbOoJ5Ywm9d8Ol4UBvNe CoCJFvslEujWYkW5nAJEnagpjuDhJ3YTGnbO7vxd+6W/foZf8bSxSuJS5eTsAb3Y5vIa MFY5Ddw1pd9e1m9b5VfMKGBbvor9NxwkdXSRBHSmvMo+wIMcnRBYHYUt4I6KfQQ5L1p2 RrPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711174815; x=1711779615; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EbyKf2p5kvOfhKqh3XRD8emzriRkVdu9uRtFgfGqp4o=; b=A01VoZYBRZr6nxGvjCH5lU8hgeolywsceOg4vvYuI1hnJK/v07t+yO0P3RRyvXDfkK SunTAKK420REmnBewKtCG8+50lj0kQqgmi7TmO60hl7DjwwdviuOGiygUV+EJCZuWKKb N5EOBhYYNZzU6B+j2GVcYM6gxX5r/K4bDxd2SjajW7P/QBSu1Tn31UFtMKOf+WYlfctH OhFxbkK4Q5n4R5mEvfaHxVzI6yjCxD8Wmz7A5PUw/pH0FMQC9LyLmrdcuqRdwQrG7pXT J+Xtx2OAdfilZ2Q4obupWJXXtrWKvR16Nh+m22/Hd448Ggw6pDSFJs0isSaWGmE6musm 4TVQ== X-Gm-Message-State: AOJu0YwavZbn2N8GugJYRF966TQyMHX4cD2kV9Ge5NA4EC+klhd7HxR+ WyPKt3eJoxxC/VOPypuWgqfWFZDwYr6lIgFU9N60NgsS+jHHkdU7IL/TQUNQj9lglG1QBCvZsa1 3//g= X-Google-Smtp-Source: AGHT+IFMn5UfauL0MR85dxcof+9So+t3TjwyNRBX1TCXGsS35UG/OFUVUZpDDS8Q536XzblP2diIcg== X-Received: by 2002:a05:6a20:2888:b0:1a3:4469:5967 with SMTP id q8-20020a056a20288800b001a344695967mr1480498pzf.57.1711174815058; Fri, 22 Mar 2024 23:20:15 -0700 (PDT) From: Akihiko Odaki Date: Sat, 23 Mar 2024 15:20:01 +0900 Subject: [PATCH v2 1/3] ui/cocoa: Fix aspect ratio MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240323-fixes-v2-1-18651a2b0394@daynix.com> References: <20240323-fixes-v2-0-18651a2b0394@daynix.com> In-Reply-To: <20240323-fixes-v2-0-18651a2b0394@daynix.com> To: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Gerd Hoffmann , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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: none client-ip=2607:f8b0:4864:20::42c; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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 @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1711174897409100005 [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 --- ui/cocoa.m | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index fa879d7dcd4b..834ebf5f6175 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -508,6 +508,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; @@ -525,8 +562,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.44.0 From nobody Sun May 12 18:37:03 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1711174894; cv=none; d=zohomail.com; s=zohoarc; b=nhT39JO73ccmH4xb+buE7dIlYooQck5M/hWNAxxXZKM9miPI2pVcl1BOyLVpCkOmzszGYVMxqDweYSB35KXvhwFQgjMzzyjcPb3vgFU5aTIJZrqbw/SFN6w0yBk48sMVYaSbmMHWpCrOe69ZjpISL2AOiGlasJzISO+L+kpMNeI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1711174894; 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=1/JZr2uStAFeg9hQSEj1pl6Z0un8Jhj/9vQLsQrKvwM=; b=McvQKaUNJ23c/RD604G3LjSflwtEAstsELr8Z8OLtNHXXpxm1WkVO5jjZfC8msGIvhEScb+FnvUvkUdb8YOmhS+cESGe0NxP8jzNv/GMRlQ80UaeDG7RkFpqcTVmoQdfIMAjyfc7UAjRy50jCPUsCOuW/qCl0dWBmZd56WRBQgE= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 171117489409873.03462737842494; Fri, 22 Mar 2024 23:21:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rnuk2-0005vh-Ly; Sat, 23 Mar 2024 02:20:30 -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 1rnujv-0005tX-Ip for qemu-devel@nongnu.org; Sat, 23 Mar 2024 02:20:24 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rnujs-0007dT-M7 for qemu-devel@nongnu.org; Sat, 23 Mar 2024 02:20:23 -0400 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-5dca1efad59so1773921a12.2 for ; Fri, 22 Mar 2024 23:20:19 -0700 (PDT) Received: from localhost ([157.82.200.213]) by smtp.gmail.com with UTF8SMTPSA id b4-20020a170902d50400b001defa82b994sm801266plg.123.2024.03.22.23.20.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 22 Mar 2024 23:20:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1711174818; x=1711779618; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=1/JZr2uStAFeg9hQSEj1pl6Z0un8Jhj/9vQLsQrKvwM=; b=XBZromdGEoViTHSN4DX7H164NvcrG6j8ntHu9F0LHU13k1LUGenxMMgaoGbw6UA6Y/ n7B7fCw7RJJNAILGjRIOX0Xzx5ZQRWqvrfJhVE6tsHX9GGh5A5ekVkbnjSfxSnSfgK5p PwKPRPhIW0S00hiIBG3ax1gyIov2GBod+X6hlOYb2viOxO7avD+wYfo80ErVXhMK8BiX fyygLP64F8gTmM7KyR6Ok1KjD4ygIHvrOmyn4OzeDzsnyDi6+kHh1GYUzPnABxyOu/oa A0Vrg+ReUup2EqKFEj/w2DkkrAwRVSNQepVRNvhmRnV8RJR0EY8D+iIu1d2hgHGFHnpA IgBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711174818; x=1711779618; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1/JZr2uStAFeg9hQSEj1pl6Z0un8Jhj/9vQLsQrKvwM=; b=HUttY2UyLTfOfI6OeNXKy7jLHAX85cVSolu/TrXjCOFDAixhGjB0++NmRKna5m8XNI /h+excRkmMGWpSUHSeUX9QCWMGdq1YWbqNfpiC+OYRkwZ3roW6fCyp8GN1VTOCU3S5w4 mwi3CBU5EgbyvEV7I0B4XQrCx9mxOWiZ0L5ia6Cl0wok6922utnQDNiyupKhJm0oqNyu 7sj0jlufkGWbce3Vr6QvGqlS1KrXzJDfIjA7SV84BKyY98gC065LAuGyiMX0ReDxYzKa qUIm1ORGScTHjVbDbsl+BKAVJkEg4bIKzuiWGYiniYjcUbSazbRK/lSgY9sLvW8CNFk+ +0XA== X-Gm-Message-State: AOJu0YypfaNKYMJYIyItGu7IR7zjG75W+rb3qsAqXiByZeDuA6LoLARx kFTWgbWzL+5dT6QjcFE/OhOnJh11VuNqWzNbUecM5xT2+kU9U+48Jy6tFbcfPZI= X-Google-Smtp-Source: AGHT+IFomI9bfec1sdiqmmlOhlLs1KuEUWBZQoB8BjmsuA4oneF6NWBe3W4j3cwOj10fDF1H9zDY4w== X-Received: by 2002:a17:903:1111:b0:1dd:b3ef:4528 with SMTP id n17-20020a170903111100b001ddb3ef4528mr2060005plh.52.1711174818259; Fri, 22 Mar 2024 23:20:18 -0700 (PDT) From: Akihiko Odaki Date: Sat, 23 Mar 2024 15:20:02 +0900 Subject: [PATCH v2 2/3] ui/cocoa: Resize window after toggling zoom-to-fit MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240323-fixes-v2-2-18651a2b0394@daynix.com> References: <20240323-fixes-v2-0-18651a2b0394@daynix.com> In-Reply-To: <20240323-fixes-v2-0-18651a2b0394@daynix.com> To: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Gerd Hoffmann , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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: none client-ip=2607:f8b0:4864:20::536; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x536.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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 @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1711174895934100001 Resize the window so that the content will fit without zooming. Fixes: 91aa508d0274 ("ui/cocoa: Let the platform toggle fullscreen") Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- ui/cocoa.m | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/cocoa.m b/ui/cocoa.m index 834ebf5f6175..3a1b899ba768 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -1396,6 +1396,7 @@ - (void)zoomToFit:(id) sender =20 [[cocoaView window] setStyleMask:styleMask]; [sender setState:styleMask & NSWindowStyleMaskResizable ? NSControlSta= teValueOn : NSControlStateValueOff]; + [cocoaView resizeWindow]; } =20 - (void)toggleZoomInterpolation:(id) sender --=20 2.44.0 From nobody Sun May 12 18:37:03 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1711174905; cv=none; d=zohomail.com; s=zohoarc; b=N0WJ1Crz0u8iUy4dPm+OloiPxyZwN8F+R15IrYR3/MIy1FY5pfmP1zzyBrIy2eubSd0CB3rpufUV1QIMkh8WYsXBfiajJnd+D0qK1g14nRNlf8VRvI/dWBUzsRTzM29WWk/jdZMt1vY8xHkdg/yNIMMihzulbUJakY5D9bbq0g8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1711174905; 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=9a+wseDHyW/HqtA3ozakI/wgiKhPEsw9cRXVXB7EC8c=; b=k3Ul1/0gu+6M6yUTNHsnuC7DPiQIC6jXTmMQHmc2WeosXi0u8PCRRdIZKsRPm1R5P2D6YpjypLEqgiiN8gBmvDWI7mcsqp795GiQI0Y5VNP/Ev4jD1DtYAN9gbeQ2oxspvkum47NhgVxcrKv2a/ui3/oS3jBqWjwj5YB3Vw6O80= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1711174905505748.6620625134057; Fri, 22 Mar 2024 23:21:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rnuk6-0005x1-0J; Sat, 23 Mar 2024 02:20:34 -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 1rnujy-0005tY-GR for qemu-devel@nongnu.org; Sat, 23 Mar 2024 02:20:26 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rnujv-0007f2-BC for qemu-devel@nongnu.org; Sat, 23 Mar 2024 02:20:24 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6e8f51d0bf0so2223240b3a.3 for ; Fri, 22 Mar 2024 23:20:22 -0700 (PDT) Received: from localhost ([157.82.200.213]) by smtp.gmail.com with UTF8SMTPSA id az2-20020a170902a58200b001e01176682dsm807582plb.27.2024.03.22.23.20.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 22 Mar 2024 23:20:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1711174821; x=1711779621; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=9a+wseDHyW/HqtA3ozakI/wgiKhPEsw9cRXVXB7EC8c=; b=1LwpUwnwoIIcsI7NmbnPsNK9N1fNMulsZevfFPKbiTUuaLoYX6jWXu8FgA6Y1Buc6q zauUDBKqXLC9fwDJmV5WuQXF9s57ipHCjQCqrQ4SEGlH6F0sq62E2rouBX3mDTM171el f8P147q7ensJCTJ9FJ1xHpc97rLUyXrPoiDkqGcMyBnGSRM+emqJN88+o5rcEP8XPHcW BxLwwUtzBbhylPO41J7AmslyhfzcLnAs9FWL87z7PMGs3OjZlnpvOU/70Prti7PYww1u 7XtyxPPa5WKxkw2aWlO7uamGldo3ry+P6zFmR2s86msmPPM29qrv1bmpSSr6l3wJDBqA YzDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711174821; x=1711779621; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9a+wseDHyW/HqtA3ozakI/wgiKhPEsw9cRXVXB7EC8c=; b=JYc3bBPicl1AN1HVPAAltMnVdNLvTFPnh/OlOMP2MUEU8h8uSB8jnEYFb+1YRYnBi6 aKzIseWeGc7oRjcu2s99TbsEDrROgzOQzqH7CgNz/icPMItzX43tKHoQOyVbcur3hQaS 65jT/80+h8Aj+t315uHomEHW+iZtIUhHTqnGUAq7qeMon116QCnS+YrwPPJ8XWEPlX6b xhR4WNQSD2IIvCOpJL8Se/3LTPiDNmv1NDqr50JtCY9NNfq4+8NNu5HUT+BoO6bRmJu2 aIxk7CmdZeoMDqFj1zI2hsgFNNoTxchqht+N6mtAVNI/b9dIfNiKJrqdyohB9KNT3BrS pZUw== X-Gm-Message-State: AOJu0Yzrx/phGgzawTxoVgihmjj+/QWqGzxyOzTBAlsp9dhB2EajFkbd aEwTYj5K3WrB30Du7tss7MwLQNSQDKDhWbCgVhoZRpYf7rIH1Xh/s2yjD0P1c5U= X-Google-Smtp-Source: AGHT+IGAPNWW1fZoEYmZoZHzyC/I+CeMezcELxhai3dMHJyt9lVldEDALMf1QIz7C/Dr/ZDm/KS1Ww== X-Received: by 2002:a05:6a21:7884:b0:1a3:4fcd:86e3 with SMTP id bf4-20020a056a21788400b001a34fcd86e3mr1841681pzc.42.1711174821404; Fri, 22 Mar 2024 23:20:21 -0700 (PDT) From: Akihiko Odaki Date: Sat, 23 Mar 2024 15:20:03 +0900 Subject: [PATCH v2 3/3] ui/cocoa: Use NSTrackingInVisibleRect MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240323-fixes-v2-3-18651a2b0394@daynix.com> References: <20240323-fixes-v2-0-18651a2b0394@daynix.com> In-Reply-To: <20240323-fixes-v2-0-18651a2b0394@daynix.com> To: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Gerd Hoffmann , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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: none client-ip=2607:f8b0:4864:20::42c; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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 @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1711174907439100001 I observed [NSTrackingArea rect] becomes de-synchronized with the view frame with some unknown condition, and fails to track mouse movement on some area of the view. Specify NSTrackingInVisibleRect option to let Cocoa automatically update NSTrackingArea, which also saves code for synchronization. Fixes: 91aa508d0274 ("ui/cocoa: Let the platform toggle fullscreen") Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- ui/cocoa.m | 48 ++++++++++++++---------------------------------- 1 file changed, 14 insertions(+), 34 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 3a1b899ba768..fb60debb9a8e 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -306,7 +306,6 @@ static void handleAnyDeviceErrors(Error * err) */ @interface QemuCocoaView : NSView { - NSTrackingArea *trackingArea; QEMUScreen screen; pixman_image_t *pixman_image; QKbdState *kbd; @@ -359,6 +358,19 @@ - (id)initWithFrame:(NSRect)frameRect self =3D [super initWithFrame:frameRect]; if (self) { =20 + NSTrackingAreaOptions options =3D NSTrackingActiveInKeyWindow | + NSTrackingMouseEnteredAndExited | + NSTrackingMouseMoved | + NSTrackingInVisibleRect; + + NSTrackingArea *trackingArea =3D + [[NSTrackingArea alloc] initWithRect:CGRectZero + options:options + owner:self + userInfo:nil]; + + [self addTrackingArea:trackingArea]; + [trackingArea release]; screen.width =3D frameRect.size.width; screen.height =3D frameRect.size.height; kbd =3D qkbd_state_init(dcl.con); @@ -392,41 +404,9 @@ - (BOOL) isOpaque return YES; } =20 -- (void) removeTrackingRect -{ - if (trackingArea) { - [self removeTrackingArea:trackingArea]; - [trackingArea release]; - trackingArea =3D nil; - } -} - -- (void) frameUpdated -{ - [self removeTrackingRect]; - - if ([self window]) { - NSTrackingAreaOptions options =3D NSTrackingActiveInKeyWindow | - NSTrackingMouseEnteredAndExited | - NSTrackingMouseMoved; - trackingArea =3D [[NSTrackingArea alloc] initWithRect:[self frame] - options:options - owner:self - userInfo:nil]; - [self addTrackingArea:trackingArea]; - [self updateUIInfo]; - } -} - - (void) viewDidMoveToWindow { [self resizeWindow]; - [self frameUpdated]; -} - -- (void) viewWillMoveToWindow:(NSWindow *)newWindow -{ - [self removeTrackingRect]; } =20 - (void) hideCursor @@ -1302,7 +1282,7 @@ - (void)windowDidExitFullScreen:(NSNotification *)not= ification - (void)windowDidResize:(NSNotification *)notification { [cocoaView updateBounds]; - [cocoaView frameUpdated]; + [cocoaView updateUIInfo]; } =20 /* Called when the user clicks on a window's close button */ --=20 2.44.0