All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] ui/cocoa: Fix input device issues on Mojave
@ 2019-06-04  9:12 Chen Zhang via Qemu-devel
  2019-06-04  9:12 ` [Qemu-devel] [PATCH 1/2] ui/cocoa: Fix absolute input device grabbing issue " Chen Zhang via Qemu-devel
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Chen Zhang via Qemu-devel @ 2019-06-04  9:12 UTC (permalink / raw)
  To: peter.maydell, kraxel; +Cc: qemu-devel, Chen Zhang

The following patches fixed issues of absolute and relative input devices on macOS Mojave.

Chen Zhang (2):
  ui/cocoa: Fix absolute input device grabbing issue on Mojave
  ui/cocoa: Fix mouse grabbing in fullscreen mode for relative input
    device

 ui/cocoa.m | 50 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 47 insertions(+), 3 deletions(-)

-- 
2.21.0



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH 1/2] ui/cocoa: Fix absolute input device grabbing issue on Mojave
  2019-06-04  9:12 [Qemu-devel] [PATCH 0/2] ui/cocoa: Fix input device issues on Mojave Chen Zhang via Qemu-devel
@ 2019-06-04  9:12 ` Chen Zhang via Qemu-devel
  2019-06-04  9:12 ` [Qemu-devel] [PATCH 2/2] ui/cocoa: Fix mouse grabbing in fullscreen mode for relative input device Chen Zhang via Qemu-devel
  2019-06-05  1:06 ` [Qemu-devel] [PATCH 0/2] ui/cocoa: Fix input device issues on Mojave no-reply
  2 siblings, 0 replies; 7+ messages in thread
From: Chen Zhang via Qemu-devel @ 2019-06-04  9:12 UTC (permalink / raw)
  To: peter.maydell, kraxel; +Cc: qemu-devel, Chen Zhang

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 was nil after cursor exiting from
window, hinting that the `-locationInWindow` method would return value in 
screen coordinates. The current implementation used raw locations from 
NSEvent without considering whether the value was for the window coordinates
or the macOS screen coordinates, nor the zooming factor for Zoom-to-Fit in
fullscreen mode.

In fullscreen mode, the fullscreen cocoa window might not be the key
window, therefore the location of event in virtual coordinates should
suffice.

This patches fixed boundary check methods for cursor in normal
and fullscreen with/without Zoom-to-Fit in Mojave.

Note: CGRect, -convertRectToScreen: and -convertRectFromScreen: were
used in coordinates conversion for compatibility reason.

Signed-off-by: Chen Zhang <tgfbeta@me.com>
---
 ui/cocoa.m | 43 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 41 insertions(+), 2 deletions(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 420b2411c1..474d44cb9f 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -405,6 +405,41 @@ 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];
