Patchwork [3/5] Pass hwheel events from the front-ends

login
register
mail settings
Submitter Brad Jorsch
Date May 4, 2010, 4:56 p.m.
Message ID <1272992201-26911-4-git-send-email-anomie@users.sourceforge.net>
Download mbox | patch
Permalink /patch/51655/
State New
Headers show

Comments

Brad Jorsch - May 4, 2010, 4:56 p.m.
SDL seems to report hwheel events as SDL_BUTTON_X1 and SDL_BUTTON_X2.
VNC I am guessing is similar, and online docs indicate that Cocoa
reports hwheel deltas in deltaX for NSScrollWheel.

Signed-off-by: Brad Jorsch <anomie@users.sourceforge.net>
---
 cocoa.m |    2 +-
 sdl.c   |   12 ++++++++++--
 vnc.c   |   11 ++++++++---
 3 files changed, 19 insertions(+), 6 deletions(-)

Patch

diff --git a/cocoa.m b/cocoa.m
index c247833..afc1b5f 100644
--- a/cocoa.m
+++ b/cocoa.m
@@ -649,7 +649,7 @@  static int cocoa_keycode_to_qemu(int keycode)
             break;
         case NSScrollWheel:
             if (isTabletEnabled || isMouseGrabed) {
-                kbd_mouse_event(0, 0, -[event deltaY], 0, 0);
+                kbd_mouse_event(0, 0, -[event deltaY], -[event deltaX], 0);
             } else {
                 [NSApp sendEvent:event];
             }
diff --git a/sdl.c b/sdl.c
index 616a7eb..f6fabf1 100644
--- a/sdl.c
+++ b/sdl.c
@@ -700,8 +700,9 @@  static void sdl_refresh(DisplayState *ds)
                         sdl_grab_start();
                     }
                 } else {
-                    int dz;
+                    int dz, dw;
                     dz = 0;
+                    dw = 0;
                     if (ev->type == SDL_MOUSEBUTTONDOWN) {
                         buttonstate |= SDL_BUTTON(bev->button);
                     } else {
@@ -714,7 +715,14 @@  static void sdl_refresh(DisplayState *ds)
                         dz = 1;
                     }
 #endif
-                    sdl_send_mouse_event(0, 0, dz, 0, bev->x, bev->y,
+#ifdef SDL_BUTTON_X1
+                    if (bev->button == SDL_BUTTON_X1 && ev->type == SDL_MOUSEBUTTONDOWN) {
+                        dw = -1;
+                    } else if (bev->button == SDL_BUTTON_X2 && ev->type == SDL_MOUSEBUTTONDOWN) {
+                        dw = 1;
+                    }
+#endif
+                    sdl_send_mouse_event(0, 0, dz, dw, bev->x, bev->y,
                                          buttonstate);
                 }
             }
diff --git a/vnc.c b/vnc.c
index 332c14a..c193963 100644
--- a/vnc.c
+++ b/vnc.c
@@ -1275,6 +1275,7 @@  static void pointer_event(VncState *vs, int button_mask, int x, int y)
 {
     int buttons = 0;
     int dz = 0;
+    int dw = 0;
 
     if (button_mask & 0x01)
         buttons |= MOUSE_EVENT_LBUTTON;
@@ -1286,23 +1287,27 @@  static void pointer_event(VncState *vs, int button_mask, int x, int y)
         dz = -1;
     if (button_mask & 0x10)
         dz = 1;
+    if (button_mask & 0x20)
+        dw = -1;
+    if (button_mask & 0x40)
+        dw = 1;
 
     if (vs->absolute) {
         kbd_mouse_event(ds_get_width(vs->ds) > 1 ?
                           x * 0x7FFF / (ds_get_width(vs->ds) - 1) : 0x4000,
                         ds_get_height(vs->ds) > 1 ?
                           y * 0x7FFF / (ds_get_height(vs->ds) - 1) : 0x4000,
-                        dz, 0, buttons);
+                        dz, dw, buttons);
     } else if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE)) {
         x -= 0x7FFF;
         y -= 0x7FFF;
 
-        kbd_mouse_event(x, y, dz, 0, buttons);
+        kbd_mouse_event(x, y, dz, dw, buttons);
     } else {
         if (vs->last_x != -1)
             kbd_mouse_event(x - vs->last_x,
                             y - vs->last_y,
-                            dz, 0, buttons);
+                            dz, dw, buttons);
         vs->last_x = x;
         vs->last_y = y;
     }