From 5655e26315bede6d714ba9a9e087c04ab00e2b49 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Wed, 17 Jul 2013 19:36:43 -0700 Subject: [PATCH] Changed scrollWheel to use precise scrolling deltas when available. Use precise scrolling deltas only on supported versions of OS X; hasPreciseScrollingDeltas, scrollingDeltaX, scrollingDeltaY are available in OS X v10.7 and later. Replaced a single occurence of a tab character with 4 spaces for consistency in src/socoa_window.m. --- README.md | 1 + src/cocoa_window.m | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d735738c..8e336178 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,7 @@ See the [GLFW documentation](http://www.glfw.org/docs/latest/). returned by `glfwGetProcAddress` - [Win32] Bugfix: The user32 and dwmapi module handles were not freed on library termination + - [Cocoa] Changed scroll callback to use precise scrolling deltas when available - [Cocoa] Enabled explicit creation of OpenGL 3.x and 4.x contexts as supported by OS X 10.9 - [Cocoa] Bugfix: The clipboard string was not freed on terminate diff --git a/src/cocoa_window.m b/src/cocoa_window.m index f32d078e..641b4d4c 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -560,7 +560,7 @@ static int translateKey(unsigned int key) userInfo:nil]; [self addTrackingArea:trackingArea]; - [super updateTrackingAreas]; + [super updateTrackingAreas]; } - (void)keyDown:(NSEvent *)event @@ -606,8 +606,27 @@ static int translateKey(unsigned int key) - (void)scrollWheel:(NSEvent *)event { - double deltaX = [event deltaX]; - double deltaY = [event deltaY]; + double deltaX, deltaY; + +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 + if ([event respondsToSelector:@selector(hasPreciseScrollingDeltas:)]) + { + deltaX = [event scrollingDeltaX]; + deltaY = [event scrollingDeltaY]; + + if ([event hasPreciseScrollingDeltas]) + { + deltaX *= 0.1; + deltaY *= 0.1; + } + } + else +#else + { + deltaX = [event deltaX]; + deltaY = [event deltaY]; + } +#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/ if (fabs(deltaX) > 0.0 || fabs(deltaY) > 0.0) _glfwInputScroll(window, deltaX, deltaY);