Changeset View
Changeset View
Standalone View
Standalone View
intern/ghost/intern/GHOST_SystemCocoa.mm
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| rstring = (char *)malloc(len); | rstring = (char *)malloc(len); | ||||
| sysctl(mib, 2, rstring, &len, NULL, 0); | sysctl(mib, 2, rstring, &len, NULL, 0); | ||||
| free(rstring); | free(rstring); | ||||
| rstring = NULL; | rstring = NULL; | ||||
| m_ignoreWindowSizedMessages = false; | m_ignoreWindowSizedMessages = false; | ||||
| m_ignoreMomentumScroll = false; | m_ignoreMomentumScroll = false; | ||||
| m_multiTouchScroll = false; | |||||
| m_last_warp_timestamp = 0; | m_last_warp_timestamp = 0; | ||||
| } | } | ||||
| GHOST_SystemCocoa::~GHOST_SystemCocoa() | GHOST_SystemCocoa::~GHOST_SystemCocoa() | ||||
| { | { | ||||
| } | } | ||||
| GHOST_TSuccess GHOST_SystemCocoa::init() | GHOST_TSuccess GHOST_SystemCocoa::init() | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
| if (momentumPhase) { | if (momentumPhase) { | ||||
| if (m_ignoreMomentumScroll) | if (m_ignoreMomentumScroll) | ||||
| break; | break; | ||||
| } | } | ||||
| else { | else { | ||||
| m_ignoreMomentumScroll = false; | m_ignoreMomentumScroll = false; | ||||
| } | } | ||||
| /* we assume phases are only set for gestures from trackpad or magic | const double dx = [event scrollingDeltaX]; | ||||
| * mouse events. note that using tablet at the same time may not work | const double dy = [event scrollingDeltaY]; | ||||
| * since this is a static variable */ | |||||
| if (phase == NSEventPhaseBegan) | |||||
| m_multiTouchScroll = true; | |||||
| else if (phase == NSEventPhaseEnded) | |||||
| m_multiTouchScroll = false; | |||||
| /* Standard scroll-wheel case, if no swiping happened, | /* Distinguish between a traditional mouse with 1D scroll-wheel, | ||||
| * and no momentum (kinetic scroll) works. */ | * and 2D scroll on a tablet, trackpad or apple mouse. */ | ||||
| if (!m_multiTouchScroll && momentumPhase == NSEventPhaseNone) { | if ([event subtype] == NSEventSubtypeMouseEvent) { | ||||
| int32_t delta; | /* On macOS, holding down the Shift key converts the vertical scroll-wheel | ||||
| * into a horizontal scrolling, consider it here. */ | |||||
| double deltaF = [event deltaY]; | int32_t delta = (dx + dy) > 0.0 ? 1 : -1; | ||||
| if (deltaF == 0.0) | |||||
| deltaF = [event deltaX]; // make blender decide if it's horizontal scroll | |||||
| if (deltaF == 0.0) | |||||
| break; // discard trackpad delta=0 events | |||||
| delta = deltaF > 0.0 ? 1 : -1; | |||||
| pushEvent(new GHOST_EventWheel([event timestamp] * 1000, window, delta)); | pushEvent(new GHOST_EventWheel([event timestamp] * 1000, window, delta)); | ||||
| } | } | ||||
| else { | else { | ||||
| NSPoint mousePos = [event locationInWindow]; | NSPoint mousePos = [event locationInWindow]; | ||||
| int32_t x, y; | int32_t x, y; | ||||
| double dx; | |||||
| double dy; | |||||
| /* with 10.7 nice scrolling deltas are supported */ | |||||
| dx = [event scrollingDeltaX]; | |||||
| dy = [event scrollingDeltaY]; | |||||
| /* However, Wacom tablet (intuos5) needs old deltas, | |||||
| * it then has momentum and phase at zero. */ | |||||
| if (phase == NSEventPhaseNone && momentumPhase == NSEventPhaseNone) { | |||||
| dx = [event deltaX]; | |||||
| dy = [event deltaY]; | |||||
| } | |||||
| window->clientToScreenIntern(mousePos.x, mousePos.y, x, y); | window->clientToScreenIntern(mousePos.x, mousePos.y, x, y); | ||||
| NSPoint delta = [[cocoawindow contentView] convertPointToBacking:NSMakePoint(dx, dy)]; | NSPoint delta = [[cocoawindow contentView] convertPointToBacking:NSMakePoint(dx, dy)]; | ||||
| pushEvent(new GHOST_EventTrackpad([event timestamp] * 1000, | pushEvent(new GHOST_EventTrackpad([event timestamp] * 1000, | ||||
| window, | window, | ||||
| GHOST_kTrackpadEventScroll, | GHOST_kTrackpadEventScroll, | ||||
| x, | x, | ||||
| y, | y, | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||