[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 13/13] ui/cocoa: Use NSTrackingInVisibleRect
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 13/13] ui/cocoa: Use NSTrackingInVisibleRect |
Date: |
Tue, 26 Mar 2024 16:45:04 +0100 |
From: Akihiko Odaki <akihiko.odaki@daynix.com>
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 <akihiko.odaki@daynix.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-ID: <20240323-fixes-v2-3-18651a2b0394@daynix.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
ui/cocoa.m | 48 ++++++++++++++----------------------------------
1 file changed, 14 insertions(+), 34 deletions(-)
diff --git a/ui/cocoa.m b/ui/cocoa.m
index 3efa8ac1a9..25e0db9dd0 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -307,7 +307,6 @@ static void handleAnyDeviceErrors(Error * err)
*/
@interface QemuCocoaView : NSView
{
- NSTrackingArea *trackingArea;
QEMUScreen screen;
pixman_image_t *pixman_image;
BOOL isMouseGrabbed;
@@ -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;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_14_0
@@ -389,41 +401,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) selectConsoleLocked:(unsigned int)index
@@ -1314,7 +1294,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.41.0
- [PULL 03/13] monitor/hmp-cmds-target: Append a space in error message in gpa2hva(), (continued)
- [PULL 03/13] monitor/hmp-cmds-target: Append a space in error message in gpa2hva(), Philippe Mathieu-Daudé, 2024/03/26
- [PULL 04/13] target/tricore/helper: Use correct string format in cpu_tlb_fill(), Philippe Mathieu-Daudé, 2024/03/26
- [PULL 05/13] hw/clock: Let clock_set_mul_div() return a boolean value, Philippe Mathieu-Daudé, 2024/03/26
- [PULL 06/13] hw/misc/stm32l4x5_rcc: Inline clock_update() in clock_mux_update(), Philippe Mathieu-Daudé, 2024/03/26
- [PULL 07/13] hw/misc/stm32l4x5_rcc: Propagate period when enabling a clock, Philippe Mathieu-Daudé, 2024/03/26
- [PULL 09/13] contrib/plugins/execlog: Fix compiler warning, Philippe Mathieu-Daudé, 2024/03/26
- [PULL 08/13] docs/system/ppc/amigang.rst: Fix formatting, Philippe Mathieu-Daudé, 2024/03/26
- [PULL 10/13] hw/smbios: add stub for smbios_get_table_legacy(), Philippe Mathieu-Daudé, 2024/03/26
- [PULL 11/13] ui/cocoa: Fix aspect ratio, Philippe Mathieu-Daudé, 2024/03/26
- [PULL 12/13] ui/cocoa: Resize window after toggling zoom-to-fit, Philippe Mathieu-Daudé, 2024/03/26
- [PULL 13/13] ui/cocoa: Use NSTrackingInVisibleRect,
Philippe Mathieu-Daudé <=
- Re: [PULL 00/13] Misc HW patches for 2024-03-26, Peter Maydell, 2024/03/26