+    // XXX: Use CGRect and -convertRectFromScreen: to support macOS 10.10
+    CGRect r = CGRectZero;
+    r.origin = [ev locationInWindow];
+    if (!eventWindow) {
+        if (!isFullscreen) {
+            return [[self window] convertRectFromScreen:r].origin;
+        } else {
+            CGPoint locationInSelfWindow = [[self window] convertRectFromScreen:r].origin;
+            CGPoint loc = [self convertPoint:locationInSelfWindow fromView:nil];
+            if (stretch_video) {
+                loc.x /= cdx;
+                loc.y /= cdy;
+            }
+            return loc;
+        }
+    } else if ([[self window] isEqual:eventWindow]) {
+        if (!isFullscreen) {
+            return r.origin;
+        } else {
+            CGPoint loc = [self convertPoint:r.origin fromView:nil];
+            if (stretch_video) {
+                loc.x /= cdx;
+                loc.y /= cdy;
+            }
+            return loc;
+        }
+    } else {
+        return [[self window] convertRectFromScreen:[eventWindow convertRectToScreen:r]].origin;
+    }
+}
+
 - (void) hideCursor
 {
     if (!cursor_hide) {
@@ -704,7 +739,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 +851,10 @@ QemuCocoaView *cocoaView;
             break;
         case NSEventTypeMouseMoved:
             if (isAbsoluteEnabled) {
-                if (![self screenContainsPoint:p] || ![[self window] isKeyWindow]) {
+                // Cursor re-entered into a window might generate events bound to screen coordinates
+                // and `nil` window property, and in full screen mode, current window might not be
+                // key window, where event location alone should suffice.
+                if (![self screenContainsPoint:p] || !([[self window] isKeyWindow] || isFullscreen)) {
                     if (isMouseGrabbed) {
                         [self ungrabMouse];
                     }
-- 
2.21.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH 2/2] ui/cocoa: Fix mouse grabbing in fullscreen mode for relative input device
  2019-06-04  9:12 [Qemu-devel] [PATCH 0/2] ui/cocoa: Fix input device issues on Mojave Chen Zhang via Qemu-devel
  2019-06-04  9:12 ` [Qemu-devel] [PATCH 1/2] ui/cocoa: Fix absolute input device grabbing issue " Chen Zhang via Qemu-devel
@ 2019-06-04  9:12 ` Chen Zhang via Qemu-devel
  2019-06-05  1:06 ` [Qemu-devel] [PATCH 0/2] ui/cocoa: Fix input device issues on Mojave no-reply
  2 siblings, 0 replies; 7+ messages in thread
From: Chen Zhang via Qemu-devel @ 2019-06-04  9:12 UTC (permalink / raw)
  To: peter.maydell, kraxel; +Cc: qemu-devel, Chen Zhang

In fullscreen mode, the window property of cocoaView may not be the key
window, and the current implementation would not re-grab cursor by left click
in fullscreen mode after ungrabbed in fullscreen mode with hot-key ctrl-opt-g.

This patch used value of isFullscreen as a short-cirtuit condition for
relative input device grabbing.

Signed-off-by: Chen Zhang <tgfbeta@me.com>
---
 ui/cocoa.m | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 474d44cb9f..aa7cf07368 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -901,7 +901,12 @@ QemuCocoaView *cocoaView;
         case NSEventTypeLeftMouseUp:
             mouse_event = true;
             if (!isMouseGrabbed && [self screenContainsPoint:p]) {
-                if([[self window] isKeyWindow]) {
+                /*
+                 * In fullscreen mode, the window of cocoaView may not be the
+                 * key window, therefore the position relative to the virtual
+                 * screen alone will be sufficient.
+                 */
+                if(isFullscreen || [[self window] isKeyWindow]) {
                     [self grabMouse];
                 }
             }
-- 
2.21.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PATCH 0/2] ui/cocoa: Fix input device issues on Mojave
  2019-06-04  9:12 [Qemu-devel] [PATCH 0/2] ui/cocoa: Fix input device issues on Mojave Chen Zhang via Qemu-devel
  2019-06-04  9:12 ` [Qemu-devel] [PATCH 1/2] ui/cocoa: Fix absolute input device grabbing issue " Chen Zhang via Qemu-devel
  2019-06-04  9:12 ` [Qemu-devel] [PATCH 2/2] ui/cocoa: Fix mouse grabbing in fullscreen mode for relative input device Chen Zhang via Qemu-devel
@ 2019-06-05  1:06 ` no-reply
  2 siblings, 0 replies; 7+ messages in thread
From: no-reply @ 2019-06-05  1:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, kraxel, tgfbeta, qemu-devel

Patchew URL: https://patchew.org/QEMU/cover.1559638310.git.tgfbeta@me.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Subject: [Qemu-devel] [PATCH 0/2] ui/cocoa: Fix input device issues on Mojave
Type: series
Message-id: cover.1559638310.git.tgfbeta@me.com

=== 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 ===

From https://github.com/patchew-project/qemu
 * [new tag]               patchew/cover.1559638310.git.tgfbeta@me.com -> patchew/cover.1559638310.git.tgfbeta@me.com
Switched to a new branch 'test'
127a6707a5 ui/cocoa: Fix mouse grabbing in fullscreen mode for relative input device
e5799359d0 ui/cocoa: Fix absolute input device grabbing issue on Mojave

=== OUTPUT BEGIN ===
1/2 Checking commit e5799359d05d (ui/cocoa: Fix absolute input device grabbing issue on Mojave)
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, 61 lines checked

Patch 1/2 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

2/2 Checking commit 127a6707a5e8 (ui/cocoa: Fix mouse grabbing in fullscreen mode for relative input device)
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, 13 lines checked

Patch 2/2 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/cover.1559638310.git.tgfbeta@me.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH 2/2] ui/cocoa: Fix mouse grabbing in fullscreen mode for relative input device
  2019-06-04  9:34 Chen Zhang via Qemu-devel
@ 2019-06-04  9:36 ` Chen Zhang via Qemu-devel
  0 siblings, 0 replies; 7+ messages in thread
From: Chen Zhang via Qemu-devel @ 2019-06-04  9:36 UTC (permalink / raw)
  To: Gerd Hoffmann, Peter Maydell; +Cc: qemu-devel

In fullscreen mode, the window property of cocoaView may not be the key
window, and the current implementation would not re-grab cursor by left click
in fullscreen mode after ungrabbed in fullscreen mode with hot-key ctrl-opt-g.

This patch used value of isFullscreen as a short-cirtuit condition for
relative input device grabbing.

Signed-off-by: Chen Zhang <tgfbeta@me.com>
---
 ui/cocoa.m | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 474d44cb9f..aa7cf07368 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -901,7 +901,12 @@ QemuCocoaView *cocoaView;
         case NSEventTypeLeftMouseUp:
             mouse_event = true;
             if (!isMouseGrabbed && [self screenContainsPoint:p]) {
-                if([[self window] isKeyWindow]) {
+                /*
+                 * In fullscreen mode, the window of cocoaView may not be the
+                 * key window, therefore the position relative to the virtual
+                 * screen alone will be sufficient.
+                 */
+                if(isFullscreen || [[self window] isKeyWindow]) {
                     [self grabMouse];
                 }
             }
-- 
2.21.0




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH 2/2] ui/cocoa: Fix mouse grabbing in fullscreen mode for relative input device
@ 2019-04-08  2:09   ` Chen Zhang via Qemu-devel
  0 siblings, 0 replies; 7+ messages in thread
From: Chen Zhang @ 2019-04-08  2:09 UTC (permalink / raw)
  To: QEMU Developers; +Cc: Peter Maydell, Gerd Hoffmann

In fullscreen mode, the window property of cocoaView may not be the key
window, and the current implementation would not grab mouse in fullscreen
mode after user ungrabs cursor in fullscreen mode with hot-key, and left
clicks the relative input devices to re-grab it.

This patch used value of isFullscreen as a short-cirtuit condition for
relative input device grabbing.

Signed-off-by: Chen Zhang <tgfbeta@me.com>
---
 ui/cocoa.m | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 474d44cb9f..aa7cf07368 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -901,7 +901,12 @@ QemuCocoaView *cocoaView;
         case NSEventTypeLeftMouseUp:
             mouse_event = true;
             if (!isMouseGrabbed && [self screenContainsPoint:p]) {
-                if([[self window] isKeyWindow]) {
+                /*
+                 * In fullscreen mode, the window of cocoaView may not be the
+                 * key window, therefore the position relative to the virtual
+                 * screen alone will be sufficient.
+                 */
+                if(isFullscreen || [[self window] isKeyWindow]) {
                     [self grabMouse];
                 }
             }
-- 
2.19.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH 2/2] ui/cocoa: Fix mouse grabbing in fullscreen mode for relative input device
@ 2019-04-08  2:09   ` Chen Zhang via Qemu-devel
  0 siblings, 0 replies; 7+ messages in thread
From: Chen Zhang via Qemu-devel @ 2019-04-08  2:09 UTC (permalink / raw)
  To: QEMU Developers; +Cc: Peter Maydell, Gerd Hoffmann

In fullscreen mode, the window property of cocoaView may not be the key
window, and the current implementation would not grab mouse in fullscreen
mode after user ungrabs cursor in fullscreen mode with hot-key, and left
clicks the relative input devices to re-grab it.

This patch used value of isFullscreen as a short-cirtuit condition for
relative input device grabbing.

Signed-off-by: Chen Zhang <tgfbeta@me.com>
---
 ui/cocoa.m | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 474d44cb9f..aa7cf07368 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -901,7 +901,12 @@ QemuCocoaView *cocoaView;
         case NSEventTypeLeftMouseUp:
             mouse_event = true;
             if (!isMouseGrabbed && [self screenContainsPoint:p]) {
-                if([[self window] isKeyWindow]) {
+                /*
+                 * In fullscreen mode, the window of cocoaView may not be the
+                 * key window, therefore the position relative to the virtual
+                 * screen alone will be sufficient.
+                 */
+                if(isFullscreen || [[self window] isKeyWindow]) {
                     [self grabMouse];
                 }
             }
-- 
2.19.2



^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-06-05  1:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-04  9:12 [Qemu-devel] [PATCH 0/2] ui/cocoa: Fix input device issues on Mojave Chen Zhang via Qemu-devel
2019-06-04  9:12 ` [Qemu-devel] [PATCH 1/2] ui/cocoa: Fix absolute input device grabbing issue " Chen Zhang via Qemu-devel
2019-06-04  9:12 ` [Qemu-devel] [PATCH 2/2] ui/cocoa: Fix mouse grabbing in fullscreen mode for relative input device Chen Zhang via Qemu-devel
2019-06-05  1:06 ` [Qemu-devel] [PATCH 0/2] ui/cocoa: Fix input device issues on Mojave no-reply
  -- strict thread matches above, loose matches on Subject: below --
2019-06-04  9:34 Chen Zhang via Qemu-devel
2019-06-04  9:36 ` [Qemu-devel] [PATCH 2/2] ui/cocoa: Fix mouse grabbing in fullscreen mode for relative input device Chen Zhang via Qemu-devel
2019-04-08  2:04 [Qemu-devel] [PATCH 0/2] ui/cocoa: Fix absolute and relative input issues on Mojave Chen Zhang
2019-04-08  2:09 ` [Qemu-devel] [PATCH 2/2] ui/cocoa: Fix mouse grabbing in fullscreen mode for relative input device Chen Zhang
2019-04-08  2:09   ` Chen Zhang via Qemu-devel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.