Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fix mouse wheel events in fullscreen mode for OS X
Browse files Browse the repository at this point in the history
With proposed patch by vernier.
  • Loading branch information
jjgod committed Jan 20, 2011
1 parent 79ee2ff commit d63b12f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/video/cocoa/SDL_cocoaevents.m
Expand Up @@ -201,6 +201,7 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sende
case NSLeftMouseDragged:
case NSRightMouseDragged:
case NSOtherMouseDragged: /* usually middle mouse dragged */
case NSScrollWheel:
case NSMouseMoved:
Cocoa_HandleMouseEvent(_this, event);
/* Pass through to NSApp to make sure everything stays in sync */
Expand Down
1 change: 1 addition & 0 deletions src/video/cocoa/SDL_cocoamouse.h
Expand Up @@ -27,6 +27,7 @@
extern void Cocoa_InitMouse(_THIS);
extern void Cocoa_HandleMouseEvent(_THIS, NSEvent * event);
extern void Cocoa_QuitMouse(_THIS);
extern void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent * event);

#endif /* _SDL_cocoamouse_h */

Expand Down
22 changes: 22 additions & 0 deletions src/video/cocoa/SDL_cocoamouse.m
Expand Up @@ -93,6 +93,9 @@
case NSRightMouseUp:
SDL_SendMouseButton(window, SDL_RELEASED, ConvertMouseButtonToSDL([event buttonNumber]));
break;
case NSScrollWheel:
Cocoa_HandleMouseWheel(window, event);
break;
case NSLeftMouseDragged:
case NSRightMouseDragged:
case NSOtherMouseDragged: /* usually middle mouse dragged */
Expand All @@ -109,4 +112,23 @@
{
}

void
Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
{
float x = [event deltaX];
float y = [event deltaY];

if (x > 0) {
x += 0.9f;
} else if (x < 0) {
x -= 0.9f;
}
if (y > 0) {
y += 0.9f;
} else if (y < 0) {
y -= 0.9f;
}
SDL_SendMouseWheel(window, (int)x, (int)y);
}

/* vi: set ts=4 sw=4 expandtab: */
16 changes: 2 additions & 14 deletions src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -29,6 +29,7 @@
#include "../../events/SDL_windowevents_c.h"
#include "SDL_cocoavideo.h"
#include "SDL_cocoashape.h"
#include "SDL_cocoamouse.h"

static __inline__ void ConvertNSRect(NSRect *r)
{
Expand Down Expand Up @@ -260,20 +261,7 @@ - (void)otherMouseDragged:(NSEvent *)theEvent

- (void)scrollWheel:(NSEvent *)theEvent
{
float x = [theEvent deltaX];
float y = [theEvent deltaY];

if (x > 0) {
x += 0.9f;
} else if (x < 0) {
x -= 0.9f;
}
if (y > 0) {
y += 0.9f;
} else if (y < 0) {
y -= 0.9f;
}
SDL_SendMouseWheel(_data->window, (int)x, (int)y);
Cocoa_HandleMouseWheel(_data->window, theEvent);
}

- (void)touchesBeganWithEvent:(NSEvent *) theEvent
Expand Down

0 comments on commit d63b12f

Please sign in to comment.