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 | |||||
| /* clang-format on */ | /* clang-format on */ | ||||
| GHOST_SystemCocoa::GHOST_SystemCocoa() | GHOST_SystemCocoa::GHOST_SystemCocoa() | ||||
| { | { | ||||
| int mib[2]; | int mib[2]; | ||||
| struct timeval boottime; | struct timeval boottime; | ||||
| size_t len; | size_t len; | ||||
| char *rstring = NULL; | |||||
| m_modifierMask = 0; | m_modifierMask = 0; | ||||
| m_outsideLoopEventProcessed = false; | m_outsideLoopEventProcessed = false; | ||||
| m_needDelayedApplicationBecomeActiveEventProcessing = false; | m_needDelayedApplicationBecomeActiveEventProcessing = false; | ||||
| m_displayManager = new GHOST_DisplayManagerCocoa(); | m_displayManager = new GHOST_DisplayManagerCocoa(); | ||||
| GHOST_ASSERT(m_displayManager, "GHOST_SystemCocoa::GHOST_SystemCocoa(): m_displayManager==0\n"); | GHOST_ASSERT(m_displayManager, "GHOST_SystemCocoa::GHOST_SystemCocoa(): m_displayManager==0\n"); | ||||
| m_displayManager->initialize(); | m_displayManager->initialize(); | ||||
| // NSEvent timeStamp is given in system uptime, state start date is boot time | // NSEvent timeStamp is given in system uptime, state start date is boot time | ||||
| mib[0] = CTL_KERN; | mib[0] = CTL_KERN; | ||||
| mib[1] = KERN_BOOTTIME; | mib[1] = KERN_BOOTTIME; | ||||
| len = sizeof(struct timeval); | len = sizeof(struct timeval); | ||||
| sysctl(mib, 2, &boottime, &len, NULL, 0); | sysctl(mib, 2, &boottime, &len, NULL, 0); | ||||
| m_start_time = ((boottime.tv_sec * 1000) + (boottime.tv_usec / 1000)); | m_start_time = ((boottime.tv_sec * 1000) + (boottime.tv_usec / 1000)); | ||||
| // Detect multitouch trackpad | |||||
| mib[0] = CTL_HW; | |||||
| mib[1] = HW_MODEL; | |||||
| sysctl(mib, 2, NULL, &len, NULL, 0); | |||||
| rstring = (char *)malloc(len); | |||||
| sysctl(mib, 2, rstring, &len, NULL, 0); | |||||
| free(rstring); | |||||
| rstring = NULL; | |||||
| m_ignoreWindowSizedMessages = false; | m_ignoreWindowSizedMessages = false; | ||||
| m_ignoreMomentumScroll = false; | m_ignoreMomentumScroll = false; | ||||
| m_multiTouchScroll = false; | m_multiTouchScroll = false; | ||||
| m_last_warp_timestamp = 0; | m_last_warp_timestamp = 0; | ||||
| } | } | ||||
| GHOST_SystemCocoa::~GHOST_SystemCocoa() | GHOST_SystemCocoa::~GHOST_SystemCocoa() | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
| objectForKey:@"NSScreenNumber"] unsignedIntValue], | objectForKey:@"NSScreenNumber"] unsignedIntValue], | ||||
| CGPointMake(xf, yf)); | CGPointMake(xf, yf)); | ||||
| // See https://stackoverflow.com/a/17559012. By default, hardware events | // See https://stackoverflow.com/a/17559012. By default, hardware events | ||||
| // will be suppressed for 500ms after a synthetic mouse event. For unknown | // will be suppressed for 500ms after a synthetic mouse event. For unknown | ||||
| // reasons CGEventSourceSetLocalEventsSuppressionInterval does not work, | // reasons CGEventSourceSetLocalEventsSuppressionInterval does not work, | ||||
| // however calling CGAssociateMouseAndMouseCursorPosition also removes the | // however calling CGAssociateMouseAndMouseCursorPosition also removes the | ||||
| // delay, even if this is undocumented. | // delay, even if this is undocumented. | ||||
| /* NOTE: CGEventSourceSetLocalEventsSuppressionInterval can be used, the | |||||
| reference above states it doesn't work with CGWarpMouseCursorPosition, | |||||
| that seems to be outdated, anyway we use CGDisplayMoveCursorToPoint. */ | |||||
| /* CGEventSourceSetLocalEventsSuppressionInterval( | |||||
| CGEventSourceCreate(kCGEventSourceStateCombinedSessionState), 0); */ | |||||
| CGAssociateMouseAndMouseCursorPosition(true); | CGAssociateMouseAndMouseCursorPosition(true); | ||||
| [pool drain]; | [pool drain]; | ||||
| return GHOST_kSuccess; | return GHOST_kSuccess; | ||||
| } | } | ||||
| GHOST_TSuccess GHOST_SystemCocoa::getModifierKeys(GHOST_ModifierKeys &keys) const | GHOST_TSuccess GHOST_SystemCocoa::getModifierKeys(GHOST_ModifierKeys &keys) const | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
| case NSEventTypeLeftMouseDragged: | case NSEventTypeLeftMouseDragged: | ||||
| case NSEventTypeRightMouseDragged: | case NSEventTypeRightMouseDragged: | ||||
| case NSEventTypeOtherMouseDragged: | case NSEventTypeOtherMouseDragged: | ||||
| handleTabletEvent(event); // Update window tablet state to be included in event. | handleTabletEvent(event); // Update window tablet state to be included in event. | ||||
| case NSEventTypeMouseMoved: { | case NSEventTypeMouseMoved: { | ||||
| GHOST_TGrabCursorMode grab_mode = window->getCursorGrabMode(); | GHOST_TGrabCursorMode grab_mode = window->getCursorGrabMode(); | ||||
| /* TODO: CHECK IF THIS IS A TABLET EVENT */ | /* TODO: Check if this is a tablet event. Can we use 'handleTabletEvent()' here? */ | ||||
| bool is_tablet = false; | bool is_tablet = false; | ||||
| if (is_tablet && window->getCursorGrabModeIsWarp()) { | if (is_tablet && window->getCursorGrabModeIsWarp()) { | ||||
| grab_mode = GHOST_kGrabDisable; | grab_mode = GHOST_kGrabDisable; | ||||
| } | } | ||||
| switch (grab_mode) { | switch (grab_mode) { | ||||
| case GHOST_kGrabHide: // Cursor hidden grab operation : no cursor move | case GHOST_kGrabHide: // Cursor hidden grab operation : no cursor move | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||