Fix T45167: OS X inertial scrolling can lead to unexpected zooming.

Differential Revision: https://developer.blender.org/D1539
This commit is contained in:
Brecht Van Lommel 2015-10-05 03:02:11 +02:00
parent a8dd0af8cf
commit 240f356166
Notes: blender-bot 2023-02-14 08:58:04 +01:00
Referenced by issue #45167, Holding Ctrl right after trackpad scrolling makes unwanted zoom (OSX)
2 changed files with 23 additions and 4 deletions

View File

@ -297,6 +297,8 @@ protected:
*/
GHOST_TInt32 m_cursorDelta_x, m_cursorDelta_y;
/** Temporarily ignore momentum scroll events */
bool m_ignoreMomentumScroll;
};
#endif // __GHOST_SYSTEMCOCOA_H__

View File

@ -374,6 +374,7 @@ GHOST_SystemCocoa::GHOST_SystemCocoa()
rstring = NULL;
m_ignoreWindowSizedMessages = false;
m_ignoreMomentumScroll = false;
}
GHOST_SystemCocoa::~GHOST_SystemCocoa()
@ -1391,19 +1392,33 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr)
case NSScrollWheel:
{
NSEventPhase momentum = NSEventPhaseNone;
NSEventPhase momentumPhase = NSEventPhaseNone;
NSEventPhase phase = NSEventPhaseNone;
bool hasMultiTouch = false;
if ([event respondsToSelector:@selector(momentumPhase)])
momentum = [event momentumPhase];
momentumPhase = [event momentumPhase];
if ([event respondsToSelector:@selector(phase)])
phase = [event phase];
if ([event respondsToSelector:@selector(hasPreciseScrollingDeltas)])
hasMultiTouch = [event hasPreciseScrollingDeltas];
/* when pressing a key while momentum scrolling continues after
* lifting fingers off the trackpad, the action can unexpectedly
* change from e.g. scrolling to zooming. this works around the
* issue by ignoring momentum scroll after a key press */
if (momentumPhase)
{
if (m_ignoreMomentumScroll)
break;
}
else
{
m_ignoreMomentumScroll = false;
}
/* standard scrollwheel case, if no swiping happened, and no momentum (kinetic scroll) works */
if (!hasMultiTouch && momentum == NSEventPhaseNone) {
if (!hasMultiTouch && momentumPhase == NSEventPhaseNone) {
GHOST_TInt32 delta;
double deltaF = [event deltaY];
@ -1426,7 +1441,7 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr)
dy = [event scrollingDeltaY];
/* however, wacom tablet (intuos5) needs old deltas, it then has momentum and phase at zero */
if (phase == NSEventPhaseNone && momentum == NSEventPhaseNone) {
if (phase == NSEventPhaseNone && momentumPhase == NSEventPhaseNone) {
dx = [event deltaX];
dy = [event deltaY];
}
@ -1561,6 +1576,7 @@ GHOST_TSuccess GHOST_SystemCocoa::handleKeyEvent(void *eventPtr)
pushEvent( new GHOST_EventKey([event timestamp] * 1000, GHOST_kEventKeyUp, window, keyCode, 0, NULL) );
//printf("Key up rawCode=0x%x charsIgnoringModifiers=%c keyCode=%u ascii=%i %c utf8=%s\n",[event keyCode],[charsIgnoringModifiers length]>0?[charsIgnoringModifiers characterAtIndex:0]:' ',keyCode,ascii,ascii, utf8_buf);
}
m_ignoreMomentumScroll = true;
break;
case NSFlagsChanged:
@ -1580,6 +1596,7 @@ GHOST_TSuccess GHOST_SystemCocoa::handleKeyEvent(void *eventPtr)
}
m_modifierMask = modifiers;
m_ignoreMomentumScroll = true;
break;
default: