From: Akihiko Odaki <akihiko.odaki@daynix.com>
To: "Peter Maydell" <peter.maydell@linaro.org>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: qemu-devel@nongnu.org, Akihiko Odaki <akihiko.odaki@daynix.com>
Subject: [PATCH 3/3] ui/cocoa: Use NSTrackingInVisibleRect
Date: Mon, 18 Mar 2024 16:53:02 +0900 [thread overview]
Message-ID: <20240318-fixes-v1-3-34f1a849b0d9@daynix.com> (raw)
In-Reply-To: <20240318-fixes-v1-0-34f1a849b0d9@daynix.com>
I observed [NSTrackingArea rect] becomes de-synchronized with the view
frame with some unknown condition. 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 <akihiko.odaki@daynix.com>
---
ui/cocoa.m | 48 ++++++++++++++----------------------------------
1 file changed, 14 insertions(+), 34 deletions(-)
diff --git a/ui/cocoa.m b/ui/cocoa.m
index 1324be6d32fe..1e2b7d931905 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
@@ -1284,7 +1264,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 */
--
2.44.0
next prev parent reply other threads:[~2024-03-18 7:53 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-18 7:52 [PATCH 0/3] Fixes for "ui/cocoa: Let the platform toggle fullscreen" Akihiko Odaki
2024-03-18 7:53 ` [PATCH 1/3] ui/cocoa: Fix aspect ratio Akihiko Odaki
2024-03-22 12:22 ` Peter Maydell
2024-03-22 12:25 ` Akihiko Odaki
2024-03-22 12:55 ` Peter Maydell
2024-03-23 6:29 ` Akihiko Odaki
2024-03-18 7:53 ` [PATCH 2/3] ui/cocoa: Resize window after toggling zoom-to-fit Akihiko Odaki
2024-03-22 12:23 ` Peter Maydell
2024-03-18 7:53 ` Akihiko Odaki [this message]
2024-03-22 12:28 ` [PATCH 3/3] ui/cocoa: Use NSTrackingInVisibleRect Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240318-fixes-v1-3-34f1a849b0d9@daynix.com \
--to=akihiko.odaki@daynix.com \
--cc=kraxel@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).