On Mojave, absolute input device, i.e. tablet, had trouble re-grabbing
the cursor in re-entry into the virtual screen area. In some cases,
the `window` property of NSEvent object is nil, after exit of cursor,
meaning that the `-locationInWindow` method would return value in screen
coordinates. Current implementation used raw locations from NSEvent
without considering whether the value was for the window coordinates or
the macOS screen coordinates, nor was the zooming factor for Zoom-to-Fit
included for fullscreen mode.
In fullscreen mode, the fullscreen cocoa window might not be the key
window, therefore location of event in virtual coordinates should suffice
for the condition of grabbing.
This patch fixed boundary check methods for cursor in normal and fullscreen
with/without Zoom-to-Fit on macOS Mojave.
Signed-off-by: Chen Zhang <tgfbeta@me.com>
---
ui/cocoa.m | 39 +++++++++++++++++++++++++++++++++++++--
1 file changed, 37 insertions(+), 2 deletions(-)
diff --git a/ui/cocoa.m b/ui/cocoa.m
index 420b2411c1..21c20e8dd9 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -405,6 +405,37 @@ QemuCocoaView *cocoaView;
return (p.x > -1 && p.x < screen.width && p.y > -1 && p.y < screen.height);
}
+/* Get location of event and convert to virtual screen coordinate */
+- (CGPoint) screenLocationOfEvent:(NSEvent *)ev
+{
+ NSWindow *eventWindow = [ev window];
+ if (!eventWindow) {
+ if (!isFullscreen) {
+ return [[self window] convertPointFromScreen:[ev locationInWindow]];
+ } else {
+ CGPoint loc = [self convertPoint:[[self window] convertPointFromScreen:[ev locationInWindow]] fromView:nil];
+ if (stretch_video) {
+ loc.x /= cdx;
+ loc.y /= cdy;
+ }
+ return loc;
+ }
+ } else if ([[self window] isEqual:eventWindow]) {
+ if (!isFullscreen) {
+ return [ev locationInWindow];
+ } else {
+ CGPoint loc = [self convertPoint:[ev locationInWindow] fromView:nil];
+ if (stretch_video) {
+ loc.x /= cdx;
+ loc.y /= cdy;
+ }
+ return loc;
+ }
+ } else {
+ return [[self window] convertPointFromScreen:[eventWindow convertPointToScreen:[ev locationInWindow]]];
+ }
+}
+
- (void) hideCursor
{
if (!cursor_hide) {
@@ -704,7 +735,8 @@ QemuCocoaView *cocoaView;
int keycode = 0;
bool mouse_event = false;
static bool switched_to_fullscreen = false;
- NSPoint p = [event locationInWindow];
+ // Location of event in virtual screen coordinates
+ NSPoint p = [self screenLocationOfEvent:event];
switch ([event type]) {
case NSEventTypeFlagsChanged:
@@ -815,7 +847,10 @@ QemuCocoaView *cocoaView;
break;
case NSEventTypeMouseMoved:
if (isAbsoluteEnabled) {
- if (![self screenContainsPoint:p] || ![[self window] isKeyWindow]) {
+ // Cursor re-entered into a window may generate events in screen coordinates
+ // and `nil` window property, and in full screen mode, current window may not be
+ // key window, where event location alone should suffice.
+ if (![self screenContainsPoint:p] || !([[self window] isKeyWindow] || isFullscreen)) {
if (isMouseGrabbed) {
[self ungrabMouse];
}
--
2.19.2
Patchew URL: https://patchew.org/QEMU/2D646E18-7F28-4F06-9F3D-D5F8A1408FAC@me.com/ Hi, This series seems to have some coding style problems. See output below for more information: Message-id: 2D646E18-7F28-4F06-9F3D-D5F8A1408FAC@me.com Type: series Subject: [Qemu-devel] [PATCH v2] ui/cocoa: Fix absolute input device grabbing issues on Mojave === TEST SCRIPT BEGIN === #!/bin/bash git rev-parse base > /dev/null || exit 0 git config --local diff.renamelimit 0 git config --local diff.renames True git config --local diff.algorithm histogram ./scripts/checkpatch.pl --mailback base.. === TEST SCRIPT END === Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 From https://github.com/patchew-project/qemu * [new tag] patchew/2D646E18-7F28-4F06-9F3D-D5F8A1408FAC@me.com -> patchew/2D646E18-7F28-4F06-9F3D-D5F8A1408FAC@me.com Switched to a new branch 'test' 0a0ec087ff ui/cocoa: Fix absolute input device grabbing issues on Mojave === OUTPUT BEGIN === ERROR: Author email address is mangled by the mailing list #2: Author: Chen Zhang via Qemu-devel <qemu-devel@nongnu.org> total: 1 errors, 0 warnings, 57 lines checked Commit 0a0ec087ffaa (ui/cocoa: Fix absolute input device grabbing issues on Mojave) has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS. === OUTPUT END === Test command exited with code: 1 The full log is available at http://patchew.org/logs/2D646E18-7F28-4F06-9F3D-D5F8A1408FAC@me.com/testing.checkpatch/?type=message. --- Email generated automatically by Patchew [https://patchew.org/]. Please send your feedback to patchew-devel@redhat.com
On Tue, 19 Mar 2019 at 03:51, Chen Zhang <tgfbeta@me.com> wrote: > > On Mojave, absolute input device, i.e. tablet, had trouble re-grabbing > the cursor in re-entry into the virtual screen area. In some cases, > the `window` property of NSEvent object is nil, after exit of cursor, > meaning that the `-locationInWindow` method would return value in screen > coordinates. Current implementation used raw locations from NSEvent > without considering whether the value was for the window coordinates or > the macOS screen coordinates, nor was the zooming factor for Zoom-to-Fit > included for fullscreen mode. > > In fullscreen mode, the fullscreen cocoa window might not be the key > window, therefore location of event in virtual coordinates should suffice > for the condition of grabbing. > > This patch fixed boundary check methods for cursor in normal and fullscreen > with/without Zoom-to-Fit on macOS Mojave. > > Signed-off-by: Chen Zhang <tgfbeta@me.com> > --- > ui/cocoa.m | 39 +++++++++++++++++++++++++++++++++++++-- > 1 file changed, 37 insertions(+), 2 deletions(-) > Hi; this doesn't compile for me, I'm afraid. I've appended the full compiler error log, but the problem seems to be that the convertPointFromScreen method of NSWindow doesn't exist. I'm not entirely sure why, since the API docs say that method was introduced in OSX 10.12 and I'm running 10.13.6, but at least at the moment our minimum OSX version is 10.10, so we need something to handle that anyway. (http://codeworkshop.net/objc-diff/sdkdiffs/macos/10.14/AppKit.html suggests that maybe the docs are wrong and this method was only added in 10.14; that would certainly fit the symptoms.) /Users/pm215/src/qemu/ui/cocoa.m:414:35: warning: instance method '-convertPointFromScreen:' not found (return type defaults to 'id') [-Wobjc-method-access] return [[self window] convertPointFromScreen:[ev locationInWindow]]; ^~~~~~~~~~~~~~~~~~~~~~ /System/Library/Frameworks/AppKit.framework/Headers/NSWindow.h:191:12: note: receiver is instance of class declared here @interface NSWindow : NSResponder <NSAnimatablePropertyContainer, NSUserInterfaceValidations, NSUserInterfaceItemIdenti... ^ /Users/pm215/src/qemu/ui/cocoa.m:414:20: error: returning 'id' from a function with incompatible result type 'CGPoint' (aka 'struct CGPoint') return [[self window] convertPointFromScreen:[ev locationInWindow]]; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /Users/pm215/src/qemu/ui/cocoa.m:416:61: warning: instance method '-convertPointFromScreen:' not found (return type defaults to 'id') [-Wobjc-method-access] CGPoint loc = [self convertPoint:[[self window] convertPointFromScreen:[ev locationInWindow]] fromView:nil]; ^~~~~~~~~~~~~~~~~~~~~~ /System/Library/Frameworks/AppKit.framework/Headers/NSWindow.h:191:12: note: receiver is instance of class declared here @interface NSWindow : NSResponder <NSAnimatablePropertyContainer, NSUserInterfaceValidations, NSUserInterfaceItemIdenti... ^ /Users/pm215/src/qemu/ui/cocoa.m:416:46: error: sending 'id' to parameter of incompatible type 'NSPoint' (aka 'struct CGPoint') CGPoint loc = [self convertPoint:[[self window] convertPointFromScreen:[ev locationInWindow]] fromView:nil]; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /System/Library/Frameworks/AppKit.framework/Headers/NSView.h:196:34: note: passing argument to parameter 'point' here - (NSPoint)convertPoint:(NSPoint)point fromView:(nullable NSView *)view; ^ /Users/pm215/src/qemu/ui/cocoa.m:435:67: warning: instance method '-convertPointToScreen:' not found (return type defaults to 'id') [-Wobjc-method-access] return [[self window] convertPointFromScreen:[eventWindow convertPointToScreen:[ev locationInWindow]]]; ^~~~~~~~~~~~~~~~~~~~ /System/Library/Frameworks/AppKit.framework/Headers/NSWindow.h:191:12: note: receiver is instance of class declared here @interface NSWindow : NSResponder <NSAnimatablePropertyContainer, NSUserInterfaceValidations, NSUserInterfaceItemIdenti... ^ /Users/pm215/src/qemu/ui/cocoa.m:435:31: warning: instance method '-convertPointFromScreen:' not found (return type defaults to 'id') [-Wobjc-method-access] return [[self window] convertPointFromScreen:[eventWindow convertPointToScreen:[ev locationInWindow]]]; ^~~~~~~~~~~~~~~~~~~~~~ /System/Library/Frameworks/AppKit.framework/Headers/NSWindow.h:191:12: note: receiver is instance of class declared here @interface NSWindow : NSResponder <NSAnimatablePropertyContainer, NSUserInterfaceValidations, NSUserInterfaceItemIdenti... ^ /Users/pm215/src/qemu/ui/cocoa.m:435:16: error: returning 'id' from a function with incompatible result type 'CGPoint' (aka 'struct CGPoint') return [[self window] convertPointFromScreen:[eventWindow convertPointToScreen:[ev locationInWindow]]]; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4 warnings and 3 errors generated. thanks -- PMM
> On Mar 27, 2019, at 12:15 AM, Peter Maydell <peter.maydell@linaro.org> wrote: > > On Tue, 19 Mar 2019 at 03:51, Chen Zhang <tgfbeta@me.com <mailto:tgfbeta@me.com>> wrote: >> >> On Mojave, absolute input device, i.e. tablet, had trouble re-grabbing >> the cursor in re-entry into the virtual screen area. In some cases, >> the `window` property of NSEvent object is nil, after exit of cursor, >> meaning that the `-locationInWindow` method would return value in screen >> coordinates. Current implementation used raw locations from NSEvent >> without considering whether the value was for the window coordinates or >> the macOS screen coordinates, nor was the zooming factor for Zoom-to-Fit >> included for fullscreen mode. >> >> In fullscreen mode, the fullscreen cocoa window might not be the key >> window, therefore location of event in virtual coordinates should suffice >> for the condition of grabbing. >> >> This patch fixed boundary check methods for cursor in normal and fullscreen >> with/without Zoom-to-Fit on macOS Mojave. >> >> Signed-off-by: Chen Zhang <tgfbeta@me.com> >> --- >> ui/cocoa.m | 39 +++++++++++++++++++++++++++++++++++++-- >> 1 file changed, 37 insertions(+), 2 deletions(-) >> > > Hi; this doesn't compile for me, I'm afraid. I've appended the full > compiler error log, but the problem seems to be that > the convertPointFromScreen method of NSWindow doesn't exist. > I'm not entirely sure why, since the API docs say that method > was introduced in OSX 10.12 and I'm running 10.13.6, but > at least at the moment our minimum OSX version is 10.10, > so we need something to handle that anyway. Hi, Just double-checked on a MacMini mid 2011 with macOS 10.13.6, Xcode 10.1. This NSWindow API did exist, and the patch could be built without error. Searching convertPointFromScreen in Xcode.app’s platform SDK showed that it was defined at line 440 in NSWindow.h of AppKit.framework. May I ask what build environment did you use (as printed by `xcode-select -p`)? > > (http://codeworkshop.net/objc-diff/sdkdiffs/macos/10.14/AppKit.html <http://codeworkshop.net/objc-diff/sdkdiffs/macos/10.14/AppKit.html> > suggests that maybe the docs are wrong and this method > was only added in 10.14; that would certainly fit the symptoms.) > > > /Users/pm215/src/qemu/ui/cocoa.m:414:35: warning: instance method > '-convertPointFromScreen:' not found > (return type defaults to 'id') [-Wobjc-method-access] > return [[self window] convertPointFromScreen:[ev locationInWindow]]; > ^~~~~~~~~~~~~~~~~~~~~~ > /System/Library/Frameworks/AppKit.framework/Headers/NSWindow.h:191:12: > note: receiver is instance of class declared here > @interface NSWindow : NSResponder <NSAnimatablePropertyContainer, > NSUserInterfaceValidations, NSUserInterfaceItemIdenti... > ^ > /Users/pm215/src/qemu/ui/cocoa.m:414:20: error: returning 'id' from a > function with incompatible result type 'CGPoint' > (aka 'struct CGPoint') > return [[self window] convertPointFromScreen:[ev locationInWindow]]; > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > /Users/pm215/src/qemu/ui/cocoa.m:416:61: warning: instance method > '-convertPointFromScreen:' not found > (return type defaults to 'id') [-Wobjc-method-access] > CGPoint loc = [self convertPoint:[[self window] > convertPointFromScreen:[ev locationInWindow]] fromView:nil]; > > ^~~~~~~~~~~~~~~~~~~~~~ > /System/Library/Frameworks/AppKit.framework/Headers/NSWindow.h:191:12: > note: receiver is instance of class declared here > @interface NSWindow : NSResponder <NSAnimatablePropertyContainer, > NSUserInterfaceValidations, NSUserInterfaceItemIdenti... > ^ > /Users/pm215/src/qemu/ui/cocoa.m:416:46: error: sending 'id' to > parameter of incompatible type 'NSPoint' (aka 'struct CGPoint') > CGPoint loc = [self convertPoint:[[self window] > convertPointFromScreen:[ev locationInWindow]] fromView:nil]; > > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > /System/Library/Frameworks/AppKit.framework/Headers/NSView.h:196:34: > note: passing argument to parameter 'point' here > - (NSPoint)convertPoint:(NSPoint)point fromView:(nullable NSView *)view; > ^ > /Users/pm215/src/qemu/ui/cocoa.m:435:67: warning: instance method > '-convertPointToScreen:' not found > (return type defaults to 'id') [-Wobjc-method-access] > return [[self window] convertPointFromScreen:[eventWindow > convertPointToScreen:[ev locationInWindow]]]; > > ^~~~~~~~~~~~~~~~~~~~ > /System/Library/Frameworks/AppKit.framework/Headers/NSWindow.h:191:12: > note: receiver is instance of class declared here > @interface NSWindow : NSResponder <NSAnimatablePropertyContainer, > NSUserInterfaceValidations, NSUserInterfaceItemIdenti... > ^ > /Users/pm215/src/qemu/ui/cocoa.m:435:31: warning: instance method > '-convertPointFromScreen:' not found > (return type defaults to 'id') [-Wobjc-method-access] > return [[self window] convertPointFromScreen:[eventWindow > convertPointToScreen:[ev locationInWindow]]]; > ^~~~~~~~~~~~~~~~~~~~~~ > /System/Library/Frameworks/AppKit.framework/Headers/NSWindow.h:191:12: > note: receiver is instance of class declared here > @interface NSWindow : NSResponder <NSAnimatablePropertyContainer, > NSUserInterfaceValidations, NSUserInterfaceItemIdenti... > ^ > /Users/pm215/src/qemu/ui/cocoa.m:435:16: error: returning 'id' from a > function with incompatible result type 'CGPoint' > (aka 'struct CGPoint') > return [[self window] convertPointFromScreen:[eventWindow > convertPointToScreen:[ev locationInWindow]]]; > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 4 warnings and 3 errors generated. > > thanks > -- PMM Best regards,
On Wed, 27 Mar 2019 at 01:09, Chen Zhang <tgfbeta@me.com> wrote: > Just double-checked on a MacMini mid 2011 with macOS 10.13.6, Xcode 10.1. This NSWindow API did exist, and the patch could be built without error. > Searching convertPointFromScreen in Xcode.app’s platform SDK showed that it was defined at line 440 in NSWindow.h of AppKit.framework. > > May I ask what build environment did you use (as printed by `xcode-select -p`)? manooth$ xcode-select -p /Applications/Xcode.app/Contents/Developer But that doesn't seem to be what the C compiler is actually using, because the error messages quote the filename /System/Library/Frameworks/AppKit.framework/Headers/NSWindow.h There is no convertPointFromScreen in that header; but there is one in both of /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/AppKit.framework/Versions/C/Headers/NSWindow.h and /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/AppKit.framework/Versions/C/Headers/NSWindow.h which are the other two copies of NSWindow.h this machine has. thanks -- PMM
> On Mar 27, 2019, at 7:37 PM, Peter Maydell <peter.maydell@linaro.org> wrote: > > On Wed, 27 Mar 2019 at 01:09, Chen Zhang <tgfbeta@me.com> wrote: >> Just double-checked on a MacMini mid 2011 with macOS 10.13.6, Xcode 10.1. This NSWindow API did exist, and the patch could be built without error. >> Searching convertPointFromScreen in Xcode.app’s platform SDK showed that it was defined at line 440 in NSWindow.h of AppKit.framework. >> >> May I ask what build environment did you use (as printed by `xcode-select -p`)? > > manooth$ xcode-select -p > /Applications/Xcode.app/Contents/Developer > > But that doesn't seem to be what the C compiler is actually > using, because the error messages quote the filename > /System/Library/Frameworks/AppKit.framework/Headers/NSWindow.h > There is no convertPointFromScreen in that header; but there > is one in both of > > /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/AppKit.framework/Versions/C/Headers/NSWindow.h > > and > /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/AppKit.framework/Versions/C/Headers/NSWindow.h > > which are the other two copies of NSWindow.h this machine has. > > thanks > -- PMM This was really odd. I tried to figure out what was wrong with the toolchain and run `xcode-select --install` and `xcode-select --switch`. After the this, clang failed like what you mentioned. I had to re-configure qemu with --extra-cflags="-isysroot `xcrun --show-sdk-path`”, forcing clang to use the correct SDK root, and then it would compile. Thanks and best regards,
ping http://patchwork.ozlabs.org/patch/1058186/ > On Mar 28, 2019, at 10:05 AM, Chen Zhang <tgfbeta@me.com> wrote: > > > >> On Mar 27, 2019, at 7:37 PM, Peter Maydell <peter.maydell@linaro.org> wrote: >> >> On Wed, 27 Mar 2019 at 01:09, Chen Zhang <tgfbeta@me.com> wrote: >>> Just double-checked on a MacMini mid 2011 with macOS 10.13.6, Xcode 10.1. This NSWindow API did exist, and the patch could be built without error. >>> Searching convertPointFromScreen in Xcode.app’s platform SDK showed that it was defined at line 440 in NSWindow.h of AppKit.framework. >>> >>> May I ask what build environment did you use (as printed by `xcode-select -p`)? >> >> manooth$ xcode-select -p >> /Applications/Xcode.app/Contents/Developer >> >> But that doesn't seem to be what the C compiler is actually >> using, because the error messages quote the filename >> /System/Library/Frameworks/AppKit.framework/Headers/NSWindow.h >> There is no convertPointFromScreen in that header; but there >> is one in both of >> >> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/AppKit.framework/Versions/C/Headers/NSWindow.h >> >> and >> /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/AppKit.framework/Versions/C/Headers/NSWindow.h >> >> which are the other two copies of NSWindow.h this machine has. >> >> thanks >> -- PMM > This was really odd. > > I tried to figure out what was wrong with the toolchain and run `xcode-select --install` and `xcode-select --switch`. After the this, clang failed like what you mentioned. > > I had to re-configure qemu with --extra-cflags="-isysroot `xcrun --show-sdk-path`”, forcing clang to use the correct SDK root, and then it would compile. > > Thanks and best regards,
On Sat, 6 Apr 2019 at 04:04, Chen Zhang <tgfbeta@me.com> wrote: > > ping > > http://patchwork.ozlabs.org/patch/1058186/ This needs changes to be able to compile with OSX 10.10. thanks -- PMM
© 2016 - 2024 Red Hat, Inc.