From patchwork Sat Mar 23 06:20:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13600533 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 lists.gnu.org (lists.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 C4FF1C6FD1F for ; Sat, 23 Mar 2024 06:21:33 +0000 (UTC) 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) 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) 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) 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 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-Dau?= =?utf-8?q?d=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: 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org [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 } } +- (NSSize)fixAspectRatio:(NSSize)max +{ + NSSize scaled; + NSSize fixed; + + scaled.width = screen.width * max.height; + scaled.height = 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 height of + * max.height (i.e. we will fill the whole height of the available screen + * 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 bars + * top and bottom). We need to pick whichever keeps the whole of the guest + * 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 directly + * comparing scale factors 1 and 2 we instead calculate and compare those + * two scale factors multiplied by (screen.height * screen.width). + */ + if (scaled.width < scaled.height) { + fixed.width = scaled.width / screen.height; + fixed.height = max.height; + } else { + fixed.width = max.width; + fixed.height = scaled.height / screen.width; + } + + return fixed; +} + - (NSSize) screenSafeAreaSize { NSSize size = [[[self window] screen] frame].size; @@ -525,8 +562,10 @@ - (void) resizeWindow [[self window] setContentSize:NSMakeSize(screen.width, screen.height)]; [[self window] center]; } else if ([[self window] styleMask] & NSWindowStyleMaskFullScreen) { - [[self window] setContentSize:[self screenSafeAreaSize]]; + [[self window] setContentSize:[self fixAspectRatio:[self screenSafeAreaSize]]]; [[self window] center]; + } else { + [[self window] setContentSize:[self fixAspectRatio:[self frame].size]]; } } From patchwork Sat Mar 23 06:20:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13600532 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 lists.gnu.org (lists.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 C2BC4C54E67 for ; Sat, 23 Mar 2024 06:21:33 +0000 (UTC) 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) 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) 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) 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 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-Dau?= =?utf-8?q?d=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: 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 [[cocoaView window] setStyleMask:styleMask]; [sender setState:styleMask & NSWindowStyleMaskResizable ? NSControlStateValueOn : NSControlStateValueOff]; + [cocoaView resizeWindow]; } - (void)toggleZoomInterpolation:(id) sender From patchwork Sat Mar 23 06:20:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13600534 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 lists.gnu.org (lists.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 8CF4EC54E67 for ; Sat, 23 Mar 2024 06:21:45 +0000 (UTC) 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) 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) 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) 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 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-Dau?= =?utf-8?q?d=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: 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 = [super initWithFrame:frameRect]; if (self) { + NSTrackingAreaOptions options = NSTrackingActiveInKeyWindow | + NSTrackingMouseEnteredAndExited | + NSTrackingMouseMoved | + NSTrackingInVisibleRect; + + NSTrackingArea *trackingArea = + [[NSTrackingArea alloc] initWithRect:CGRectZero + options:options + owner:self + userInfo:nil]; + + [self addTrackingArea:trackingArea]; + [trackingArea release]; screen.width = frameRect.size.width; screen.height = frameRect.size.height; kbd = qkbd_state_init(dcl.con); @@ -392,41 +404,9 @@ - (BOOL) isOpaque return YES; } -- (void) removeTrackingRect -{ - if (trackingArea) { - [self removeTrackingArea:trackingArea]; - [trackingArea release]; - trackingArea = nil; - } -} - -- (void) frameUpdated -{ - [self removeTrackingRect]; - - if ([self window]) { - NSTrackingAreaOptions options = NSTrackingActiveInKeyWindow | - NSTrackingMouseEnteredAndExited | - NSTrackingMouseMoved; - trackingArea = [[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]; } - (void) hideCursor @@ -1302,7 +1282,7 @@ - (void)windowDidExitFullScreen:(NSNotification *)notification - (void)windowDidResize:(NSNotification *)notification { [cocoaView updateBounds]; - [cocoaView frameUpdated]; + [cocoaView updateUIInfo]; } /* Called when the user clicks on a window's close button */