[Qemu-devel] [PATCH] cocoa.m: Fix scroll wheel support

John Arbuckle posted 1 patch 7 years, 9 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20171230163012.95032-1-programmingkidx@gmail.com
Test checkpatch passed
Test docker passed
Test ppc passed
Test s390x passed
There is a newer version of this series
ui/cocoa.m | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
[Qemu-devel] [PATCH] cocoa.m: Fix scroll wheel support
Posted by John Arbuckle 7 years, 9 months ago
When using a mouse's scroll wheel in a guest with the cocoa front-end, the mouse pointer moves up and down instead of scrolling the window. This patch fixes this problem.

Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
---
 ui/cocoa.m | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 330ccebf90..d2e5f80b74 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -786,11 +786,18 @@ - (void) handleEvent:(NSEvent *)event
             mouse_event = true;
             break;
         case NSEventTypeScrollWheel:
-            if (isMouseGrabbed) {
-                buttons |= ([event deltaY] < 0) ?
-                    MOUSE_EVENT_WHEELUP : MOUSE_EVENT_WHEELDN;
-            }
-            mouse_event = true;
+            /* Determine if this is a scroll up or scroll down event */
+            buttons = ([event scrollingDeltaY] > 0) ?
+                INPUT_BUTTON_WHEEL_UP : INPUT_BUTTON_WHEEL_DOWN;
+            qemu_input_queue_btn(dcl->con, buttons, true);
+            qemu_input_event_sync();
+            qemu_input_queue_btn(dcl->con, buttons, false);
+            qemu_input_event_sync();
+            /*
+             * Since deltaY also reports scroll wheel events we prevent mouse
+             * movement code from executing.
+             */
+            mouse_event = false;
             break;
         default:
             [NSApp sendEvent:event];
-- 
2.14.3 (Apple Git-98)


Re: [Qemu-devel] [PATCH] cocoa.m: Fix scroll wheel support
Posted by Peter Maydell 7 years, 9 months ago
On 30 December 2017 at 16:30, John Arbuckle <programmingkidx@gmail.com> wrote:
> When using a mouse's scroll wheel in a guest with the cocoa front-end, the mouse pointer moves up and down instead of scrolling the window. This patch fixes this problem.

Thanks for this patch. The code looks good to me, but
you can now also remove the entries for INPUT_BUTTON_WHEEL_UP
and INPUT_BUTTON_WHEEL_DOWN from the bmap[] array, because
we can no longer get into that code with those button types.

I think it's also worth having a comment that we send
wheel events to the guest regardless of window focus now
(which is in line with standard OSX UI behaviour, so it
seems like the right thing).

PS: can you line-wrap your commit messages, please?

> Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
> ---
>  ui/cocoa.m | 17 ++++++++++++-----
>  1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/ui/cocoa.m b/ui/cocoa.m
> index 330ccebf90..d2e5f80b74 100644
> --- a/ui/cocoa.m
> +++ b/ui/cocoa.m
> @@ -786,11 +786,18 @@ - (void) handleEvent:(NSEvent *)event
>              mouse_event = true;
>              break;
>          case NSEventTypeScrollWheel:
> -            if (isMouseGrabbed) {
> -                buttons |= ([event deltaY] < 0) ?
> -                    MOUSE_EVENT_WHEELUP : MOUSE_EVENT_WHEELDN;
> -            }
> -            mouse_event = true;
> +            /* Determine if this is a scroll up or scroll down event */
> +            buttons = ([event scrollingDeltaY] > 0) ?
> +                INPUT_BUTTON_WHEEL_UP : INPUT_BUTTON_WHEEL_DOWN;
> +            qemu_input_queue_btn(dcl->con, buttons, true);
> +            qemu_input_event_sync();
> +            qemu_input_queue_btn(dcl->con, buttons, false);
> +            qemu_input_event_sync();
> +            /*
> +             * Since deltaY also reports scroll wheel events we prevent mouse
> +             * movement code from executing.
> +             */
> +            mouse_event = false;
>              break;
>          default:
>              [NSApp sendEvent:event];
> --
> 2.14.3 (Apple Git-98)
>

thanks
-- PMM